/*
 * Copyright 2000-2016 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.testFramework;

import com.intellij.util.SmartList;
import com.intellij.util.ThrowableRunnable;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.lang.CompoundRuntimeException;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;

/**
 * Runs all given runnables and throws all the caught exceptions at the end.
 *
 * @author peter
 */
public class RunAll implements Runnable {
  private final List<ThrowableRunnable<?>> myActions;

  public RunAll(ThrowableRunnable<Throwable>... actions) {
    this(Arrays.asList(actions));
  }

  private RunAll(List<ThrowableRunnable<?>> actions) {
    myActions = actions;
  }

  @Contract(pure=true)
  public RunAll append(ThrowableRunnable<Throwable>... actions) {
    return new RunAll(ContainerUtil.concat(myActions, ContainerUtil.newArrayList(actions)));
  }

  @Override
  public void run() {
    CompoundRuntimeException.throwIfNotEmpty(collectExceptions());
  }

  @NotNull
  public List<Throwable> collectExceptions() {
    List<Throwable> errors = new SmartList<>();
    for (ThrowableRunnable<?> action : myActions) {
      try {
        action.run();
      }
      catch (CompoundRuntimeException e) {
        errors.addAll(e.getExceptions());
      }
      catch (Throwable e) {
        errors.add(e);
      }
    }
    return errors;
  }
}

@@ -908,33 +908,8 @@
 l;%0A%0A
-import java.util.Arrays;%0A
 impo
@@ -927,16 +927,16 @@
 l.List;%0A
+
 %0A/**%0A * 
@@ -1130,16 +1130,31 @@
 tions;%0A%0A
+  @SafeVarargs%0A
   public
@@ -1217,17 +1217,30 @@
 his(
+ContainerUtil.new
 Array
-s.as
 List
@@ -1341,16 +1341,31 @@
 s;%0A  %7D%0A%0A
+  @SafeVarargs%0A
   @Contr
@@ -1379,16 +1379,16 @@
 e=true)%0A
-
   public
@@ -1384,24 +1384,30 @@
 e)%0A  public 
+final 
 RunAll appen

add @SafeVarargs to RunAll (IDEA-CR-15166)