use of org.sonar.plugins.java.api.tree.MethodReferenceTree 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.MethodReferenceTree in project sonar-java by SonarSource.
the class ConstantsShouldBeStaticFinalCheck method hasConstantInitializer.
private static boolean hasConstantInitializer(VariableTree variableTree) {
ExpressionTree init = variableTree.initializer();
if (init != null) {
if (ExpressionUtils.skipParentheses(init).is(Tree.Kind.METHOD_REFERENCE)) {
MethodReferenceTree methodRef = (MethodReferenceTree) ExpressionUtils.skipParentheses(init);
if (isInstanceIdentifier(methodRef.expression())) {
return false;
}
}
boolean arrayWithInitializer = true;
if (init.is(Tree.Kind.NEW_ARRAY)) {
// exclude allocations : new int[6] but allow initialization new int[]{1,2};
NewArrayTree newArrayTree = (NewArrayTree) init;
arrayWithInitializer = newArrayTree.dimensions().isEmpty() || newArrayTree.openBraceToken() != null;
}
return arrayWithInitializer && !containsChildrenOfKind((JavaTree) init, Tree.Kind.METHOD_INVOCATION, Tree.Kind.NEW_CLASS);
}
return false;
}
Aggregations