@Override public Void scan(Tree tree, Void unused) { return Objects.equals(stoppingPoint, tree) ? null : super.scan(tree, unused); }
@Override public Void scan(Iterable<? extends Tree> iterable, Void unused) { if (stoppingPoint != null && iterable != null) { ImmutableList.Builder<Tree> builder = ImmutableList.builder(); for (Tree t : iterable) { if (stoppingPoint.equals(t)) { break; } builder.add(t); } iterable = builder.build(); } return super.scan(iterable, unused); }
/** Find the set of all identifiers referenced within this Tree */ public static ImmutableSet<Symbol> findReferencedIdentifiers(Tree tree) { ImmutableSet.Builder<Symbol> builder = ImmutableSet.builder(); createFindIdentifiersScanner(builder, null).scan(tree, null); return builder.build(); }
@Override public Boolean scan(Tree t, Unifier unifier) { if (t != null) { Boolean forbidden = t.accept(PlaceholderUnificationVisitor.FORBIDDEN_REFERENCE_VISITOR, unifier); return firstNonNull(forbidden, false) || firstNonNull(super.scan(t, unifier), false); } return false; } };
@Override public Boolean scan(Tree tree, Boolean matchFound) { if (matchFound) { return true; } if (matcher.matches(tree, state)) { return true; } return super.scan(tree, false); }
@Override public Boolean scan(Tree tree, Void unused) { if (badAnswers.contains(ASTHelpers.getSymbol(tree))) { return true; } return super.scan(tree, null); }
@Override public Void visitReference(ReferenceTree referenceTree, SymbolSink sink) { // do this first, it attributes the referenceTree as a side-effect trees.getElement(getCurrentPath()); TreeScanner<Void, SymbolSink> nonRecursiveScanner = new TreeScanner<Void, SymbolSink>() { @Override public Void visitIdentifier(IdentifierTree tree, SymbolSink sink) { Symbol sym = ASTHelpers.getSymbol(tree); if (sym != null) { sink.accept(sym); } return null; } }; DCReference reference = (DCReference) referenceTree; nonRecursiveScanner.scan(reference.qualifierExpression, sink); nonRecursiveScanner.scan(reference.paramTypes, sink); return null; } }
@Override public Void visitReference(ReferenceTree referenceTree, Void sink) { // do this first, it attributes the referenceTree as a side-effect trees.getElement(getCurrentPath()); com.sun.source.util.TreeScanner<Void, Void> nonRecursiveScanner = new com.sun.source.util.TreeScanner<Void, Void>() { @Override public Void visitIdentifier(IdentifierTree tree, Void sink) { Symbol sym = ASTHelpers.getSymbol(tree); if (sym != null) { System.out.println("sym = " + sym); } return null; } }; DCReference reference = (DCReference) referenceTree; nonRecursiveScanner.scan(reference.qualifierExpression, sink); nonRecursiveScanner.scan(reference.paramTypes, sink); return null; } }
@Override public Boolean scan(Tree node, Unifier unifier) { Iterator<UExpression> iterator = unmatched.iterator(); while (iterator.hasNext()) { if (couldUnify(iterator.next(), node, unifier)) { iterator.remove(); return true; } } for (UExpression expr : allowed) { if (couldUnify(expr, node, unifier)) { return true; } } if (node instanceof JCExpression) { JCExpression expr = (JCExpression) node; for (UFreeIdent.Key key : Iterables.filter(unifier.getBindings().keySet(), UFreeIdent.Key.class)) { JCExpression keyBinding = unifier.getBinding(key); if (PlaceholderUnificationVisitor.equivalentExprs(unifier, expr, keyBinding)) { return false; } } } return firstNonNull(super.scan(node, unifier), true); }
return treesToScan.isEmpty() ? false : scanner.scan(treesToScan, null);
@Override public Boolean scan(Tree tree, Void aVoid) { Symbol sym = ASTHelpers.getSymbol(tree); if (sym instanceof VarSymbol) { VarSymbol varSym = (VarSymbol) sym; if (badMocks.contains(ASTHelpers.getSymbol(tree))) { return true; } // custom answer strategies can be specified using @Mock(answer = ...) if (ASTHelpers.hasAnnotation(sym, MOCK_ANNOTATION, state) && !answerHandlesGenerics(varSym, state)) { return true; } // gwtmockito mocks @UiFields if (ASTHelpers.hasAnnotation(varSym, UI_FIELD_ANNOTATION, state)) { return true; } } return super.scan(tree, aVoid); }
Tree prev = state.getPath().getLeaf(); for (Tree curr : state.getPath().getParentPath()) { createFindIdentifiersScanner(usedSymbols, prev).scan(curr, null); switch (curr.getKind()) { case BLOCK:
@Override public Choice<UnifierWithUnconsumedStatements> apply( final UnifierWithUnconsumedStatements state) { int goodIndex = 0; while (goodIndex < state.unconsumedStatements().size()) { StatementTree stmt = state.unconsumedStatements().get(goodIndex); // If the statement refers to bound variables or doesn't always exit, stop consuming // statements. if (firstNonNull(FORBIDDEN_REFERENCE_SCANNER.scan(stmt, state.unifier()), false) || ControlFlowVisitor.INSTANCE.visitStatement(stmt) != ControlFlowVisitor.Result.NEVER_EXITS) { break; } else { goodIndex++; } } Collection<Integer> breakPoints = ContiguousSet.create(Range.closed(0, goodIndex), DiscreteDomain.integers()); return Choice.from(breakPoints) .transform( (Integer k) -> { Unifier unifier = state.unifier().fork(); unifier.putBinding(key(), state.unconsumedStatements().subList(0, k)); List<? extends StatementTree> remaining = state.unconsumedStatements().subList(k, state.unconsumedStatements().size()); return UnifierWithUnconsumedStatements.create(unifier, remaining); }); }
boolean verified = ExpressionTemplate.trueOrNull( ExpressionTemplate.PLACEHOLDER_VERIFIER.scan( templateStatements(), checkedUnifier.get())); if (!verified) {
if (findSuper.scan(tree, null)) { return Description.NO_MATCH;
return expression() .unify(target, unifier) .condition(u -> trueOrNull(PLACEHOLDER_VERIFIER.scan(expression(), u))) .thenOption( new Function<Unifier, Optional<Unifier>>() {
return super.scan(tree, context);
@Override protected TreeAnalysis defaultAction(Tree node, Void p) { // In general, we have no knowledge about whether a language construct // will invoke a method or not, just based on analysing its children. // For instance, an "if" makes no guarantees, an "if...else" // guarantees the intersection of its paths, and a try...finally // guarantees its finally block. TreeAnalysis result = new TreeAnalysis(); // However, any explicit return call _may_ be hit. result.explicitReturn = (RETURN_TREE_FINDER.scan(node, null) != null); return result; } };
@Override public Void scan(Tree node, Void p) { return fromIdx[0] < -1 ? super.scan(node, p) : null; } @Override
/** * Returns {@code true} if the tree contains at least one {@linkplain ErroneousTree "erroneous"} * node. */ private static boolean hasErrorNode(Tree tree) { return isTrue(HAS_ERRONEOUS_NODE.scan(tree, false)); }