use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class SelectorMethodArgumentCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
MethodTree methodTree = (MethodTree) tree;
if (Boolean.TRUE.equals(methodTree.isOverriding())) {
return;
}
List<Symbol> booleanParameterSymbols = getBooleanParametersAsSymbol(methodTree.parameters());
BlockTree blockTree = methodTree.block();
if (isPublic(methodTree) && blockTree != null && !booleanParameterSymbols.isEmpty()) {
for (Symbol variable : booleanParameterSymbols) {
Collection<IdentifierTree> usages = variable.usages();
if (usages.size() == 1) {
blockTree.accept(new ConditionalStatementVisitor(variable.name(), Iterables.get(usages, 0), methodTree));
}
}
}
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class StandardFunctionalInterfaceCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
ClassTree classTree = (ClassTree) tree;
// classTree.simpleName() never null for Tree.Kind.INTERFACE
IdentifierTree issueLocation = classTree.simpleName();
// The question "Why we raise issue only for interface annotated with @FunctionalInterface?"
// is discussed in comments of https://jira.sonarsource.com/browse/SONARJAVA-504
Optional.of(classTree).filter(StandardFunctionalInterfaceCheck::isFunctionalInterface).filter(StandardFunctionalInterfaceCheck::isNonStandardFunctionalInterface).filter(StandardFunctionalInterfaceCheck::hasNoExtension).flatMap(StandardFunctionalInterfaceCheck::lookupFunctionalMethod).flatMap(StandardFunctionalInterfaceCheck::lookupMatchingStandardInterface).ifPresent(standardInterface -> reportIssue(issueLocation, buildIssueMessage(classTree, standardInterface)));
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class SAMAnnotatedCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
ClassTree classTree = (ClassTree) tree;
if (hasOneAbstractMethod(classTree.symbol()) && !isAnnotated(classTree)) {
IdentifierTree simpleName = classTree.simpleName();
reportIssue(simpleName, "Annotate the \"" + simpleName.name() + "\" interface with the @FunctionalInterface annotation" + context.getJavaVersion().java8CompatibilityMessage());
}
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class SecureCookieCheck method checkSecureCall.
private void checkSecureCall(MethodInvocationTree mit) {
if (isSetSecureCall(mit) && mit.methodSelect().is(Tree.Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree mse = (MemberSelectExpressionTree) mit.methodSelect();
if (mse.expression().is(Tree.Kind.IDENTIFIER)) {
Symbol reference = ((IdentifierTree) mse.expression()).symbol();
unsecuredCookies.remove(reference);
}
}
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class SillyEqualsCheck method onMethodInvocationFound.
@Override
protected void onMethodInvocationFound(MethodInvocationTree tree) {
ExpressionTree firstArgument = Iterables.getOnlyElement(tree.arguments());
Type argumentType = firstArgument.symbolType().erasure();
if (argumentType.isPrimitive()) {
argumentType = ((JavaType) argumentType).primitiveWrapperType();
}
Type ownerType = getMethodOwnerType(tree).erasure();
IdentifierTree methodInvocationName = ExpressionUtils.methodName(tree);
if (isLiteralNull(firstArgument)) {
reportIssue(methodInvocationName, "Remove this call to \"equals\"; comparisons against null always return false; consider using '== null' to check for nullity.");
} else if (ownerType.isArray()) {
checkWhenOwnerIsArray(methodInvocationName, (Type.ArrayType) ownerType, argumentType);
} else {
checkWhenOwnerIsNotArray(methodInvocationName, ownerType, argumentType);
}
}
Aggregations