@Override public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { if (node.isAbstract() || node.isInterface() || node.isNested()) { return data; } List<ASTMethodDeclaration> m = node.findDescendantsOfType(ASTMethodDeclaration.class); boolean testsFound = false; if (m != null) { for (ASTMethodDeclaration md : m) { if (isJUnitMethod(md, data)) { testsFound = true; break; } } } if (!testsFound) { addViolation(data, node); } return data; } }
/** * Returns the interfaces implemented by this class, or * extended by this interface. Returns an empty list if * none is specified. */ public List<ASTClassOrInterfaceType> getSuperInterfacesTypeNodes() { Iterable<ASTClassOrInterfaceType> it = isInterface() ? getFirstChildOfType(ASTExtendsList.class) : getFirstChildOfType(ASTImplementsList.class); return it == null ? Collections.<ASTClassOrInterfaceType>emptyList() : CollectionUtil.toList(it.iterator()); }
@Override public String getTypeImage() { return ((ASTClassOrInterfaceDeclaration) node).getImage(); }
/** * Find out whether the variable is used in an outer class */ private boolean usedInOuterClass(ASTClassOrInterfaceDeclaration node, NameDeclaration decl) { List<ASTClassOrInterfaceDeclaration> outerClasses = node.getParentsOfType(ASTClassOrInterfaceDeclaration.class); for (ASTClassOrInterfaceDeclaration outerClass : outerClasses) { ASTClassOrInterfaceBody classOrInterfaceBody = outerClass .getFirstChildOfType(ASTClassOrInterfaceBody.class); if (usedInOuter(decl, classOrInterfaceBody)) { return true; } } return false; }
@Override public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { if (node.isInterface() && node.isAbstract()) { // an abstract interface reportUnnecessaryModifiers(data, node, Modifier.ABSTRACT, "interface types are implicitly abstract"); } if (!node.isNested()) { return data; } boolean isParentInterfaceOrAnnotation = node.enclosingTypeIsA(TypeKind.INTERFACE, TypeKind.ANNOTATION); // a public class or interface within an interface or annotation if (node.isPublic() && isParentInterfaceOrAnnotation) { reportUnnecessaryModifiers(data, node, Modifier.PUBLIC, "members of " + getPrintableNodeKind(node.getEnclosingTypeDeclaration()) + " types are implicitly public"); } if (node.isStatic()) { if (node.isInterface()) { // a static interface reportUnnecessaryModifiers(data, node, Modifier.STATIC, "member interfaces are implicitly static"); } else if (isParentInterfaceOrAnnotation) { // a type nested within an interface reportUnnecessaryModifiers(data, node, Modifier.STATIC, "types nested within an interface type are implicitly static"); } } return data; }
@Override public Object visit(final ASTClassOrInterfaceDeclaration node, final Object data) { if (node.isInterface() || node.isStatic() || node.hasDescendantOfType(ASTConstructorDeclaration.class) || hasIgnoredAnnotation(node)) { return data; for (final ASTMethodDeclaration m : node.findDescendantsOfType(ASTMethodDeclaration.class)) { if (!m.isStatic()) { addViolation(data, node); for (final ASTFieldDeclaration f : node.findDescendantsOfType(ASTFieldDeclaration.class)) { if (!f.isStatic()) { addViolation(data, node);
final public void ClassOrInterfaceDeclaration(int modifiers) throws ParseException { ASTClassOrInterfaceDeclaration jjtn000 = new ASTClassOrInterfaceDeclaration(this, JJTCLASSORINTERFACEDECLARATION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1));Token t = null; jjtn000.setModifiers(modifiers); boolean inInterfaceOld = inInterface; inInterface = false; case INTERFACE: jj_consume_token(INTERFACE); jjtn000.setInterface(); inInterface = true; break; default: checkForBadTypeIdentifierUsage(t.image); jjtn000.setImage(t.image); switch (jj_nt.kind) { case LT: jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); inInterface = inInterfaceOld; } catch (Throwable jjte000) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
@Override public TypeKind getTypeKind() { return isInterface() ? TypeKind.INTERFACE : TypeKind.CLASS; }
/** * Returns {@code true} if access modifier of construtor is same as class's, * otherwise {@code false}. * * @param node the class declaration node * @param cons the constructor declaration node */ private boolean haveSameAccessModifier(ASTClassOrInterfaceDeclaration node, ASTConstructorDeclaration cons) { return node.isPrivate() && cons.isPrivate() || node.isProtected() && cons.isProtected() || node.isPublic() && cons.isPublic() || node.isPackagePrivate() && cons.isPackagePrivate(); } }
private boolean extendsOrImplementsCloneable(final ASTClassOrInterfaceDeclaration node) { if (node.getType() != null) { return Cloneable.class.isAssignableFrom(node.getType()); final ASTImplementsList impl = node.getFirstChildOfType(ASTImplementsList.class); if (impl != null) { for (int ix = 0; ix < impl.jjtGetNumChildren(); ix++) { if (node.jjtGetNumChildren() != 0 && node.jjtGetChild(0) instanceof ASTExtendsList) { final ASTClassOrInterfaceType type = (ASTClassOrInterfaceType) node.jjtGetChild(0).jjtGetChild(0); final Class<?> clazz = type.getType(); if (clazz != null) {
if (decl.jjtGetParent() instanceof ASTClassOrInterfaceDeclaration) { ASTClassOrInterfaceDeclaration parent = (ASTClassOrInterfaceDeclaration) decl.jjtGetParent(); if (parent.isAbstract() || parent.isInterface() || parent.getSuperClassTypeNode() != null) { return data;
@Override public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { if (node.isInterface()) { return super.visit(node, data); } if (!isPojo(node)) { return super.visit(node, data); } if (node.isAbstract() || withLombokAnnotation(node)) { return super.visit(node, data); } if (!node.hasDescendantMatchingXPath(XPATH)) { ViolationUtils.addViolationWithPrecisePosition(this, node, data, I18nResources.getMessage(MESSAGE_KEY_PREFIX + ".notostring", node.getImage())); } else { checkForExtend(node, data); } return super.visit(node, data); }
@Override public Object visit(ASTClassOrInterfaceDeclaration decl, Object data) { if (decl.isAbstract()) { List<ASTMethodDeclaration> methods = decl.findDescendantsOfType(ASTMethodDeclaration.class); for (ASTMethodDeclaration method : methods) { if (!method.isAbstract()) { if (!decl.isInterface()) { return super.visit(decl, data); methodNodes = decl.findChildNodesWithXPath(METHOD_IN_INTERFACE_XPATH); } catch (JaxenException e) { throw new RuntimeException("XPath expression " + METHOD_IN_INTERFACE_XPATH
@Override public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { if (node.isInterface()) { return data; } try { List<Node> nodes = node.findChildNodesWithXPath(XPATH); for (Node item : nodes) { if (!(item instanceof ASTName)) { continue; } addViolationWithMessage(data, item, "java.set.ClassCastExceptionWithSubListToArrayListRule.violation.msg", new Object[] {item.getImage()}); } } catch (JaxenException e) { e.printStackTrace(); } return super.visit(node, data); } }
private List<ASTConstructorDeclaration> findAllConstructors(ASTClassOrInterfaceDeclaration node) { return node.getFirstChildOfType(ASTClassOrInterfaceBody.class) .findDescendantsOfType(ASTConstructorDeclaration.class); } }
@Override public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { List<ASTMethodDeclarator> methods = node.findDescendantsOfType(ASTMethodDeclarator.class); for (ASTMethodDeclarator m : methods) { if (m.hasImageEqualTo(node.getImage())) { addViolation(data, m); } } return super.visit(node, data); } }
@Override public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { if (node.isAbstract()) { checkMatches(node, abstractClassRegex, data); } else if (isUtilityClass(node)) { checkMatches(node, utilityClassRegex, data); } else if (node.isInterface()) { checkMatches(node, interfaceRegex, data); } else { checkMatches(node, classRegex, data); } return data; }
@Override public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { if (node.isInterface()) { return data; } entryStack.push(new Entry(node)); super.visit(node, data); Entry classEntry = entryStack.pop(); if (showClassesComplexity) { if (classEntry.getComplexityAverage() >= reportLevel || classEntry.highestDecisionPoints >= reportLevel) { addViolation(data, node, new String[] { "class", node.getImage(), classEntry.getComplexityAverage() + " (Highest = " + classEntry.highestDecisionPoints + ')', }); } } return data; }