@Override public void visitForEachStatement(ForEachStatement tree) { scan(tree.variable()); scan(tree.expression()); scan(tree.statement()); }
public void isCallingGetWithSymbol(ForEachStatement forEachTree, Symbol variable, Symbol mapSymbol) { this.variable = variable; result = false; this.mapSymbol = mapSymbol; scan(forEachTree.statement()); if (result) { reportIssue(forEachTree.forKeyword(), "Iterate over the \"entrySet\" instead of the \"keySet\"."); } }
@Override public void visitForEachStatement(ForEachStatement tree) { // do not scan the variable and expression addLines(tree.forKeyword(), tree.closeParenToken()); addLineOfCloseBrace(tree.forKeyword(), tree.statement()); scan(tree.statement()); }
@Override public void visitForEachStatement(ForEachStatement tree) { ExpressionTree expression = tree.expression(); if (expression instanceof IdentifierTree && isResourceIterator((IdentifierTree) expression)) { checkModelProviderCall(tree, tree.statement()); } super.visitForEachStatement(tree); }
@Override public void visitForEachStatement(ForEachStatement tree) { scan(tree.statement()); }
@Override public void visitNode(Tree tree) { if (hasSemantic()) { ForEachStatement forEachTree = (ForEachStatement) tree; ExpressionTree expressionTree = forEachTree.expression(); if (expressionTree.is(Tree.Kind.METHOD_INVOCATION)) { MethodInvocationTree methodTree = (MethodInvocationTree) expressionTree; Symbol ownerSymbol = getOwnerSymbol(methodTree); if (ownerSymbol != null && MAP_KEYSET_METHOD.matches(methodTree)) { new GetUsageVisitor().isCallingGetWithSymbol(forEachTree, forEachTree.variable().symbol(), ownerSymbol); } } } }
private void checkForEach(Map<Symbol, Integer> forEachSymbols, @Nullable Tree previousIterable, ForEachStatement item) { ExpressionTree expressionTree = ExpressionUtils.skipParentheses(item.expression()); if (expressionTree.is(Tree.Kind.IDENTIFIER)) { checkForEachIdentifier(forEachSymbols, (IdentifierTree) expressionTree); } else if (previousIterable != null) { checkForEachExpression(previousIterable, expressionTree); } }
@Override public void visitForEachStatement(ForEachStatement tree) { checkBlock(tree.closeParenToken(), tree.statement()); super.visitForEachStatement(tree); }
@Override public void visitForEachStatement(ForEachStatement tree) { CFG cfg = CFG.buildCFG(Collections.singletonList(tree), true); Symbol var = tree.variable().symbol(); boolean liveVar = true; if(var.owner().isMethodSymbol()) { cfg.setMethodSymbol((Symbol.MethodSymbol) var.owner()); LiveVariables analyze = LiveVariables.analyze(cfg); Set<Symbol> live = analyze.getOut(cfg.reversedBlocks().get(1)); liveVar = live.contains(var); } if(!liveVar) { variables.add(var); } super.visitForEachStatement(tree); if(!liveVar) { variables.remove(var); } }
@Override public void visitForEachStatement(ForEachStatement tree) { SyntaxToken forKeyword = tree.forKeyword(); checkNesting(forKeyword); nestingLevel.push(forKeyword); super.visitForEachStatement(tree); nestingLevel.pop(); }
@Override public void visitForEachStatement(ForEachStatement tree) { scan(tree.expression()); currentState.invalidateVariables(new AssignmentVisitor().findAssignedVariables(tree.statement())); currentState = new State(currentState); scan(tree.statement()); restorePreviousState(); }
@Override public void visitForEachStatement(ForEachStatement tree) { scan(tree.statement()); }
@Override public void visitNode(Tree tree) { if (hasSemantic()) { ForEachStatement forEachTree = (ForEachStatement) tree; ExpressionTree expressionTree = forEachTree.expression(); if (expressionTree.is(Tree.Kind.METHOD_INVOCATION)) { MethodInvocationTree methodTree = (MethodInvocationTree) expressionTree; Symbol ownerSymbol = getOwnerSymbol(methodTree); if (ownerSymbol != null && MAP_KEYSET_METHOD.matches(methodTree)) { new GetUsageVisitor().isCallingGetWithSymbol(forEachTree, forEachTree.variable().symbol(), ownerSymbol); } } } }
private void checkForEach(Map<Symbol, Integer> forEachSymbols, @Nullable Tree previousIterable, ForEachStatement item) { ExpressionTree expressionTree = ExpressionUtils.skipParentheses(item.expression()); if (expressionTree.is(Tree.Kind.IDENTIFIER)) { checkForEachIdentifier(forEachSymbols, (IdentifierTree) expressionTree); } else if (previousIterable != null) { checkForEachExpression(previousIterable, expressionTree); } }
@Override public void visitForEachStatement(ForEachStatement tree) { checkBlock(tree.closeParenToken(), tree.statement()); super.visitForEachStatement(tree); }
@Override public void visitForEachStatement(ForEachStatement tree) { CFG cfg = CFG.buildCFG(Collections.singletonList(tree), true); Symbol var = tree.variable().symbol(); boolean liveVar = true; if(var.owner().isMethodSymbol()) { cfg.setMethodSymbol((Symbol.MethodSymbol) var.owner()); LiveVariables analyze = LiveVariables.analyze(cfg); Set<Symbol> live = analyze.getOut(cfg.reversedBlocks().get(1)); liveVar = live.contains(var); } if(!liveVar) { variables.add(var); } super.visitForEachStatement(tree); if(!liveVar) { variables.remove(var); } }
@Override public void visitForEachStatement(ForEachStatement tree) { SyntaxToken forKeyword = tree.forKeyword(); checkNesting(forKeyword); nestingLevel.push(forKeyword); super.visitForEachStatement(tree); nestingLevel.pop(); }
@Override public void visitForEachStatement(ForEachStatement tree) { scan(tree.variable()); scan(tree.expression()); scan(tree.statement()); }
@Override public void visitForEachStatement(ForEachStatement tree) { for (ExecutionState state : currentStates) { evaluateExpression(state, tree.expression()); } invalidateAssignedVariables(extractor.findAssignedVariables(tree)); currentStates = evaluateStatement(currentStates, tree.statement()); invalidateAssignedVariables(extractor.findAssignedVariables(tree)); }
public void isCallingGetWithSymbol(ForEachStatement forEachTree, Symbol variable, Symbol mapSymbol) { this.variable = variable; result = false; this.mapSymbol = mapSymbol; scan(forEachTree.statement()); if (result) { reportIssue(forEachTree.forKeyword(), "Iterate over the \"entrySet\" instead of the \"keySet\"."); } }