String className = tree.simpleName().name(); LOGGER.info(className + "<<>>" + tree.symbol().isAbstract()); if(tree.symbol().isAbstract()){
@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.InputStream") || superType.is("java.io.FilterInputStream"))) { return; } Optional<MethodTree> readByteIntInt = findMethod(classTree, READ_BYTES_INT_INT); if (!readByteIntInt.isPresent()) { String message = findMethod(classTree, READ_INT) .filter(readIntTree -> readIntTree.block().body().isEmpty()) .map(readIntTree -> "Provide an empty override of \"read(byte[],int,int)\" for this class as well.") .orElse("Provide an override of \"read(byte[],int,int)\" for this class."); reportIssue(className, message); } }
@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.InputStream") || superType.is("java.io.FilterInputStream"))) { return; } Optional<MethodTree> readByteIntInt = findMethod(classTree, READ_BYTES_INT_INT); if (!readByteIntInt.isPresent()) { String message = findMethod(classTree, READ_INT) .filter(readIntTree -> readIntTree.block().body().isEmpty()) .map(readIntTree -> "Provide an empty override of \"read(byte[],int,int)\" for this class as well.") .orElse("Provide an override of \"read(byte[],int,int)\" for this class."); reportIssue(className, message); } }
@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); } }
@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); } }
@Override public void visitNode(Tree tree) { ClassTree classTree = (ClassTree) tree; Symbol.TypeSymbol typeSymbol = classTree.symbol(); if (typeSymbol.isAbstract()) { Collection<Symbol> members = typeSymbol.memberSymbols(); int nbAbstractMethod = countAbstractMethods(members); // don't count this and super as members int nbOfMembers = members.size() - 2; if (hasDefaultConstructor(members)) { //remove default constructor from members nbOfMembers -=1; } if (isExtendingObject(classTree) && nbAbstractMethod == nbOfMembers) { // emtpy abstract class or only abstract method context.reportIssue(this, classTree.simpleName(), "Convert this \"" + typeSymbol + "\" class to an interface"); } if (nbOfMembers > 0 && nbAbstractMethod == 0 && !isPartialImplementation(classTree)) { // Not empty abstract class with no abstract method context.reportIssue(this, classTree.simpleName(), "Convert this \"" + typeSymbol + "\" class to a concrete class with a private constructor"); } } }
@Override public void visitNode(Tree tree) { ClassTree classTree = (ClassTree) tree; Symbol.TypeSymbol typeSymbol = classTree.symbol(); if (typeSymbol.isAbstract()) { Collection<Symbol> members = typeSymbol.memberSymbols(); int nbAbstractMethod = countAbstractMethods(members); // don't count this and super as members int nbOfMembers = members.size() - 2; if (hasDefaultConstructor(members)) { //remove default constructor from members nbOfMembers -=1; } if (isExtendingObject(classTree) && nbAbstractMethod == nbOfMembers) { // emtpy abstract class or only abstract method context.reportIssue(this, classTree.simpleName(), "Convert this \"" + typeSymbol + "\" class to an interface"); } if (nbOfMembers > 0 && nbAbstractMethod == 0 && !isPartialImplementation(classTree)) { // Not empty abstract class with no abstract method context.reportIssue(this, classTree.simpleName(), "Convert this \"" + typeSymbol + "\" class to a concrete class with a private constructor"); } } }
@Override public void visitClass(ClassTree tree) { if (tree.is(Tree.Kind.CLASS)) { Symbol.TypeSymbol typeSymbol = tree.symbol(); if (typeSymbol != null && typeSymbol.isAbstract()) { Collection<Symbol> symbols = typeSymbol.memberSymbols(); int abstractMethod = countAbstractMethods(symbols); if (isExtendingObject(tree) && abstractMethod == symbols.size() - 2) { //emtpy abstract class or only abstract method context.addIssue(tree, this, "Convert this \"" + typeSymbol + "\" class to an interface"); } if (symbols.size() > 2 && abstractMethod == 0 && !isPartialImplementation(tree)) { //Not empty abstract class with no abstract method context.addIssue(tree, this, "Convert this \"" + typeSymbol + "\" class to a concrete class with a private constructor"); } } } super.visitClass(tree); }
private static boolean isExclusion(Symbol.TypeSymbol symbol) { return symbol.isAbstract() || symbol.type().isSubtypeOf("java.lang.Throwable") || isGuiClass((TypeJavaSymbol) symbol) || hasSuppressWarningAnnotation((TypeJavaSymbol) symbol); }
private boolean isExclusion(Symbol.TypeSymbol symbol) { return symbol.isAbstract() || symbol.type().isSubtypeOf("java.lang.Throwable") || isGuiClass((TypeJavaSymbol) symbol) || hasSuppressWarningAnnotation((TypeJavaSymbol) symbol); }
@Override public void visitNode(Tree tree) { if (hasSemantic()) { ClassTree classTree = (ClassTree) tree; Symbol.TypeSymbol symbol = classTree.symbol(); Type type = symbol.type(); if (classTree.simpleName() != null && type.isSubtypeOf("java.util.Comparator") && !type.isSubtypeOf("java.io.Serializable") && !symbol.isAbstract()) { addIssue(classTree, "Make this class \"Serializable\"."); } } }
@Override public void visitNode(Tree tree) { if (hasSemantic()) { ClassTree classTree = (ClassTree) tree; Symbol.TypeSymbol symbol = classTree.symbol(); Type type = symbol.type(); IdentifierTree simpleName = classTree.simpleName(); if (simpleName != null && type.isSubtypeOf("java.util.Comparator") && !type.isSubtypeOf("java.io.Serializable") && !symbol.isAbstract()) { reportIssue(simpleName, "Make this class \"Serializable\"."); } } }
@Override public void visitNode(Tree tree) { ClassTree classTree = (ClassTree) tree; Symbol.TypeSymbol classSymbol = classTree.symbol(); if (isCloneable(classTree) && !classSymbol.isAbstract() && !declaresCloneMethod(classSymbol)) { reportIssue(classTree.simpleName(), "Add a \"clone()\" method to this class."); } }
@Override public void visitNode(Tree tree) { ClassTree classTree = (ClassTree) tree; Symbol.TypeSymbol classSymbol = classTree.symbol(); if (isCloneable(classTree) && !classSymbol.isAbstract() && !declaresCloneMethod(classSymbol)) { addIssue(tree, "Add a \"clone()\" method to this class."); } }
private static boolean isExclusion(Symbol.TypeSymbol symbol) { return symbol.isAbstract() || symbol.type().isSubtypeOf("java.lang.Throwable") || isGuiClass((TypeJavaSymbol) symbol) || hasSuppressWarningAnnotation((TypeJavaSymbol) symbol); }
@Override public void visitNode(Tree tree) { if (hasSemantic()) { ClassTree classTree = (ClassTree) tree; Symbol.TypeSymbol symbol = classTree.symbol(); Type type = symbol.type(); IdentifierTree simpleName = classTree.simpleName(); if (simpleName != null && type.isSubtypeOf("java.util.Comparator") && !type.isSubtypeOf("java.io.Serializable") && !symbol.isAbstract()) { reportIssue(simpleName, "Make this class \"Serializable\"."); } } }
@Override public void visitNode(Tree tree) { ClassTree classTree = (ClassTree) tree; Symbol.TypeSymbol classSymbol = classTree.symbol(); if (isCloneable(classTree) && !classSymbol.isAbstract() && !declaresCloneMethod(classSymbol)) { reportIssue(classTree.simpleName(), "Add a \"clone()\" method to this class."); } }