use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class ReplaceLambdaByMethodRefCheck method isMethodInvocation.
private static boolean isMethodInvocation(@Nullable Tree tree, LambdaExpressionTree lambdaTree) {
if (tree != null && tree.is(Tree.Kind.METHOD_INVOCATION, Tree.Kind.NEW_CLASS)) {
Arguments arguments;
if (tree.is(Tree.Kind.NEW_CLASS)) {
if (((NewClassTree) tree).classBody() != null) {
return false;
}
arguments = ((NewClassTree) tree).arguments();
} else {
MethodInvocationTree mit = (MethodInvocationTree) tree;
if (hasMethodInvocationInMethodSelect(mit) || hasNonFinalFieldInMethodSelect(mit)) {
return false;
}
arguments = mit.arguments();
}
List<VariableTree> parameters = lambdaTree.parameters();
return matchingParameters(parameters, arguments) || (arguments.isEmpty() && isNoArgMethodInvocationFromLambdaParam(tree, parameters));
}
return false;
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class ServletInstanceFieldCheck method reportIssuesOnVariable.
private void reportIssuesOnVariable() {
issuableVariables.removeAll(excludedVariables);
for (VariableTree variable : issuableVariables) {
reportIssue(variable.simpleName(), "Remove this misleading mutable servlet instance field or make it \"static\" and/or \"final\"");
}
issuableVariables.clear();
excludedVariables.clear();
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class SecureCookieCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (hasSemantic()) {
if (tree.is(Tree.Kind.VARIABLE)) {
VariableTree variableTree = (VariableTree) tree;
addToUnsecuredCookies(variableTree);
} else if (tree.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) tree;
checkSecureCall(mit);
}
}
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class RedundantModifierCheck method visitNode.
@Override
public void visitNode(Tree tree) {
ClassTree classTree = (ClassTree) tree;
for (Tree member : classTree.members()) {
if (member.is(Tree.Kind.METHOD)) {
MethodTree methodTree = (MethodTree) member;
ModifiersTree modifiers = methodTree.modifiers();
if (isInterfaceOrAnnotation(tree)) {
checkRedundantModifier(modifiers, Modifier.ABSTRACT);
checkRedundantModifier(modifiers, Modifier.PUBLIC);
} else if (ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.FINAL)) {
checkRedundantModifier(modifiers, Modifier.FINAL);
}
} else if (member.is(Tree.Kind.VARIABLE) && isInterfaceOrAnnotation(tree)) {
VariableTree variableTree = (VariableTree) member;
ModifiersTree modifiers = variableTree.modifiers();
checkRedundantModifier(modifiers, Modifier.PUBLIC);
checkRedundantModifier(modifiers, Modifier.STATIC);
checkRedundantModifier(modifiers, Modifier.FINAL);
} else if (member.is(Kind.CONSTRUCTOR) && tree.is(Kind.ENUM)) {
checkRedundantModifier(((MethodTree) member).modifiers(), Modifier.PRIVATE);
}
}
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class StaticMultithreadedUnsafeFieldsCheck method visitNode.
@Override
public void visitNode(Tree tree) {
VariableTree variableTree = (VariableTree) tree;
Type type = variableTree.type().symbolType();
if (ModifiersUtils.hasModifier(variableTree.modifiers(), Modifier.STATIC) && isForbiddenType(variableTree)) {
if (type.isSubtypeOf(JAVA_TEXT_SIMPLE_DATE_FORMAT) && onlySynchronizedUsages((Symbol.VariableSymbol) variableTree.symbol())) {
return;
}
IdentifierTree identifierTree = variableTree.simpleName();
reportIssue(identifierTree, String.format("Make \"%s\" an instance variable.", identifierTree.name()));
}
}
Aggregations