// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij;

import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.regex.Pattern;

/**
 * @author yole
 */
public abstract class TestClassesFilter {
  public static final TestClassesFilter ALL_CLASSES = new TestClassesFilter() {
    @Override
    public boolean matches(String className, String moduleName) {
      return true;
    }
  };

  public abstract boolean matches(String className, @Nullable String moduleName);
  
  public boolean matches(String className) { return matches(className, null); }

  protected static ArrayList<Pattern> compilePatterns(Collection<String> filterList) {
    ArrayList<Pattern> patterns = new ArrayList<>();
    for (String aFilter : filterList) {
      String filter = aFilter.trim();
      if (filter.length() == 0) continue;
      filter = filter.replaceAll("\\*", ".\\*");
      Pattern pattern = Pattern.compile(filter);
      patterns.add(pattern);
    }
    return patterns;
  }

  protected static boolean matchesAnyPattern(Collection<Pattern> patterns, String className) {
    for (Pattern pattern : patterns) {
      if (pattern.matcher(className).matches()) {
        return true;
      }
    }
    return false;
  }

  public static class And extends TestClassesFilter {
    private final TestClassesFilter first;
    private final TestClassesFilter second;

    public And(TestClassesFilter first, TestClassesFilter second) {
      this.first = first;
      this.second = second;
    }

    @Override
    public boolean matches(String className, @Nullable String moduleName) {
      return first.matches(className, moduleName) &&
             second.matches(className, moduleName);
    }

    @Override
    public String toString() {
      return "AndTestClassesFilter{" +
             "first: " + first.toString() + "," +
             "second: " + second.toString() + '}';
    }
  }
}

@@ -537,24 +537,104 @@
  true;%0A    %7D
+%0A%0A    @Override%0A    public String toString() %7B%0A      return %22ALL_CLASSES%22;%0A    %7D
 %0A  %7D;%0A%0A  pub

add toString's to test class filters, add all classes