@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; if (!methodTree.symbol().isPublic()) { return; } methodTree.parameters().stream() .map(VariableTree::symbol) .map(Symbol::usages) .flatMap(List::stream) .forEach(parameter -> checkUsage(parameter, methodTree)); }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; if (!methodTree.symbol().isPublic()) { return; } methodTree.parameters().stream() .map(VariableTree::symbol) .map(Symbol::usages) .flatMap(List::stream) .forEach(parameter -> checkUsage(parameter, methodTree)); }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; Symbol.MethodSymbol methodSymbol = methodTree.symbol(); if (!methodSymbol.isPublic() || !Boolean.FALSE.equals(methodTree.isOverriding()) || isOverloaded(methodSymbol)) { return; } boolean springInjectionAnnotated = isSpringInjectionAnnotated(methodSymbol.metadata()); methodTree.parameters().stream() .map(VariableTree::symbol) .filter(p -> p.type().isClass() && !p.type().symbol().isEnum() && !p.type().is("java.lang.String")) .filter(p -> !(springInjectionAnnotated && p.type().is("java.util.Collection"))) .forEach(p -> handleParameter(p, springInjectionAnnotated)); }
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 boolean isPublic(MethodTree methodTree) { return methodTree.symbol().isPublic(); }
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 bothPublic(Symbol.MethodSymbol method, Symbol parentMethod) { return method.isPublic() && parentMethod.isPublic(); }
private static boolean isPublic(MethodTree methodTree) { return methodTree.symbol().isPublic(); }
private void checkSetupTearDownSignature(MethodTree methodTree) { Symbol.MethodSymbol symbol = methodTree.symbol(); if (!symbol.isPublic() && !symbol.isProtected()) { reportIssue(methodTree, "Make this method \"public\"."); } else if (!methodTree.parameters().isEmpty()) { reportIssue(methodTree, "This method does not accept parameters."); } else { TypeTree returnType = methodTree.returnType(); if (returnType != null && !returnType.symbolType().isVoid()) { reportIssue(methodTree, "Make this method return \"void\"."); } } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; Symbol.MethodSymbol methodSymbol = methodTree.symbol(); if (isClassController(methodSymbol) && isRequestMappingAnnotated(methodSymbol) && !methodSymbol.isPublic()) { reportIssue(methodTree.simpleName(), "Make this method \"public\"."); } }
private static boolean bothPublic(Symbol.MethodSymbol method, Symbol parentMethod) { return method.isPublic() && parentMethod.isPublic(); }
private static Map<Symbol, String> collectMethodsPropagation(ClassTree classTree) { Map<Symbol, String> methodPropagationMap = new HashMap<>(); String classPropagation = getPropagation(classTree.symbol(), null); for (Tree member : classTree.members()) { if (member.is(Tree.Kind.METHOD)) { MethodTree method = (MethodTree) member; if (method.symbol().isPublic()) { methodPropagationMap.put(method.symbol(), getPropagation(method.symbol(), classPropagation)); } } } return methodPropagationMap; }
private static boolean isPublic(MethodTree methodTree) { return methodTree.symbol().isPublic(); }
private static Map<Symbol, String> collectMethodsPropagation(ClassTree classTree) { Map<Symbol, String> methodPropagationMap = new HashMap<>(); String classPropagation = getPropagation(classTree.symbol(), null); for (Tree member : classTree.members()) { if (member.is(Tree.Kind.METHOD)) { MethodTree method = (MethodTree) member; if (method.symbol().isPublic()) { methodPropagationMap.put(method.symbol(), getPropagation(method.symbol(), classPropagation)); } } } return methodPropagationMap; }
private void checkTestNGmembers(IdentifierTree className, Stream<Symbol.MethodSymbol> members) { if (members.noneMatch(member -> member.isPublic() && !member.isStatic() && member.returnType() != null)) { reportClass(className); } }
@Override public void visitNode(Tree tree) { MethodTree method = (MethodTree) tree; boolean isPublic = method.modifiers().contains(Modifier.PUBLIC); if (hasSemantic()) { isPublic = method.symbol().isPublic(); } if (!isPublic && hasTransactionalAnnotation(method)) { reportIssue(method.simpleName(), "Make this method \"public\" or remove the \"@Transactional\" annotation"); } }
@Override public void visitNode(Tree tree) { MethodTree method = (MethodTree) tree; boolean isPublic = method.modifiers().contains(Modifier.PUBLIC); if (hasSemantic()) { isPublic = method.symbol().isPublic(); } if (!isPublic && hasTransactionalAnnotation(method)) { reportIssue(method.simpleName(), "Make this method \"public\" or remove the \"@Transactional\" annotation"); } }
private void checkTestNGmembers(IdentifierTree className, Stream<Symbol.MethodSymbol> members) { if (members.noneMatch(member -> member.isPublic() && !member.isStatic() && member.returnType() != null)) { reportClass(className); } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; Symbol.MethodSymbol methodSymbol = methodTree.symbol(); if (isClassController(methodSymbol) && isRequestMappingAnnotated(methodSymbol) && !methodSymbol.isPublic()) { reportIssue(methodTree.simpleName(), "Make this method \"public\"."); } }
private void checkSetupTearDownSignature(MethodTree methodTree) { Symbol.MethodSymbol symbol = methodTree.symbol(); if (!symbol.isPublic() && !symbol.isProtected()) { reportIssue(methodTree, "Make this method \"public\"."); } else if (!methodTree.parameters().isEmpty()) { reportIssue(methodTree, "This method does not accept parameters."); } else { TypeTree returnType = methodTree.returnType(); if (returnType != null && !returnType.symbolType().isVoid()) { reportIssue(methodTree, "Make this method return \"void\"."); } } }