use of org.sonar.plugins.java.api.tree.MethodTree in project sonar-java by SonarSource.
the class ConfusingOverloadCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
MethodTree methodTree = (MethodTree) tree;
if (Boolean.FALSE.equals(methodTree.isOverriding())) {
Symbol.MethodSymbol methodSymbol = methodTree.symbol();
Symbol.TypeSymbol owner = (Symbol.TypeSymbol) methodSymbol.owner();
Type superClass = owner.superClass();
if (superClass != null && !SERIALIZATION_METHOD_NAME.contains(methodSymbol.name())) {
boolean reportStaticIssue = checkMethod(methodTree.simpleName(), methodSymbol, superClass);
superClass = superClass.symbol().superClass();
while (superClass != null && !reportStaticIssue) {
reportStaticIssue = checkStaticMethod(methodTree.simpleName(), methodSymbol, superClass);
superClass = superClass.symbol().superClass();
}
}
}
}
use of org.sonar.plugins.java.api.tree.MethodTree in project sonar-java by SonarSource.
the class CloneOverrideCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
MethodTree methodTree = (MethodTree) tree;
IdentifierTree identifierTree = methodTree.simpleName();
if (methodTree.parameters().isEmpty() && "clone".equals(identifierTree.name()) && !isUnsupportedCloneOverride(methodTree)) {
reportIssue(identifierTree, "Remove this \"clone\" implementation; use a copy constructor or copy factory instead.");
}
}
use of org.sonar.plugins.java.api.tree.MethodTree in project sonar-java by SonarSource.
the class AssertsOnParametersOfPublicMethodCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
MethodTree methodTree = (MethodTree) tree;
if (!methodTree.symbol().isPublic()) {
return;
}
methodTree.parameters().stream().map(VariableTree::symbol).map(Symbol::usages).flatMap(List::stream).forEach(parameter -> checkUsage(parameter, methodTree));
}
use of org.sonar.plugins.java.api.tree.MethodTree in project sonar-java by SonarSource.
the class ReassignmentFinderTest method parameter_with_usage.
@Test
public void parameter_with_usage() throws Exception {
String code = newCode("int foo(boolean test) {", " if (test) {}", " return test;", "}");
MethodTree method = methodTree(code);
List<StatementTree> statements = method.block().body();
assertThatLastReassignmentsOfReturnedVariableIsEqualTo(statements, null);
}
use of org.sonar.plugins.java.api.tree.MethodTree in project sonar-java by SonarSource.
the class ExplodedGraphWalker method startingStates.
private Iterable<ProgramState> startingStates(MethodTree tree, ProgramState currentState) {
Stream<ProgramState> stateStream = Stream.of(currentState);
boolean isEqualsMethod = EQUALS.matches(tree);
boolean nonNullParameters = isGloballyAnnotatedParameterNonNull(methodTree.symbol());
boolean nullableParameters = isGloballyAnnotatedParameterNullable(methodTree.symbol());
boolean hasMethodBehavior = methodBehavior != null;
for (final VariableTree variableTree : tree.parameters()) {
// create
final SymbolicValue sv = constraintManager.createSymbolicValue(variableTree);
Symbol variableSymbol = variableTree.symbol();
if (hasMethodBehavior) {
methodBehavior.addParameter(sv);
}
stateStream = stateStream.map(ps -> ps.put(variableSymbol, sv));
if (isEqualsMethod || parameterCanBeNull(variableSymbol, nullableParameters)) {
stateStream = stateStream.flatMap((ProgramState ps) -> Stream.concat(sv.setConstraint(ps, ObjectConstraint.NULL).stream(), sv.setConstraint(ps, ObjectConstraint.NOT_NULL).stream()));
} else if (nonNullParameters || isAnnotatedNonNull(variableSymbol)) {
stateStream = stateStream.flatMap(ps -> sv.setConstraint(ps, ObjectConstraint.NOT_NULL).stream());
}
}
return stateStream.collect(Collectors.toList());
}
Aggregations