EmptyPublicCtorInClassCheck extends AbstractCheck { @Override public void visitToken(DetailAST node) { switch (node.getType()) { case TokenTypes.IMPORT: final String packageMemberName = getIdentifierName(node); if (isOnDemandImport(packageMemberName)) { onDemandImports.add(packageMemberName); } else { singleTypeImports.add(packageMemberName); } break; case TokenTypes.CLASS_DEF: if (getClassCtorCount(node) == 1) { final DetailAST ctorDef = getFirstCtorDefinition(node); if (isCtorPublic(ctorDef) && isCtorHasNoParameters(ctorDef) && isCtorHasNoStatements(ctorDef) && !isClassHasRegisteredAnnotation(node) && !isCtorHasRegisteredAnnotation(ctorDef)) { log(ctorDef, MSG_KEY); } } break; case TokenTypes.PACKAGE_DEF: filePackageName = getIdentifierName(node); break; default: SevntuUtil.reportInvalidToken(node.getType()); break; } }  void setClassAnnotationNames(String regex); void setCtorAnnotationNames(String regex); @Override int[] getDefaultTokens(); @Override int[] getAcceptableTokens(); @Override int[] getRequiredTokens(); @Override void beginTree(DetailAST aRootNode); @Override void visitToken(DetailAST node); static final String MSG_KEY; }
@Test public void testUnsupportedNode() { final DetailAstImpl sync = new DetailAstImpl(); sync.setType(TokenTypes.LITERAL_SYNCHRONIZED); try { final EmptyPublicCtorInClassCheck check = new EmptyPublicCtorInClassCheck(); check.visitToken(sync); fail("exception expected"); } catch (IllegalArgumentException ex) { Assert.assertEquals("Found unsupported token: LITERAL_SYNCHRONIZED", ex.getMessage()); } }