use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class SyntaxTreeNameFinder method visitMemberSelectExpression.
@Override
public void visitMemberSelectExpression(MemberSelectExpressionTree tree) {
ExpressionTree expression = ExpressionUtils.skipParentheses(tree.expression());
if (expression.is(Tree.Kind.IDENTIFIER)) {
String identifierName = ((IdentifierTree) expression).name();
if ("this".equals(identifierName) || "super".equals(identifierName)) {
tree.identifier().accept(this);
return;
}
}
expression.accept(this);
}
use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class ModulusEqualityCheck method isSizeAccessor.
private static boolean isSizeAccessor(ExpressionTree expressionTree) {
if (expressionTree.is(Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) expressionTree;
Type type = memberSelectExpressionTree.expression().symbolType();
String memberName = memberSelectExpressionTree.identifier().name();
return isCollectionSize(type, memberName) || isStringLength(type, memberName) || isArrayLength(type, memberName);
} else if (expressionTree.is(Kind.METHOD_INVOCATION)) {
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) expressionTree;
return isSizeAccessor(methodInvocationTree.methodSelect());
}
return false;
}
use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class ModulusEqualityCheck method isMethodParameter.
private boolean isMethodParameter(ExpressionTree expressionTree) {
if (expressionTree.is(Tree.Kind.IDENTIFIER)) {
IdentifierTree identifier = (IdentifierTree) expressionTree;
Symbol symbol = identifier.symbol();
return methodParams.contains(symbol);
} else if (expressionTree.is(Tree.Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) expressionTree;
return isMethodParameter(memberSelectExpressionTree.expression());
} else if (expressionTree.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) expressionTree;
return isMethodParameter(methodInvocationTree.methodSelect());
}
return false;
}
use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree 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.MemberSelectExpressionTree 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