use of org.sonar.plugins.java.api.tree.Arguments 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.Arguments in project sonar-java by SonarSource.
the class DefaultEncodingUsageCheck method onMethodInvocationFound.
@Override
protected void onMethodInvocationFound(MethodInvocationTree mit) {
if (COMMONS_IO_CHARSET_MATCHERS.anyMatch(mit)) {
Arguments arguments = mit.arguments();
ExpressionTree lastArgument = arguments.get(arguments.size() - 1);
testNullLiteralPassedForEncoding(lastArgument);
} else if (FILEUTILS_WRITE_WITH_CHARSET_MATCHERS.anyMatch(mit)) {
testNullLiteralPassedForEncoding(mit.arguments().get(2));
} else {
reportIssue(ExpressionUtils.methodName(mit), "Remove this use of \"" + mit.symbol().name() + "\"");
}
}
use of org.sonar.plugins.java.api.tree.Arguments in project sonar-java by SonarSource.
the class TypeAndReferenceSolver method completeMetadata.
private static void completeMetadata(JavaSymbol symbol, List<AnnotationTree> annotations) {
for (AnnotationTree tree : annotations) {
AnnotationInstanceResolve annotationInstance = new AnnotationInstanceResolve((JavaSymbol.TypeJavaSymbol) tree.symbolType().symbol());
symbol.metadata().addAnnotation(annotationInstance);
Arguments arguments = tree.arguments();
if (arguments.size() > 1 || (!arguments.isEmpty() && arguments.get(0).is(Tree.Kind.ASSIGNMENT))) {
for (ExpressionTree expressionTree : arguments) {
AssignmentExpressionTree aet = (AssignmentExpressionTree) expressionTree;
// TODO: Store more precise value than the expression (real value in case of literal, symbol for enums, array of values, solve constants?)
annotationInstance.addValue(new AnnotationValueResolve(((IdentifierTree) aet.variable()).name(), aet.expression()));
}
} else {
// Constant
addConstantValue(tree, annotationInstance);
}
}
}
use of org.sonar.plugins.java.api.tree.Arguments in project sonar-java by SonarSource.
the class TypeAndReferenceSolver method visitAnnotation.
@Override
public void visitAnnotation(AnnotationTree tree) {
if (((AbstractTypedTree) tree.annotationType()).isTypeSet()) {
// This handle the case where type and its annotation is shared between two variables.
return;
}
resolveAs(tree.annotationType(), JavaSymbol.TYP);
Arguments arguments = tree.arguments();
if (arguments.size() > 1 || (!arguments.isEmpty() && arguments.get(0).is(Tree.Kind.ASSIGNMENT))) {
// resolve by identifying correct identifier in assignment.
for (ExpressionTree expressionTree : arguments) {
AssignmentExpressionTree aet = (AssignmentExpressionTree) expressionTree;
IdentifierTree variable = (IdentifierTree) aet.variable();
JavaSymbol identInType = resolve.findMethod(semanticModel.getEnv(tree), getType(tree.annotationType()), variable.name(), ImmutableList.<JavaType>of()).symbol();
associateReference(variable, identInType);
JavaType type = identInType.type;
if (type == null) {
type = Symbols.unknownType;
}
registerType(variable, type);
resolveAs(aet.expression(), JavaSymbol.VAR);
}
} else {
for (ExpressionTree expressionTree : arguments) {
resolveAs(expressionTree, JavaSymbol.VAR);
}
}
registerType(tree, getType(tree.annotationType()));
}
use of org.sonar.plugins.java.api.tree.Arguments in project sonar-java by SonarSource.
the class ArrayForVarArgCheck method visitNode.
@Override
public void visitNode(Tree tree) {
Symbol sym;
Arguments args;
Tree methodName;
if (tree.is(Tree.Kind.NEW_CLASS)) {
NewClassTree nct = (NewClassTree) tree;
sym = nct.constructorSymbol();
args = nct.arguments();
methodName = nct.identifier();
} else {
MethodInvocationTree mit = (MethodInvocationTree) tree;
sym = mit.symbol();
args = mit.arguments();
methodName = mit.methodSelect();
}
if (sym.isMethodSymbol() && !args.isEmpty()) {
ExpressionTree lastArg = args.get(args.size() - 1);
JavaSymbol.MethodJavaSymbol methodSymbol = (JavaSymbol.MethodJavaSymbol) sym;
MethodJavaType methodType = getMethodType(methodSymbol, methodName);
checkInvokedMethod(methodSymbol, methodType, lastArg);
}
}
Aggregations