use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.
the class AnnotationArgumentOrderCheck method visitNode.
@Override
public void visitNode(Tree tree) {
AnnotationTree annotationTree = (AnnotationTree) tree;
TypeSymbol annotationSymbol = annotationTree.symbolType().symbol();
if (annotationSymbol.isUnknown()) {
return;
}
List<String> declarationNames = new ArrayList<>();
for (Symbol symbol : annotationSymbol.memberSymbols()) {
declarationNames.add(symbol.name());
}
List<String> annotationArguments = new ArrayList<>();
for (ExpressionTree argument : annotationTree.arguments()) {
if (argument.is(Tree.Kind.ASSIGNMENT)) {
AssignmentExpressionTree assignmentTree = (AssignmentExpressionTree) argument;
IdentifierTree nameTree = (IdentifierTree) assignmentTree.variable();
annotationArguments.add(nameTree.name());
}
}
declarationNames.retainAll(annotationArguments);
if (!declarationNames.equals(annotationArguments)) {
reportIssue(annotationTree.annotationType(), "Reorder annotation arguments to match the order of declaration.");
}
}
use of org.sonar.plugins.java.api.tree.ExpressionTree 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.ExpressionTree 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.ExpressionTree in project sonar-java by SonarSource.
the class InvalidDateValuesCheck method onMethodInvocationFound.
@Override
protected void onMethodInvocationFound(MethodInvocationTree mit) {
String name = getMethodName(mit);
Arguments arguments = mit.arguments();
if ("set".equals(name)) {
// Calendar method
ExpressionTree arg0 = arguments.get(0);
ExpressionTree arg1 = arguments.get(1);
String referenceName = getReferencedCalendarName(arg0);
if (referenceName != null) {
checkArgument(arg1, referenceName, "\"{0}\" is not a valid value for setting \"{1}\".");
}
} else if ("<init>".equals(mit.symbol().name())) {
// call to this() or super()
checkConstructorArguments(mit.arguments());
} else {
checkArgument(arguments.get(0), name, "\"{0}\" is not a valid value for \"{1}\" method.");
}
}
use of org.sonar.plugins.java.api.tree.ExpressionTree 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);
}
}
}
Aggregations