use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class KeySetInsteadOfEntrySetCheck method visitNode.
@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);
}
}
}
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree 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.MethodInvocationTree in project sonar-java by SonarSource.
the class LDAPInjectionCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
MethodInvocationTree mit = (MethodInvocationTree) tree;
if (isDirContextSearchCall(mit)) {
// Check the first two arguments of search method
checkDirContextArg(mit.arguments().get(0), mit);
checkDirContextArg(mit.arguments().get(1), mit);
} else if (isSearchControlCall(mit)) {
ExpressionTree arg = mit.arguments().get(0);
if (isDynamicArray(arg, mit)) {
reportOnArgument(arg);
}
}
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class IgnoredReturnValueCheck method visitNode.
@Override
public void visitNode(Tree tree) {
ExpressionTree expr = ((ExpressionStatementTree) tree).expression();
if (expr.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) expr;
if (isExcluded(mit)) {
return;
}
Symbol methodSymbol = mit.symbol();
if (!isVoidOrUnknown(mit.symbolType()) && isCheckedType(methodSymbol.owner().type()) && methodSymbol.isPublic() && !isConstructor(methodSymbol)) {
IdentifierTree methodName = ExpressionUtils.methodName(mit);
reportIssue(methodName, "The return value of \"" + methodName.name() + "\" must be used.");
}
}
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class EnumSetCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
VariableTree variableTree = (VariableTree) tree;
ExpressionTree initializer = variableTree.initializer();
if (initializer == null) {
return;
}
if (initializer.is(Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) initializer;
if (COLLECTIONS_UNMODIFIABLE.matches(mit)) {
// check the collection used as parameter
initializer = mit.arguments().get(0);
} else if (!SET_CREATION_METHODS.anyMatch(mit) || "immutableEnumSet".equals(mit.symbol().name())) {
// but discard any other method invocations (killing the noise)
return;
}
}
checkIssue(initializer.symbolType(), initializer, variableTree.type());
}
Aggregations