@Override public boolean isFindBoundary() { return isAnonymousInnerClass(); }
@Override public boolean hasSuppressWarningsAnnotationFor(Rule rule) { for (int i = 0; i < jjtGetNumChildren(); i++) { if (jjtGetChild(i) instanceof ASTAnnotation) { ASTAnnotation a = (ASTAnnotation) jjtGetChild(i); if (a.suppresses(rule)) { return true; } } } return false; }
/** * Tries to resolve a given typeImage as a generic Type. If the Generic Type * is found, any defined ClassOrInterfaceType below this type declaration is * used (this is typically a type bound, e.g. {@code <T extends List>}. * * @param argument * the node, from where to start searching. * @param typeImage * the type as string * @return the resolved class or <code>null</code> if nothing was found. */ private Class<?> resolveGenericType(Node argument, String typeImage) { List<ASTTypeParameter> types = new ArrayList<>(); // first search only within the same method ASTClassOrInterfaceBodyDeclaration firstParentOfType = argument .getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class); if (firstParentOfType != null) { types.addAll(firstParentOfType.findDescendantsOfType(ASTTypeParameter.class)); } // then search class level types, from inner-most to outer-most List<ASTClassOrInterfaceDeclaration> enclosingClasses = argument .getParentsOfType(ASTClassOrInterfaceDeclaration.class); for (ASTClassOrInterfaceDeclaration enclosing : enclosingClasses) { ASTTypeParameters classLevelTypeParameters = enclosing.getFirstChildOfType(ASTTypeParameters.class); if (classLevelTypeParameters != null) { types.addAll(classLevelTypeParameters.findDescendantsOfType(ASTTypeParameter.class)); } } return resolveGenericType(typeImage, types); }
private boolean methodHasOverride(Node node) { ASTClassOrInterfaceBodyDeclaration method = node.getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class); if (method != null && method.jjtGetNumChildren() > 0 && method.jjtGetChild(0) instanceof ASTAnnotation) { ASTMarkerAnnotation marker = method.getFirstDescendantOfType(ASTMarkerAnnotation.class); if (marker != null && marker.getFirstChildOfType(ASTName.class) != null) { ASTName name = marker.getFirstChildOfType(ASTName.class); if (name.getType() == Override.class) { return true; } } } return false; } }
(ASTClassOrInterfaceBodyDeclaration)node.jjtGetParent(); int startLine = classOrInterfaceBodyDecl.getBeginLine(); int endLine = classOrInterfaceBodyDecl.getEndLine(); Node firstChild = classOrInterfaceBodyDecl.jjtGetChild(0); Token firstToken = (Token)classOrInterfaceBodyDecl.jjtGetFirstToken();
final public void ClassOrInterfaceBodyDeclaration() throws ParseException { ASTClassOrInterfaceBodyDeclaration jjtn000 = new ASTClassOrInterfaceBodyDeclaration(this, JJTCLASSORINTERFACEBODYDECLARATION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1));int modifiers; try { if (jj_2_12(2147483647)) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
extras.add(((ASTAssignmentOperator) node).isCompound() ? "compound" : "simple"); } else if (node instanceof ASTClassOrInterfaceBodyDeclaration) { if (((ASTClassOrInterfaceBodyDeclaration) node).isAnonymousInnerClass()) { extras.add("anonymous inner class"); if (((ASTClassOrInterfaceBodyDeclaration) node).isEnumChild()) { extras.add("enum child");
private boolean methodHasOverride(Node node) { ASTClassOrInterfaceBodyDeclaration method = node.getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class); if (method != null && method.jjtGetNumChildren() > 0 && method.jjtGetChild(0) instanceof ASTAnnotation) { ASTMarkerAnnotation marker = method.getFirstDescendantOfType(ASTMarkerAnnotation.class); if (marker != null && marker.getFirstChildOfType(ASTName.class) != null) { ASTName name = marker.getFirstChildOfType(ASTName.class); if (name.getType() == Override.class) { return true; } } } return false; } }
final public void ClassOrInterfaceBodyDeclaration() throws ParseException { ASTClassOrInterfaceBodyDeclaration jjtn000 = new ASTClassOrInterfaceBodyDeclaration(this, JJTCLASSORINTERFACEBODYDECLARATION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1));int modifiers; try { if (jj_2_12(2147483647)) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
extras.add(((ASTAssignmentOperator) node).isCompound() ? "compound" : "simple"); } else if (node instanceof ASTClassOrInterfaceBodyDeclaration) { if (((ASTClassOrInterfaceBodyDeclaration) node).isAnonymousInnerClass()) { extras.add("anonymous inner class"); if (((ASTClassOrInterfaceBodyDeclaration) node).isEnumChild()) { extras.add("enum child");
@Override public Object visit(ASTClassOrInterfaceBodyDeclaration node, Object data) { boolean inAnnotation = false; for (int i = 0; i < node.jjtGetNumChildren(); i++) { Node child = node.jjtGetChild(i); if (child instanceof ASTAnnotation) { ASTName annotationName = child.getFirstDescendantOfType(ASTName.class); if ("Test".equals(annotationName.getImage())) { inAnnotation = true; continue; } } if (child instanceof ASTMethodDeclaration) { boolean isJUnitMethod = isJUnitMethod((ASTMethodDeclaration) child, data); if (inAnnotation || isJUnitMethod) { List<Node> found = new ArrayList<>(); found.addAll((List<Node>) visit((ASTMethodDeclaration) child, data)); for (Node name : found) { addViolation(data, name); } } } inAnnotation = false; } return super.visit(node, data); }
private boolean inAnonymousInnerClass(Node node) { ASTClassOrInterfaceBodyDeclaration parent = node.getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class); return parent != null && parent.isAnonymousInnerClass(); }
/** * Tries to resolve a given typeImage as a generic Type. If the Generic Type * is found, any defined ClassOrInterfaceType below this type declaration is * used (this is typically a type bound, e.g. {@code <T extends List>}. * * @param argument * the node, from where to start searching. * @param typeImage * the type as string * @return the resolved class or <code>null</code> if nothing was found. */ private Class<?> resolveGenericType(Node argument, String typeImage) { List<ASTTypeParameter> types = new ArrayList<>(); // first search only within the same method ASTClassOrInterfaceBodyDeclaration firstParentOfType = argument .getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class); if (firstParentOfType != null) { types.addAll(firstParentOfType.findDescendantsOfType(ASTTypeParameter.class)); } // then search class level types, from inner-most to outer-most List<ASTClassOrInterfaceDeclaration> enclosingClasses = argument .getParentsOfType(ASTClassOrInterfaceDeclaration.class); for (ASTClassOrInterfaceDeclaration enclosing : enclosingClasses) { ASTTypeParameters classLevelTypeParameters = enclosing.getFirstChildOfType(ASTTypeParameters.class); if (classLevelTypeParameters != null) { types.addAll(classLevelTypeParameters.findDescendantsOfType(ASTTypeParameter.class)); } } return resolveGenericType(typeImage, types); }
for (int i = 0; i < parent.jjtGetNumChildren(); i++) { Node n = parent.jjtGetChild(i); if (n instanceof ASTAnnotation) { if (n.jjtGetChild(0) instanceof ASTMarkerAnnotation) {
private <T> void lclFindChildrenOfType(Node node, Class<T> targetType, List<T> results) { if (node.getClass().equals(targetType)) { results.add((T) node); } if (node instanceof ASTClassOrInterfaceDeclaration && ((ASTClassOrInterfaceDeclaration) node).isNested()) { return; } if (node instanceof ASTClassOrInterfaceBodyDeclaration && ((ASTClassOrInterfaceBodyDeclaration) node).isAnonymousInnerClass()) { return; } for (int i = 0; i < node.jjtGetNumChildren(); i++) { Node child = node.jjtGetChild(i); if (child.getClass().equals(targetType)) { results.add((T) child); } } } }
@Override public boolean hasSuppressWarningsAnnotationFor(Rule rule) { for (int i = 0; i < jjtGetNumChildren(); i++) { if (jjtGetChild(i) instanceof ASTAnnotation) { ASTAnnotation a = (ASTAnnotation) jjtGetChild(i); if (a.suppresses(rule)) { return true; } } } return false; }
@Override public boolean isFindBoundary() { return isAnonymousInnerClass(); }
@Override public Object visit(ASTClassOrInterfaceBodyDeclaration node, Object data) { boolean inAnnotation = false; for (int i = 0; i < node.jjtGetNumChildren(); i++) { Node child = node.jjtGetChild(i); if (child instanceof ASTAnnotation) { ASTName annotationName = child.getFirstDescendantOfType(ASTName.class); if ("Test".equals(annotationName.getImage())) { inAnnotation = true; continue; } } if (child instanceof ASTMethodDeclaration) { boolean isJUnitMethod = isJUnitMethod((ASTMethodDeclaration) child, data); if (inAnnotation || isJUnitMethod) { List<Node> found = new ArrayList<>(); found.addAll((List<Node>) visit((ASTMethodDeclaration) child, data)); for (Node name : found) { addViolation(data, name); } } } inAnnotation = false; } return super.visit(node, data); }
private boolean inAnonymousInnerClass(Node node) { ASTClassOrInterfaceBodyDeclaration parent = node.getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class); return parent != null && parent.isAnonymousInnerClass(); }
for (int i = 0; i < parent.jjtGetNumChildren(); i++) { Node n = parent.jjtGetChild(i); if (n instanceof ASTAnnotation) { if (n.jjtGetChild(0) instanceof ASTMarkerAnnotation) {