boolean containsExplicitThrowableException(Tree tree) { containsExplicitThrowable = false; tree.accept(this); return containsExplicitThrowable; }
@Override public void accept(TreeVisitor visitor) { for (T t : list) { t.accept(visitor); } }
private static boolean throwsException(Tree tree) { ThrowExceptionVisitor visitor = new ThrowExceptionVisitor(); tree.accept(visitor); return visitor.throwsException; }
@Override public ProgramState checkPostStatement(CheckerContext context, Tree syntaxNode) { final PostStatementVisitor visitor = new PostStatementVisitor(context); syntaxNode.accept(visitor); return visitor.programState; }
@Override public ProgramState checkPreStatement(CheckerContext context, Tree syntaxNode) { AbstractStatementVisitor visitor = new PreStatementVisitor(context); syntaxNode.accept(visitor); return visitor.programState; }
@Override public ProgramState checkPostStatement(CheckerContext context, Tree syntaxNode) { final PostStatementVisitor visitor = new PostStatementVisitor(context); syntaxNode.accept(visitor); return visitor.programState; }
private static Set<String> unresolvedIdentifierNames(Tree tree) { UnresolvedIdentifierVisitor visitor = new UnresolvedIdentifierVisitor(); tree.accept(visitor); return visitor.unresolvedIdentifierNames; }
private static boolean mayHaveSideEffect(Tree tree) { MethodInvocationFinder methodInvocationFinder = new MethodInvocationFinder(); tree.accept(methodInvocationFinder); return methodInvocationFinder.found; }
@Override public ProgramState checkPostStatement(CheckerContext context, Tree syntaxNode) { PostStatementVisitor visitor = new PostStatementVisitor(context); syntaxNode.accept(visitor); return visitor.programState; }
@Override public ProgramState checkPreStatement(CheckerContext context, Tree syntaxNode) { final PreStatementVisitor visitor = new PreStatementVisitor(context); syntaxNode.accept(visitor); return visitor.programState; }
private Set<Symbol> getUsedVariables(@Nullable Tree syntaxNode, Symbol.MethodSymbol owner) { if(syntaxNode == null) { return Collections.emptySet(); } VariableReadExtractor extractorFromClass = new VariableReadExtractor(owner, includeFields); syntaxNode.accept(extractorFromClass); return extractorFromClass.usedVariables(); }
@CheckForNull private static TypeTree getTypeFromExpression(Tree expression, Tree.Kind[] kinds) { if (expression.is(kinds)) { TypeTreeLocator visitor = new TypeTreeLocator(kinds); expression.accept(visitor); return visitor.type; } return null; }
private static Set<Symbol> getUsedLocalVarInSubTree(Tree tree, Symbol.MethodSymbol methodSymbol) { VariableReadExtractor localVarExtractor = new VariableReadExtractor(methodSymbol, false); tree.accept(localVarExtractor); return localVarExtractor.usedVariables(); }
public static String getName(Tree syntaxNode) { SyntaxTreeNameFinder finder = new SyntaxTreeNameFinder(); syntaxNode.accept(finder); return finder.getName(); }
private static boolean isReassigned(Symbol variableSymbol, Tree method) { Collection<IdentifierTree> usages = variableSymbol.usages(); ReAssignmentFinder reAssignmentFinder = new ReAssignmentFinder(usages); method.accept(reAssignmentFinder); return reAssignmentFinder.foundReAssignment; }
@Override public ProgramState checkPreStatement(CheckerContext context, Tree syntaxNode) { if (contexts.peek().isThreadRunMethod()) { // It is OK to have an endless Thread run method return context.getState(); } final PreStatementVisitor visitor = new PreStatementVisitor(context); syntaxNode.accept(visitor); return visitor.programState; }
@Override protected void onConstructorFound(NewClassTree newClassTree) { Tree mTree = ExpressionUtils.getEnclosingMethod(newClassTree); if (mTree != null) { MethodInvocationVisitor mitVisit = new MethodInvocationVisitor(newClassTree); mTree.accept(mitVisit); if (!mitVisit.secureRandomFound) { reportIssue(newClassTree, "Use a dynamically-generated, random IV."); } } }
private static boolean methodReturningVariableWithSameName(Symbol methodSymbol, Symbol variableSymbol) { if (!sameName(variableSymbol, methodSymbol)) { return false; } Tree declaration = methodSymbol.declaration(); if (declaration != null) { ReturnVisitor returnVisitor = new ReturnVisitor(variableSymbol); declaration.accept(returnVisitor); return returnVisitor.singleReturnWithVariableSymbol(); } return false; }
@Override protected void onMethodInvocationFound(MethodInvocationTree methodInvocation) { Tree enclosingMethod = ExpressionUtils.getEnclosingMethod(methodInvocation); if (enclosingMethod == null) { return; } MethodBodyVisitor visitor = new MethodBodyVisitor(); enclosingMethod.accept(visitor); if (!visitor.foundCallsToSecuringMethods()) { reportIssue(methodInvocation.methodSelect(), "Secure this \"Transformer\" by either disabling external DTDs or enabling secure processing."); } }
@Override public void visitNode(Tree tree) { MethodTree methodTree = (MethodTree) tree; if (hasSemantic() && isIteratorNextMethod(methodTree.symbol()) && methodTree.block() != null) { NextMethodBodyVisitor visitor = new NextMethodBodyVisitor(); tree.accept(visitor); if (!visitor.foundThrow) { reportIssue(methodTree.simpleName(), "Add a \"NoSuchElementException\" for iteration beyond the end of the collection."); } } }