@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); } }
@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 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"); } } } }