use of org.sonar.plugins.java.api.tree.MethodTree in project sonar-java by SonarSource.
the class AssertionInThreadRunCheck method visitNode.
@Override
public void visitNode(Tree tree) {
MethodTree methodTree = (MethodTree) tree;
BlockTree block = methodTree.block();
if (block != null && isRunMethod(methodTree)) {
block.accept(new AssertionsVisitor());
}
}
use of org.sonar.plugins.java.api.tree.MethodTree in project sonar-java by SonarSource.
the class AssertsOnParametersOfPublicMethodCheck method checkUsage.
private void checkUsage(IdentifierTree parameterUsage, MethodTree methodTree) {
Tree parameterParent = parameterUsage.parent();
while (!parameterParent.equals(methodTree) && !assertReported.contains(parameterParent)) {
if (parameterParent.is(Tree.Kind.ASSERT_STATEMENT)) {
assertReported.add((AssertStatementTree) parameterParent);
reportIssue(parameterParent, "Replace this assert with a proper check.");
return;
}
parameterParent = parameterParent.parent();
}
}
use of org.sonar.plugins.java.api.tree.MethodTree in project sonar-java by SonarSource.
the class ProtectedMemberInFinalClassCheck method checkMember.
private void checkMember(Tree member) {
if (member.is(Kind.VARIABLE)) {
VariableTree variableTree = (VariableTree) member;
checkVariableCompliance(variableTree);
} else if (member.is(Kind.METHOD)) {
MethodTree methodTree = (MethodTree) member;
if (Boolean.FALSE.equals(methodTree.isOverriding())) {
checkMethodCompliance(methodTree);
}
}
}
use of org.sonar.plugins.java.api.tree.MethodTree in project sonar-java by SonarSource.
the class ModulusEqualityCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (tree.is(Tree.Kind.EQUAL_TO)) {
BinaryExpressionTree equality = (BinaryExpressionTree) tree;
checkModulusAndIntLiteral(equality.leftOperand(), equality.rightOperand());
checkModulusAndIntLiteral(equality.rightOperand(), equality.leftOperand());
} else {
MethodTree methodTree = (MethodTree) tree;
for (VariableTree variableTree : methodTree.parameters()) {
methodParams.add(variableTree.symbol());
}
}
}
use of org.sonar.plugins.java.api.tree.MethodTree in project sonar-java by SonarSource.
the class RedundantTypeCastCheck method targetType.
@CheckForNull
private static Type targetType(TypeCastTree tree) {
Tree parent = skipParentheses(tree.parent());
Type target = null;
if (parent.is(Tree.Kind.RETURN_STATEMENT)) {
Tree method = parent;
while (!method.is(Tree.Kind.METHOD, Tree.Kind.LAMBDA_EXPRESSION)) {
method = method.parent();
}
target = method.is(Tree.Kind.LAMBDA_EXPRESSION) ? null : ((MethodJavaType) ((MethodTree) method).symbol().type()).resultType();
} else if (parent.is(Tree.Kind.VARIABLE)) {
VariableTree variableTree = (VariableTree) parent;
target = variableTree.symbol().type();
} else if (parent.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) parent;
if (mit.symbol().isMethodSymbol()) {
JavaSymbol.MethodJavaSymbol sym = (JavaSymbol.MethodJavaSymbol) mit.symbol();
int castArgIndex = mit.arguments().indexOf(tree);
target = sym.parameterTypes().get(castArgIndex);
}
} else if (parent.is(Tree.Kind.MEMBER_SELECT, Tree.Kind.CONDITIONAL_EXPRESSION)) {
target = tree.type().symbolType();
} else if (parent.is(Tree.Kind.ARRAY_ACCESS_EXPRESSION)) {
target = ((ArrayAccessExpressionTree) parent).expression().symbolType();
} else if (parent instanceof ExpressionTree) {
target = ((ExpressionTree) parent).symbolType();
}
return target;
}
Aggregations