use of org.sonar.plugins.java.api.tree.IdentifierTree 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.IdentifierTree 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.IdentifierTree in project sonar-java by SonarSource.
the class ImmediateReverseBoxingCheck method addUnboxingIssue.
private void addUnboxingIssue(ExpressionTree expressionTree, ExpressionTree expression) {
if (expression.is(Tree.Kind.IDENTIFIER)) {
IdentifierTree identifier = (IdentifierTree) expression;
reportIssue(expressionTree, "Remove the unboxing of \"" + identifier.name() + "\".");
} else {
String name = expression.symbolType().name();
reportIssue(expressionTree, "Remove the unboxing from \"" + name + "\".");
}
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class ImmediateReverseBoxingCheck method addBoxingIssue.
private void addBoxingIssue(Tree tree, Symbol classSymbol, Tree boxingArg) {
if (boxingArg.is(Tree.Kind.IDENTIFIER)) {
IdentifierTree identifier = (IdentifierTree) boxingArg;
reportIssue(tree, "Remove the boxing of \"" + identifier.name() + "\".");
} else {
reportIssue(tree, "Remove the boxing to \"" + classSymbol.name() + "\".");
}
}
use of org.sonar.plugins.java.api.tree.IdentifierTree 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.");
}
}
}
Aggregations