use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class IgnoredReturnValueCheck method visitNode.
@Override
public void visitNode(Tree tree) {
ExpressionTree expr = ((ExpressionStatementTree) tree).expression();
if (expr.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) expr;
if (isExcluded(mit)) {
return;
}
Symbol methodSymbol = mit.symbol();
if (!isVoidOrUnknown(mit.symbolType()) && isCheckedType(methodSymbol.owner().type()) && methodSymbol.isPublic() && !isConstructor(methodSymbol)) {
IdentifierTree methodName = ExpressionUtils.methodName(mit);
reportIssue(methodName, "The return value of \"" + methodName.name() + "\" must be used.");
}
}
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class HiddenFieldCheck method isInStaticInnerClass.
private static boolean isInStaticInnerClass(VariableTree hiddenVariable, VariableTree variableTree) {
Symbol hiddenVariableOwner = hiddenVariable.symbol().owner();
Symbol owner = variableTree.symbol().owner();
while (!owner.equals(hiddenVariableOwner)) {
if (owner.isTypeSymbol() && owner.isStatic()) {
return true;
}
owner = owner.owner();
}
return false;
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class EqualsArgumentTypeCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
MethodTree methodTree = (MethodTree) tree;
if (methodTree.block() != null && "equals".equals(methodTree.symbol().name()) && methodTree.parameters().size() == 1) {
Symbol parameterSymbol = methodTree.parameters().get(0).symbol();
if (parameterSymbol.type().is("java.lang.Object")) {
CastVisitor castVisitor = new CastVisitor(parameterSymbol);
methodTree.accept(castVisitor);
if (castVisitor.hasUncheckedCast) {
reportIssue(methodTree.simpleName(), "Add a type test to this method.");
}
}
}
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class FileCreateTempFileCheck method checkAndAdvanceState.
@Nullable
private State checkAndAdvanceState(MethodInvocationTree mit, State requiredState, State nextState) {
ExpressionTree methodSelect = mit.methodSelect();
if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
ExpressionTree expressionTree = ((MemberSelectExpressionTree) methodSelect).expression();
if (expressionTree.is(Tree.Kind.IDENTIFIER)) {
Symbol symbol = ((IdentifierTree) expressionTree).symbol();
Map<Symbol, State> symbolStateMap = symbolStack.peek();
if (symbolStateMap != null && symbolStateMap.containsKey(symbol) && requiredState.equals(symbolStateMap.get(symbol))) {
symbolStateMap.put(symbol, nextState);
return nextState;
}
}
}
return null;
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class DefaultEncodingUsageCheck method onConstructorFound.
@Override
protected void onConstructorFound(NewClassTree newClassTree) {
Symbol symbol = newClassTree.constructorSymbol();
if (symbol.isMethodSymbol()) {
Symbol.MethodSymbol constructor = (Symbol.MethodSymbol) symbol;
String signature = constructor.owner().name() + "(" + Joiner.on(',').join(constructor.parameterTypes()) + ")";
reportIssue(newClassTree.identifier(), "Remove this use of constructor \"" + signature + "\"");
}
}
Aggregations