Search in sources :

Example 6 with TreeScanner

use of com.sun.tools.javac.tree.TreeScanner in project error-prone by google.

the class UnificationTest method expectMatches.

public void expectMatches(final Template<?> template, Match... expected) {
    final Set<Match> expectedMatches = Sets.newHashSet(expected);
    TreeScanner matchScanner = new TreeScanner() {

        @Override
        public void scan(JCTree tree) {
            if (tree == null) {
                return;
            }
            for (TemplateMatch templateMatch : template.match(tree, context)) {
                Match match = Match.create(templateMatch);
                if (!expectedMatches.remove(match)) {
                    fail(String.format("Unexpected match against template %s:%n%s", template, match));
                }
            }
            super.scan(tree);
        }
    };
    for (JCCompilationUnit unit : compilationUnits) {
        matchScanner.scan(unit);
    }
    for (Match missingMatch : expectedMatches) {
        fail(String.format("Expected match against template %s not found: %s", template, missingMatch));
    }
}
Also used : JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) TreeScanner(com.sun.tools.javac.tree.TreeScanner) JCTree(com.sun.tools.javac.tree.JCTree)

Aggregations

TreeScanner (com.sun.tools.javac.tree.TreeScanner)6 JCTree (com.sun.tools.javac.tree.JCTree)5 ImmutableMap (com.google.common.collect.ImmutableMap)2 MethodTree (com.sun.source.tree.MethodTree)2 Tree (com.sun.source.tree.Tree)2 Symbol (com.sun.tools.javac.code.Symbol)2 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)2 Set (java.util.Set)2 Objects (com.google.common.base.Objects)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 MoreCollectors (com.google.common.collect.MoreCollectors)1 Streams (com.google.common.collect.Streams)1 BugPattern (com.google.errorprone.BugPattern)1 JDK (com.google.errorprone.BugPattern.Category.JDK)1 WARNING (com.google.errorprone.BugPattern.SeverityLevel.WARNING)1 VisitorState (com.google.errorprone.VisitorState)1 ClassTreeMatcher (com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher)1 MethodTreeMatcher (com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher)1