use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class RawExceptionCheck method visitThrowStatement.
@Override
public void visitThrowStatement(ThrowStatementTree tree) {
if (tree.expression().is(Tree.Kind.NEW_CLASS)) {
TypeTree exception = ((NewClassTree) tree.expression()).identifier();
Type symbolType = exception.symbolType();
if (symbolType instanceof MethodJavaType) {
symbolType = ((MethodJavaType) exception.symbolType()).resultType();
}
if (isRawException(symbolType)) {
reportIssue(exception);
}
}
super.visitThrowStatement(tree);
}
use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class OutputStreamOverrideWriteCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
ClassTree classTree = (ClassTree) tree;
Type superType = classTree.symbol().superClass();
IdentifierTree className = classTree.simpleName();
if (className == null || classTree.symbol().isAbstract() || superType == null || !(superType.is("java.io.OutputStream") || superType.is("java.io.FilterOutputStream"))) {
return;
}
Optional<MethodTree> writeByteIntInt = findMethod(classTree, WRITE_BYTES_INT_INT);
Optional<MethodTree> writeInt = findMethod(classTree, WRITE_INT);
if (!writeByteIntInt.isPresent()) {
String message = "Provide an override of \"write(byte[],int,int)\" for this class.";
if (writeInt.isPresent()) {
MethodTree writeIntTree = writeInt.get();
if (writeIntTree.block().body().isEmpty()) {
message = "Provide an empty override of \"write(byte[],int,int)\" for this class as well.";
}
}
reportIssue(className, message);
}
}
use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class ObjectCreatedOnlyToCallGetClassCheck method getTypeName.
private static String getTypeName(ExpressionTree tree) {
Type type = tree.symbolType();
String name = getTypeName(type);
if (name.isEmpty()) {
name = getAnonymousClassTypeName(type.symbol());
}
return name;
}
use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class CompareObjectWithEqualsCheck method parentClassImplementsEquals.
private static boolean parentClassImplementsEquals(Symbol.TypeSymbol symbol) {
Type superClass = symbol.superClass();
while (superClass != null && superClass.symbol().isTypeSymbol()) {
Symbol.TypeSymbol superClassSymbol = superClass.symbol();
if (!superClass.is(JAVA_LANG_OBJECT) && hasEqualsMethod(superClassSymbol)) {
return true;
}
superClass = superClassSymbol.superClass();
}
return false;
}
use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.
the class ConfusingOverloadCheck method confusingOverload.
private static boolean confusingOverload(Symbol.MethodSymbol methodSymbol, Symbol.MethodSymbol methodWithSameName) {
if (methodSymbol.isStatic()) {
return false;
}
List<Type> argTypes = methodSymbol.parameterTypes();
List<Type> parameterTypes = methodWithSameName.parameterTypes();
if (argTypes.size() != parameterTypes.size()) {
return false;
}
for (int i = 0; i < argTypes.size(); i++) {
Type argType = argTypes.get(i);
if (argType.isUnknown() || !argType.name().equals(parameterTypes.get(i).name())) {
return false;
}
}
return true;
}
Aggregations