use of org.sonar.plugins.java.api.semantic.Symbol 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.semantic.Symbol in project sonar-java by SonarSource.
the class SimpleClassNameCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
CompilationUnitTree cut = (CompilationUnitTree) tree;
cut.types().stream().filter(NOT_EMPTY_STATEMENT).map(t -> ((ClassTree) t).symbol()).forEach(this::checkSymbol);
List<ImportTree> imports = cut.imports().stream().filter(NOT_EMPTY_STATEMENT).map(t -> (ImportTree) t).collect(Collectors.toList());
boolean fileContainsStarImport = imports.stream().filter(it -> it.qualifiedIdentifier().is(Kind.MEMBER_SELECT)).map(it -> ((MemberSelectExpressionTree) it.qualifiedIdentifier()).identifier()).anyMatch(i -> "*".equals(i.name()));
if (!fileContainsStarImport) {
checkImports(imports);
}
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class SecureCookieCheck method isSetSecureCall.
private static boolean isSetSecureCall(MethodInvocationTree mit) {
Symbol methodSymbol = mit.symbol();
boolean hasArityOne = mit.arguments().size() == 1;
if (hasArityOne && isCallSiteCookie(methodSymbol)) {
ExpressionTree expressionTree = mit.arguments().get(0);
if (expressionTree.is(Tree.Kind.BOOLEAN_LITERAL) && "false".equals(((LiteralTree) expressionTree).value())) {
return false;
}
return "setSecure".equals(getIdentifier(mit).name());
}
return false;
}
use of org.sonar.plugins.java.api.semantic.Symbol 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.semantic.Symbol in project sonar-java by SonarSource.
the class ReplaceLambdaByMethodRefCheck method hasNonFinalFieldInMethodSelect.
private static boolean hasNonFinalFieldInMethodSelect(MethodInvocationTree mit) {
MemberSelectExpressionTree mse = getMemberSelect(mit);
if (mse == null) {
return false;
}
ExpressionTree expression = ExpressionUtils.skipParentheses(mse.expression());
Symbol symbol = null;
if (expression.is(Tree.Kind.IDENTIFIER)) {
symbol = ((IdentifierTree) expression).symbol();
} else if (expression.is(Tree.Kind.MEMBER_SELECT)) {
symbol = ((MemberSelectExpressionTree) expression).identifier().symbol();
}
return symbol != null && symbol.owner().isTypeSymbol() && !isThisOrSuper(symbol.name()) && !symbol.isFinal();
}
Aggregations