use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class CallSuperInTestCaseCheck method requiresSuperCall.
private static boolean requiresSuperCall(Symbol.MethodSymbol methodSymbol) {
Type superType = methodSymbol.owner().type().symbol().superClass();
Collection<Symbol> symbols = Lists.newArrayList();
while (superType != null && !superType.is(JUNIT_FRAMEWORK_TEST_CASE) && symbols.isEmpty()) {
symbols = superType.symbol().lookupSymbols(methodSymbol.name());
superType = superType.symbol().superClass();
}
return !symbols.isEmpty() && !symbols.iterator().next().owner().type().is(JUNIT_FRAMEWORK_TEST_CASE);
}
use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class StringToPrimitiveConversionCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (hasSemantic()) {
if (tree.is(Tree.Kind.VARIABLE)) {
VariableTreeImpl variableTree = (VariableTreeImpl) tree;
Type variableType = variableTree.type().symbolType();
PrimitiveCheck primitiveCheck = getPrimitiveCheck(variableType);
ExpressionTree initializer = variableTree.initializer();
if (primitiveCheck != null && initializer != null) {
primitiveCheck.checkInstantiation(initializer);
}
} else {
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) tree;
for (PrimitiveCheck primitiveCheck : primitiveChecks) {
primitiveCheck.checkMethodInvocation(methodInvocationTree);
}
}
}
}
use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class SubClassStaticReferenceCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
ClassTree classTree = (ClassTree) tree;
Type classType = classTree.symbol().type();
List<Tree> members = classTree.members();
// JLS 12.4. Initialization of Classes and Interfaces:
// Initialization of a class consists of executing its static initializers and the initializers for static fields (class variables)
// declared in the class.
checkStaticVariables(members, classType);
checkStaticInitializers(members, classType);
}
use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class ThreadAsRunnableArgumentCheck method checkArgumentsTypes.
private void checkArgumentsTypes(List<ExpressionTree> arguments, MethodJavaSymbol methodSymbol) {
List<Type> parametersTypes = methodSymbol.parameterTypes();
// FIXME As arguments are not handled for method resolution using static imports, the provided methodSymbol may not match.
if (!parametersTypes.isEmpty()) {
for (int index = 0; index < arguments.size(); index++) {
ExpressionTree argument = arguments.get(index);
Type providedType = argument.symbolType();
if (!argument.is(Kind.NULL_LITERAL) && isThreadAsRunnable(providedType, parametersTypes, index, methodSymbol.isVarArgs())) {
reportIssue(argument, getMessage(argument, providedType, index));
}
}
}
}
use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class ThrowCheckedExceptionCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (tree.is(Tree.Kind.METHOD)) {
methods.push((MethodTree) tree);
} else {
ThrowStatementTree throwStatementTree = (ThrowStatementTree) tree;
Type symbolType = throwStatementTree.expression().symbolType();
if (symbolType.isSubtypeOf("java.lang.Exception") && !symbolType.isSubtypeOf("java.lang.RuntimeException") && !isFromMethodOverride(symbolType)) {
reportIssue(throwStatementTree.expression(), "Remove the usage of the checked exception '" + symbolType.name() + "'.");
}
}
}
Aggregations