use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class AbstractInjectionChecker method isDynamicString.
protected boolean isDynamicString(Tree methodTree, ExpressionTree arg, @Nullable Symbol currentlyChecking, boolean firstLevel) {
if (arg.is(Tree.Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) arg;
IdentifierTree identifier = memberSelectExpressionTree.identifier();
if (ExpressionUtils.isSelectOnThisOrSuper(memberSelectExpressionTree)) {
return isIdentifierDynamicString(methodTree, identifier, currentlyChecking, firstLevel);
}
return !isConstant(identifier.symbol());
} else if (arg.is(Tree.Kind.IDENTIFIER)) {
return isIdentifierDynamicString(methodTree, (IdentifierTree) arg, currentlyChecking, firstLevel);
} else if (arg.is(Tree.Kind.PLUS)) {
BinaryExpressionTree binaryArg = (BinaryExpressionTree) arg;
return isDynamicString(methodTree, binaryArg.rightOperand(), currentlyChecking) || isDynamicString(methodTree, binaryArg.leftOperand(), currentlyChecking);
} else if (arg.is(Tree.Kind.METHOD_INVOCATION)) {
return false;
}
return !arg.is(Tree.Kind.STRING_LITERAL, Tree.Kind.NULL_LITERAL);
}
use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class ImmediateReverseBoxingCheck method checkForUnboxing.
private void checkForUnboxing(ExpressionTree expressionTree) {
if (!expressionTree.is(Tree.Kind.METHOD_INVOCATION)) {
return;
}
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) expressionTree;
if (isUnboxingMethodInvocation(methodInvocationTree)) {
ExpressionTree methodSelect = methodInvocationTree.methodSelect();
if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) methodSelect;
ExpressionTree unboxedExpression = memberSelectExpressionTree.expression();
String unboxingResultTypeName = methodInvocationTree.symbolType().fullyQualifiedName();
if (unboxingResultTypeName.equals(PRIMITIVE_TYPES_BY_WRAPPER.get(unboxedExpression.symbolType().fullyQualifiedName()))) {
addUnboxingIssue(expressionTree, unboxedExpression);
}
}
}
}
use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class IdenticalOperandOnBinaryExpressionCheck method checkEqualsMethods.
private void checkEqualsMethods(MethodInvocationTree mit) {
if (EQUALS_MATCHER.matches(mit)) {
if (mit.methodSelect().is(Tree.Kind.MEMBER_SELECT)) {
ExpressionTree leftOp = ((MemberSelectExpressionTree) mit.methodSelect()).expression();
ExpressionTree rightOp = mit.arguments().get(0);
if (SyntacticEquivalence.areEquivalent(leftOp, rightOp)) {
reportIssue(rightOp, "Correct one of the identical sub-expressions on both sides of equals.", ImmutableList.of(new JavaFileScannerContext.Location("", leftOp)), null);
}
}
} else if (DEEP_EQUALS_MATCHER.matches(mit) || OBJECTS_EQUALS_MATCHER.matches(mit)) {
ExpressionTree leftOp = mit.arguments().get(0);
ExpressionTree rightOp = mit.arguments().get(1);
if (SyntacticEquivalence.areEquivalent(leftOp, rightOp)) {
reportIssue(rightOp, "Correct one of the identical argument sub-expressions.", ImmutableList.of(new JavaFileScannerContext.Location("", leftOp)), null);
}
}
}
use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class FileCreateTempFileCheck method checkAndAdvanceState.
@Nullable
private State checkAndAdvanceState(MethodInvocationTree mit, State requiredState, State nextState) {
ExpressionTree methodSelect = mit.methodSelect();
if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
ExpressionTree expressionTree = ((MemberSelectExpressionTree) methodSelect).expression();
if (expressionTree.is(Tree.Kind.IDENTIFIER)) {
Symbol symbol = ((IdentifierTree) expressionTree).symbol();
Map<Symbol, State> symbolStateMap = symbolStack.peek();
if (symbolStateMap != null && symbolStateMap.containsKey(symbol) && requiredState.equals(symbolStateMap.get(symbol))) {
symbolStateMap.put(symbol, nextState);
return nextState;
}
}
}
return null;
}
use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class CFG method buildMethodInvocation.
private void buildMethodInvocation(MethodInvocationTree mit) {
handleExceptionalPaths(mit.symbol());
currentBlock.elements.add(mit);
build(mit.arguments());
if (mit.methodSelect().is(Tree.Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree memberSelect = (MemberSelectExpressionTree) mit.methodSelect();
build(memberSelect.expression());
} else {
build(mit.methodSelect());
}
}
Aggregations