use of org.sonar.plugins.java.api.semantic.Type in project JavaForFun by gumartinm.
the class ParameterCheck method visitNode.
@Override
public void visitNode(Tree tree) {
MethodTree method = (MethodTree) tree;
if (method.parameters().size() == 1) {
MethodSymbol symbol = method.symbol();
Type firstParameterType = symbol.parameterTypes().get(0);
Type returnType = symbol.returnType().type();
if (returnType.is(firstParameterType.fullyQualifiedName())) {
reportIssue(method.simpleName(), "Remove this method");
}
}
}
use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class InstanceOfAlwaysTrueCheck method visitNode.
@Override
public void visitNode(Tree tree) {
InstanceOfTree instanceOfTree = (InstanceOfTree) tree;
Type expressionType = instanceOfTree.expression().symbolType();
Type instanceOf = instanceOfTree.type().symbolType();
if (expressionType.isSubtypeOf(instanceOf) && !instanceOfTree.expression().is(Tree.Kind.NULL_LITERAL)) {
reportIssue(instanceOfTree.instanceofKeyword(), "Remove this useless \"instanceof\" operator; it will always return \"true\". ");
}
}
use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class InterruptedExceptionCheck method visitNode.
@Override
public void visitNode(Tree tree) {
TryStatementTree tryStatementTree = (TryStatementTree) tree;
withinInterruptingFinally.addFirst(isFinallyInterrupting(tryStatementTree.finallyBlock()));
for (CatchTree catchTree : tryStatementTree.catches()) {
Type catchType = catchTree.parameter().symbol().type();
if (catchType.is("java.lang.InterruptedException") || catchType.is("java.lang.ThreadDeath")) {
BlockVisitor blockVisitor = new BlockVisitor(catchTree.parameter().symbol());
catchTree.block().accept(blockVisitor);
if (!blockVisitor.threadInterrupted && !isWithinInterruptingFinally()) {
reportIssue(catchTree.parameter(), "Either re-interrupt this method or rethrow the \"" + catchType.name() + "\".");
}
}
}
}
use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class InterfaceOrSuperclassShadowingCheck method visitNode.
@Override
public void visitNode(Tree tree) {
ClassTree classTree = (ClassTree) tree;
if (hasSemantic()) {
Symbol.TypeSymbol classSymbol = classTree.symbol();
checkSuperType(classTree, classSymbol.superClass());
for (Type interfaceType : classSymbol.interfaces()) {
checkSuperType(classTree, interfaceType);
}
}
}
use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class EnumMapCheck method hasEnumKey.
private static boolean hasEnumKey(Type symbolType) {
Type type = symbolType;
if (type instanceof MethodJavaType) {
type = ((MethodJavaType) type).resultType();
}
if (type instanceof ParametrizedTypeJavaType) {
ParametrizedTypeJavaType parametrizedTypeJavaType = (ParametrizedTypeJavaType) type;
List<TypeVariableJavaType> typeParameters = parametrizedTypeJavaType.typeParameters();
if (!typeParameters.isEmpty()) {
return parametrizedTypeJavaType.substitution(typeParameters.get(0)).symbol().isEnum();
}
}
return false;
}
Aggregations