private boolean isPrivateMethodOfOuterClass(Symbol symbol) { return symbol.isPrivate() && symbol.owner().equals(classSymbol.owner()) && !"<init>".equals(symbol.name()); }
private boolean isPrivateMethodOfOuterClass(Symbol symbol) { return symbol.isPrivate() && symbol.owner().equals(classSymbol.owner()) && !"<init>".equals(symbol.name()); }
private boolean outerClassHasMethodWithSameName(Symbol symbol) { return !((Symbol.TypeSymbol)classSymbol.owner()).lookupSymbols(symbol.name()).isEmpty(); }
@Override public void visitClass(ClassTree tree) { Symbol.TypeSymbol symbol = tree.symbol(); if (!tree.is(Tree.Kind.CLASS)) { return; } outerClasses.push(symbol); atLeastOneReference.push(Boolean.FALSE); scan(tree.members()); Boolean oneReference = atLeastOneReference.pop(); outerClasses.pop(); if (!symbol.isStatic() && !oneReference && couldBeDeclaredStatic(symbol)) { Tree reportTree = tree.simpleName(); if(reportTree == null) { // Ignore issues on anonymous classes return; } String message = "Make this a \"static\" inner class."; if(symbol.owner().isMethodSymbol()) { message = "Make this local class a \"static\" inner class."; } context.reportIssue(this, reportTree, message); } }
private boolean isValidSubstitution(TypeSubstitution candidate, TypeVariableJavaType typeVar, JavaType typeParam, JavaType site) { for (JavaType bound : typeVar.bounds) { JavaType currentBound = applySubstitution(bound, candidate); while (currentBound.isTagged(JavaType.TYPEVAR) && !currentBound.symbol().owner().isMethodSymbol()) { JavaType newBound = candidate.substitutedType(currentBound); if (newBound == null && site.isParameterized()) { newBound = ((ParametrizedTypeJavaType) site).typeSubstitution.substitutedType(currentBound); } if (newBound == null) { return ((JavaSymbol.TypeJavaSymbol) site.symbol()).typeVariableTypes.contains(currentBound); } if (currentBound.equals(newBound)) { // exploring the same substitution, we cannot deduce anything break; } currentBound = newBound; } if (!isUnboundedWildcard(typeParam) && !typeParam.isSubtypeOf(currentBound)) { return false; } } return true; }
private void visitClassTree(ClassTree classTree) { Symbol.TypeSymbol symbol = classTree.symbol(); if (isInnerClass(symbol) && directlyImplementsSerializable(symbol)) { Tree reportTree = ExpressionsHelper.reportOnClassTree(classTree); Symbol owner = symbol.owner(); if (owner.isTypeSymbol()) { Symbol.TypeSymbol ownerType = (Symbol.TypeSymbol) owner; if (isMatchingOuterClass(ownerType.type()) && !symbol.isStatic()) { reportIssue(reportTree, "Make this inner class static"); } } else if (owner.isMethodSymbol()) { Symbol.TypeSymbol methodOwner = (Symbol.TypeSymbol) owner.owner(); if (isMatchingOuterClass(methodOwner.type()) && !owner.isStatic()) { String methodName = owner.name(); reportIssue(reportTree, "Make \"" + methodName + "\" static"); } } } }
private void visitClassTree(ClassTree classTree) { Symbol.TypeSymbol symbol = classTree.symbol(); if (isInnerClass(symbol) && directlyImplementsSerializable(symbol)) { Tree reportTree = ExpressionsHelper.reportOnClassTree(classTree); Symbol owner = symbol.owner(); if (owner.isTypeSymbol()) { Symbol.TypeSymbol ownerType = (Symbol.TypeSymbol) owner; if (isMatchingOuterClass(ownerType.type()) && !symbol.isStatic()) { reportIssue(reportTree, "Make this inner class static"); } } else if (owner.isMethodSymbol()) { Symbol.TypeSymbol methodOwner = (Symbol.TypeSymbol) owner.owner(); if (isMatchingOuterClass(methodOwner.type()) && !owner.isStatic()) { String methodName = owner.name(); reportIssue(reportTree, "Make \"" + methodName + "\" static"); } } } }
private void visitClassTree(ClassTree classTree) { Symbol.TypeSymbol symbol = classTree.symbol(); if (isInnerClass(symbol) && directlyImplementsSerializable(symbol)) { Symbol owner = symbol.owner(); if (owner.isTypeSymbol()) { Symbol.TypeSymbol ownerType = (Symbol.TypeSymbol) owner; if (isMatchingOuterClass(ownerType.type()) && !symbol.isStatic()) { addIssue(classTree, "Make this inner class static"); } } else if (owner.isMethodSymbol()) { Symbol.TypeSymbol methodOwner = (Symbol.TypeSymbol) owner.owner(); if (isMatchingOuterClass(methodOwner.type()) && !owner.isStatic()) { String methodName = owner.name(); addIssue(classTree, "Make \"" + methodName + "\" static"); } } } }
@Override public void visitNode(Tree tree) { ClassTree node = (ClassTree) tree; Symbol.TypeSymbol symbol = node.symbol(); Symbol owner = symbol.owner(); Type ownerType = owner.type(); if (ownerType != null && ownerType.isClass() && owner.owner().isPackageSymbol()) { // raise only one issue for the first level of nesting when multiple nesting int lines = new LinesOfCodeVisitor().linesOfCode(node); if (lines > max) { reportIssue(ExpressionsHelper.reportOnClassTree(node), "Reduce this class from " + lines + " to the maximum allowed " + max + " or externalize it in a public class."); } } }
private boolean outerClassHasMethodWithSameName(Symbol symbol) { return !((Symbol.TypeSymbol) classSymbol.owner()).lookupSymbols(symbol.name()).isEmpty(); }
private static boolean isPrivateInnerClass(ClassTree classTree) { return !classTree.symbol().owner().isPackageSymbol() && ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.PRIVATE); }
private boolean extendsOuterClass(Symbol.TypeSymbol classSymbol) { Type superType = classSymbol.superClass(); return superType != null && superType.equals(classSymbol.owner().type()); }
private boolean outerClassHasMethodWithSameName(Symbol symbol) { return !((Symbol.TypeSymbol) classSymbol.owner()).lookupSymbols(symbol.name()).isEmpty(); }
@Override public void visitNode(Tree tree) { ClassTree node = (ClassTree) tree; Symbol.TypeSymbol symbol = node.symbol(); Symbol owner = symbol.owner(); Type ownerType = owner.type(); if (ownerType != null && ownerType.isClass() && owner.owner().isPackageSymbol()) { // raise only one issue for the first level of nesting when multiple nesting int lines = new LinesOfCodeVisitor().linesOfCode(node); if (lines > max) { reportIssue(ExpressionsHelper.reportOnClassTree(node), "Reduce this class from " + lines + " to the maximum allowed " + max + " or externalize it in a public class."); } } }
private static boolean extendsOuterClass(Symbol.TypeSymbol classSymbol) { Type superType = classSymbol.superClass(); return superType != null && superType.erasure().equals(classSymbol.owner().type().erasure()); }
private static boolean extendsOuterClass(Symbol.TypeSymbol classSymbol) { Type superType = classSymbol.superClass(); return superType != null && superType.erasure().equals(classSymbol.owner().type().erasure()); }
private static boolean isPrivateInnerClass(ClassTree classTree) { return !classTree.symbol().owner().isPackageSymbol() && ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.PRIVATE); }
private boolean isInherited(Symbol symbol) { Type methodOwnerType = symbol.owner().type().erasure(); Type innerType = classSymbol.type().erasure(); return !symbol.isStatic() && innerType.isSubtypeOf(methodOwnerType) && !classSymbol.owner().type().equals(methodOwnerType) && !innerType.equals(methodOwnerType); }
private boolean isInherited(Symbol symbol) { Type methodOwnerType = symbol.owner().type(); Type innerType = classSymbol.type(); return !symbol.isStatic() && innerType.isSubtypeOf(methodOwnerType) && !classSymbol.owner().type().equals(methodOwnerType) && !innerType.equals(methodOwnerType); }
private boolean isInherited(Symbol symbol) { Type methodOwnerType = symbol.owner().type().erasure(); Type innerType = classSymbol.type().erasure(); return !symbol.isStatic() && innerType.isSubtypeOf(methodOwnerType) && !classSymbol.owner().type().equals(methodOwnerType) && !innerType.equals(methodOwnerType); }