public void compute(ASTMethodDeclaration node) { if (node.jjtGetParent() instanceof ASTClassOrInterfaceBodyDeclaration) { this.computeNow(node); } }
private boolean isJUnit4Method(ASTMethodDeclaration method) { return isJUnit4Class && doesNodeContainJUnitAnnotation(method.jjtGetParent(), JUNIT4_CLASS_NAME); }
private boolean isJUnit5Method(ASTMethodDeclaration method) { return isJUnit5Class && doesNodeContainJUnitAnnotation(method.jjtGetParent(), JUNIT5_CLASS_NAME); }
private boolean isAnnotatedOverride(ASTMethodDeclaration decl) { List<ASTMarkerAnnotation> annotations = decl.jjtGetParent().findDescendantsOfType(ASTMarkerAnnotation.class); for (ASTMarkerAnnotation ann : annotations) { // TODO consider making a method to get the annotations of a method if (ann.getFirstChildOfType(ASTName.class).getImage().equals("Override")) { return true; } } return false; }
private boolean hasOverrideAnnotation(ASTMethodDeclaration node) { int childIndex = node.jjtGetChildIndex(); for (int i = 0; i < childIndex; i++) { Node previousSibling = node.jjtGetParent().jjtGetChild(i); List<ASTMarkerAnnotation> annotations = previousSibling.findDescendantsOfType(ASTMarkerAnnotation.class); for (ASTMarkerAnnotation annotation : annotations) { ASTName name = annotation.getFirstChildOfType(ASTName.class); if (name != null && (name.hasImageEqualTo("Override") || name.hasImageEqualTo("java.lang.Override"))) { return true; } } } return false; } }
@Override public Object visit(ASTMethodDeclaration methodDeclaration, Object o) { if (junitImported && isAllowedMethod(methodDeclaration)) { return super.visit(methodDeclaration, o); } if (methodDeclaration.getMethodName().startsWith("test")) { return super.visit(methodDeclaration, o); } // Ignore overridden methods, the issue should be marked on the method definition final List<ASTAnnotation> methodAnnotations = methodDeclaration.jjtGetParent().findChildrenOfType(ASTAnnotation.class); for (final ASTAnnotation annotation : methodAnnotations) { final ASTName annotationName = annotation.getFirstDescendantOfType(ASTName.class); if (annotationName.hasImageEqualTo("Override") || annotationName.hasImageEqualTo("java.lang.Override")) { return super.visit(methodDeclaration, o); } } checkExceptions(methodDeclaration, o); return super.visit(methodDeclaration, o); }
@Override public Object visit(ASTMethodDeclaration method, Object data) { if (isJUnitMethod(method, data)) { if (!isExpectAnnotated(method.jjtGetParent())) { Map<String, VariableNameDeclaration> variables = getVariables(method); Scope classScope = method.getScope().getParent(); Map<String, List<NameOccurrence>> expectables = getRuleAnnotatedExpectedExceptions(classScope); if (!containsExpectOrAssert(method.getBlock(), expectables, variables)) { addViolation(data, method); } } } return data; }
ASTClassOrInterfaceBodyDeclaration parent = (ASTClassOrInterfaceBodyDeclaration) node.jjtGetParent(); for (int i = 0; i < parent.jjtGetNumChildren(); i++) { Node n = parent.jjtGetChild(i);
public void compute(ASTMethodDeclaration node) { if (node.jjtGetParent() instanceof ASTClassOrInterfaceBodyDeclaration) { this.computeNow(node); } }
private boolean isJUnit4Method(ASTMethodDeclaration method) { return isJUnit4Class && doesNodeContainJUnitAnnotation(method.jjtGetParent(), JUNIT4_CLASS_NAME); }
private boolean isJUnit5Method(ASTMethodDeclaration method) { return isJUnit5Class && doesNodeContainJUnitAnnotation(method.jjtGetParent(), JUNIT5_CLASS_NAME); }
private boolean isAnnotatedOverride(ASTMethodDeclaration decl) { List<ASTMarkerAnnotation> annotations = decl.jjtGetParent().findDescendantsOfType(ASTMarkerAnnotation.class); for (ASTMarkerAnnotation ann : annotations) { // TODO consider making a method to get the annotations of a method if (ann.getFirstChildOfType(ASTName.class).getImage().equals("Override")) { return true; } } return false; }
private boolean hasOverrideAnnotation(ASTMethodDeclaration node) { int childIndex = node.jjtGetChildIndex(); for (int i = 0; i < childIndex; i++) { Node previousSibling = node.jjtGetParent().jjtGetChild(i); List<ASTMarkerAnnotation> annotations = previousSibling.findDescendantsOfType(ASTMarkerAnnotation.class); for (ASTMarkerAnnotation annotation : annotations) { ASTName name = annotation.getFirstChildOfType(ASTName.class); if (name != null && (name.hasImageEqualTo("Override") || name.hasImageEqualTo("java.lang.Override"))) { return true; } } } return false; } }
(ASTClassOrInterfaceBodyDeclaration)node.jjtGetParent();
@Override public Object visit(ASTMethodDeclaration methodDeclaration, Object o) { if (junitImported && isAllowedMethod(methodDeclaration)) { return super.visit(methodDeclaration, o); } if (methodDeclaration.getMethodName().startsWith("test")) { return super.visit(methodDeclaration, o); } // Ignore overridden methods, the issue should be marked on the method definition final List<ASTAnnotation> methodAnnotations = methodDeclaration.jjtGetParent().findChildrenOfType(ASTAnnotation.class); for (final ASTAnnotation annotation : methodAnnotations) { final ASTName annotationName = annotation.getFirstDescendantOfType(ASTName.class); if (annotationName.hasImageEqualTo("Override") || annotationName.hasImageEqualTo("java.lang.Override")) { return super.visit(methodDeclaration, o); } } checkExceptions(methodDeclaration, o); return super.visit(methodDeclaration, o); }
@Override public Object visit(ASTMethodDeclaration method, Object data) { if (isJUnitMethod(method, data)) { if (!isExpectAnnotated(method.jjtGetParent())) { Map<String, VariableNameDeclaration> variables = getVariables(method); Scope classScope = method.getScope().getParent(); Map<String, List<NameOccurrence>> expectables = getRuleAnnotatedExpectedExceptions(classScope); if (!containsExpectOrAssert(method.getBlock(), expectables, variables)) { addViolation(data, method); } } } return data; }
ASTClassOrInterfaceBodyDeclaration parent = (ASTClassOrInterfaceBodyDeclaration) node.jjtGetParent(); for (int i = 0; i < parent.jjtGetNumChildren(); i++) { Node n = parent.jjtGetChild(i);