use of org.sonar.plugins.java.api.tree.AssignmentExpressionTree in project sonar-java by SonarSource.
the class CollectionMethodsWithLinearComplexityCheck method usageInAssignment.
private static Stream<AssignmentExpressionTree> usageInAssignment(IdentifierTree usage) {
Tree prevParent = usage;
Tree parent = usage.parent();
while (parent != null && !parent.is(Tree.Kind.ASSIGNMENT) && parent.is(Tree.Kind.MEMBER_SELECT, Tree.Kind.IDENTIFIER)) {
prevParent = parent;
parent = parent.parent();
}
if (parent != null && parent.is(Tree.Kind.ASSIGNMENT)) {
AssignmentExpressionTree assignment = (AssignmentExpressionTree) parent;
if (assignment.variable().equals(prevParent)) {
return Stream.of(assignment);
}
}
return Stream.empty();
}
use of org.sonar.plugins.java.api.tree.AssignmentExpressionTree in project sonar-java by SonarSource.
the class OperatorPrecedenceCheck method visitAnnotation.
@Override
public void visitAnnotation(AnnotationTree tree) {
stack.push(null);
for (ExpressionTree argument : tree.arguments()) {
if (argument.is(Tree.Kind.ASSIGNMENT)) {
scan(((AssignmentExpressionTree) argument).expression());
} else {
scan(argument);
}
}
stack.pop();
}
use of org.sonar.plugins.java.api.tree.AssignmentExpressionTree in project sonar-java by SonarSource.
the class OperatorPrecedenceCheck method visitIfStatement.
@Override
public void visitIfStatement(IfStatementTree tree) {
super.visitIfStatement(tree);
ExpressionTree condition = tree.condition();
if (condition.is(Tree.Kind.ASSIGNMENT) && EQUALITY_RELATIONAL_OPERATORS.contains(((AssignmentExpressionTree) condition).expression().kind())) {
raiseIssue(((AssignmentExpressionTree) condition).operatorToken().line(), tree);
}
}
use of org.sonar.plugins.java.api.tree.AssignmentExpressionTree in project sonar-java by SonarSource.
the class LiveVariables method processBlockElements.
private void processBlockElements(CFG.Block block, Set<Symbol> blockKill, Set<Symbol> blockGen) {
// process elements from bottom to top
Set<Tree> assignmentLHS = new HashSet<>();
for (Tree element : Lists.reverse(block.elements())) {
switch(element.kind()) {
case ASSIGNMENT:
processAssignment((AssignmentExpressionTree) element, blockKill, blockGen, assignmentLHS);
break;
case IDENTIFIER:
processIdentifier((IdentifierTree) element, blockGen, assignmentLHS);
break;
case MEMBER_SELECT:
processMemberSelect((MemberSelectExpressionTree) element, assignmentLHS, blockGen);
break;
case VARIABLE:
blockKill.add(((VariableTree) element).symbol());
blockGen.remove(((VariableTree) element).symbol());
break;
case LAMBDA_EXPRESSION:
blockGen.addAll(getUsedVariables(((LambdaExpressionTree) element).body(), cfg.methodSymbol()));
break;
case METHOD_REFERENCE:
blockGen.addAll(getUsedVariables(((MethodReferenceTree) element).expression(), cfg.methodSymbol()));
break;
case NEW_CLASS:
blockGen.addAll(getUsedVariables(((NewClassTree) element).classBody(), cfg.methodSymbol()));
break;
default:
}
}
}
use of org.sonar.plugins.java.api.tree.AssignmentExpressionTree in project sonar-java by SonarSource.
the class LiveVariables method processAssignment.
private void processAssignment(AssignmentExpressionTree element, Set<Symbol> blockKill, Set<Symbol> blockGen, Set<Tree> assignmentLHS) {
Symbol symbol = null;
ExpressionTree lhs = element.variable();
if (lhs.is(Kind.IDENTIFIER)) {
symbol = ((IdentifierTree) lhs).symbol();
} else if (includeFields && lhs.is(Kind.MEMBER_SELECT)) {
symbol = getField((MemberSelectExpressionTree) lhs);
}
if (symbol != null && includeSymbol(symbol)) {
assignmentLHS.add(lhs);
blockGen.remove(symbol);
blockKill.add(symbol);
}
}
Aggregations