use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class LocksNotUnlockedCheck method reportIssue.
private void reportIssue(JavaFileScannerContext.Location location) {
if (location.syntaxNode.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree syntaxNode = (MethodInvocationTree) location.syntaxNode;
Tree tree = issueTree(syntaxNode);
reportIssue(tree, "Unlock this lock along all executions paths of this method.");
}
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class NullDereferenceCheck method setNullConstraint.
private static List<ProgramState> setNullConstraint(CheckerContext context, Tree syntaxNode) {
SymbolicValue val = context.getState().peekValue();
if (syntaxNode.is(Tree.Kind.METHOD_INVOCATION) && isAnnotatedCheckForNull((MethodInvocationTree) syntaxNode)) {
Preconditions.checkNotNull(val);
List<ProgramState> states = new ArrayList<>();
states.addAll(val.setConstraint(context.getState(), ObjectConstraint.NULL));
states.addAll(val.setConstraint(context.getState(), ObjectConstraint.NOT_NULL));
return states;
}
return Lists.newArrayList(context.getState());
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class NullDereferenceCheck method checkPreStatement.
@Override
public ProgramState checkPreStatement(CheckerContext context, Tree syntaxNode) {
if (context.getState().peekValue() == null) {
// stack is empty, nothing to do.
return context.getState();
}
if (syntaxNode.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree methodInvocation = (MethodInvocationTree) syntaxNode;
Tree methodSelect = methodInvocation.methodSelect();
if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
SymbolicValue dereferencedSV = context.getState().peekValue(methodInvocation.arguments().size());
return checkConstraint(context, methodSelect, dereferencedSV);
}
}
if (syntaxNode.is(Tree.Kind.ARRAY_ACCESS_EXPRESSION)) {
Tree toCheck = ((ArrayAccessExpressionTree) syntaxNode).expression();
SymbolicValue currentVal = context.getState().peekValue(1);
return checkConstraint(context, toCheck, currentVal);
}
if (syntaxNode.is(Tree.Kind.MEMBER_SELECT)) {
return checkMemberSelect(context, (MemberSelectExpressionTree) syntaxNode, context.getState().peekValue());
}
return context.getState();
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class ParameterNullnessCheck method checkPreStatement.
@Override
public ProgramState checkPreStatement(CheckerContext context, Tree syntaxNode) {
ProgramState state = context.getState();
if (syntaxNode.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) syntaxNode;
checkParameters(mit, mit.symbol(), mit.arguments(), state);
} else if (syntaxNode.is(Tree.Kind.NEW_CLASS)) {
NewClassTree nct = (NewClassTree) syntaxNode;
checkParameters(nct, nct.constructorSymbol(), nct.arguments(), state);
}
return state;
}
use of org.sonar.plugins.java.api.tree.MethodInvocationTree in project sonar-java by SonarSource.
the class AbsOnNegativeCheck method checkForIssue.
private void checkForIssue(ExpressionTree tree) {
if (tree.is(Tree.Kind.MEMBER_SELECT)) {
Symbol identifierSymbol = ((MemberSelectExpressionTree) tree).identifier().symbol();
Type ownerType = identifierSymbol.owner().type();
if ("MIN_VALUE".equals(identifierSymbol.name()) && (ownerType.is("java.lang.Integer") || ownerType.is("java.lang.Long"))) {
reportIssue(tree, "Use the original value instead.");
}
} else {
MethodInvocationTree nestedTree = extractMethodInvocation(tree);
if (nestedTree != null && NEGATIVE_METHODS.anyMatch(nestedTree)) {
reportIssue(nestedTree, "Use the original value instead.");
}
}
}
Aggregations