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; }
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; }
private boolean hasOnlyStaticMethods(Symbol.TypeSymbol newClassTypeSymbol) { Collection<MethodSymbol> methods = filterMethods(newClassTypeSymbol.memberSymbols()); if (methods.isEmpty()) { return false; } for (MethodSymbol method : methods) { if (!method.isStatic()) { return false; } } return superClassHasOnlyStaticMethods(newClassTypeSymbol); }
@Override public void visitMethod(MethodTree tree) { if (isExcluded(tree)) { return; } Symbol.MethodSymbol symbol = tree.symbol(); methodReferences.push(new MethodReference(symbol)); scan(tree.parameters()); scan(tree.block()); MethodReference reference = methodReferences.pop(); if (symbol.isPrivate() && !symbol.isStatic() && !reference.hasNonStaticReference()) { context.reportIssue(this, tree.simpleName(), "Make \"" + symbol.name() + "\" a \"static\" method."); } }
private void checkSuiteSignature(MethodTree methodTree) { Symbol.MethodSymbol symbol = methodTree.symbol(); if (!symbol.isPublic()) { reportIssue(methodTree, "Make this method \"public\"."); } else if (!symbol.isStatic()) { reportIssue(methodTree, "Make this method \"static\"."); } else if (!methodTree.parameters().isEmpty()) { reportIssue(methodTree, "This method does not accept parameters."); } else { TypeTree returnType = methodTree.returnType(); if (returnType != null && !returnType.symbolType().isSubtypeOf("junit.framework.Test")) { reportIssue(methodTree, "This method should return either a \"junit.framework.Test\" or a \"junit.framework.TestSuite\"."); } } }
@Override public void visitMethod(MethodTree tree) { if (isExcluded(tree)) { return; } Symbol.MethodSymbol symbol = tree.symbol(); methodReferences.push(new MethodReference(symbol)); scan(tree.parameters()); scan(tree.block()); MethodReference reference = methodReferences.pop(); if (symbol.isPrivate() && !symbol.isStatic() && !reference.hasNonStaticReference()) { context.reportIssue(this, tree.simpleName(), "Make \"" + symbol.name() + "\" a \"static\" method."); } }
private static boolean isPrivateStaticOrAbstract(Symbol.MethodSymbol methodSymbol) { return methodSymbol.isPrivate() || methodSymbol.isStatic() || methodSymbol.isAbstract(); }
private void checkSuiteSignature(MethodTree methodTree) { Symbol.MethodSymbol symbol = methodTree.symbol(); if (!symbol.isPublic()) { reportIssue(methodTree, "Make this method \"public\"."); } else if (!symbol.isStatic()) { reportIssue(methodTree, "Make this method \"static\"."); } else if (!methodTree.parameters().isEmpty()) { reportIssue(methodTree, "This method does not accept parameters."); } else { TypeTree returnType = methodTree.returnType(); if (returnType != null && !returnType.symbolType().isSubtypeOf("junit.framework.Test")) { reportIssue(methodTree, "This method should return either a \"junit.framework.Test\" or a \"junit.framework.TestSuite\"."); } } }
private static boolean isPrivateStaticOrAbstract(Symbol.MethodSymbol methodSymbol) { return methodSymbol.isPrivate() || methodSymbol.isStatic() || methodSymbol.isAbstract(); }
private void checkNotStatic(MethodTree methodTree) { Symbol.MethodSymbol methodSymbol = methodTree.symbol(); if (methodSymbol.isStatic()) { reportIssue(methodTree.simpleName(), "The \"static\" modifier should not be applied to \"" + methodSymbol.name() + "\"."); } }
private void checkTestNGmembers(IdentifierTree className, Stream<Symbol.MethodSymbol> members) { if (members.noneMatch(member -> member.isPublic() && !member.isStatic() && member.returnType() != null)) { reportClass(className); } }
public static boolean methodCanNotBeOverriden(Symbol.MethodSymbol methodSymbol) { if (Flags.isFlagged(((JavaSymbol.MethodJavaSymbol) methodSymbol).flags(), Flags.NATIVE)) { return false; } return !methodSymbol.isAbstract() && (methodSymbol.isPrivate() || methodSymbol.isFinal() || methodSymbol.isStatic() || methodSymbol.owner().isFinal()); } }
private void checkTestNGmembers(IdentifierTree className, Stream<Symbol.MethodSymbol> members) { if (members.noneMatch(member -> member.isPublic() && !member.isStatic() && member.returnType() != null)) { reportClass(className); } }
private void checkNotStatic(MethodTree methodTree) { Symbol.MethodSymbol methodSymbol = methodTree.symbol(); if (methodSymbol.isStatic()) { reportIssue(methodTree.simpleName(), "The \"static\" modifier should not be applied to \"" + methodSymbol.name() + "\"."); } }
public static boolean methodCanNotBeOverriden(Symbol.MethodSymbol methodSymbol) { if (Flags.isFlagged(((JavaSymbol.MethodJavaSymbol) methodSymbol).flags(), Flags.NATIVE)) { return false; } return !methodSymbol.isAbstract() && (methodSymbol.isPrivate() || methodSymbol.isFinal() || methodSymbol.isStatic() || methodSymbol.owner().isFinal()); } }
private static boolean hideStaticMethod(Symbol.MethodSymbol methodSymbol, Type superClass, Symbol symbolWithSameName) { return symbolWithSameName.isStatic() && !methodSymbol.isStatic() && BooleanUtils.isTrue(((MethodJavaSymbol) methodSymbol).checkOverridingParameters((MethodJavaSymbol) symbolWithSameName, (ClassJavaType) superClass)); }
private static boolean hideStaticMethod(Symbol.MethodSymbol methodSymbol, Type superClass, Symbol symbolWithSameName) { return symbolWithSameName.isStatic() && !methodSymbol.isStatic() && BooleanUtils.isTrue(((MethodJavaSymbol) methodSymbol).checkOverridingParameters((MethodJavaSymbol) symbolWithSameName, (ClassJavaType) superClass)); }
private void checkNotStatic(MethodTree methodTree) { Symbol.MethodSymbol methodSymbol = methodTree.symbol(); if (methodSymbol.isStatic()) { addIssue(methodTree, "The \"static\" modifier should not be applied to \"" + methodSymbol.name() + "\"."); } }