PublicReferenceToPrivateTypeCheck extends AbstractCheck { @Override public void visitToken(DetailAST defAst) { switch (defAst.getType()) { case TokenTypes.CLASS_DEF: case TokenTypes.INTERFACE_DEF: case TokenTypes.ENUM_DEF: if (hasModifier(TokenTypes.LITERAL_PRIVATE, defAst)) { addPrivateTypes(defAst); } break; case TokenTypes.METHOD_DEF: if (isDefinedInTopLevelClass(defAst) && !hasModifier(TokenTypes.LITERAL_PRIVATE, defAst)) { addExternallyAccessibleMethodTypes(defAst); } break; case TokenTypes.VARIABLE_DEF: if (isDefinedInTopLevelClass(defAst) && !hasModifier(TokenTypes.LITERAL_PRIVATE, defAst)) { addExternallyAccessibleFieldTypes(defAst); } break; default: SevntuUtil.reportInvalidToken(defAst.getType()); break; } }  @Override int[] getDefaultTokens(); @Override int[] getAcceptableTokens(); @Override int[] getRequiredTokens(); @Override void beginTree(DetailAST rootAST); @Override void visitToken(DetailAST defAst); @Override void finishTree(DetailAST rootAst); static boolean hasModifier(int modifierType, DetailAST defAst); static final String MSG_KEY; }
@Test public void testUnsupportedNode() { final DetailAstImpl sync = new DetailAstImpl(); sync.setType(TokenTypes.LITERAL_SYNCHRONIZED); try { final PublicReferenceToPrivateTypeCheck check = new PublicReferenceToPrivateTypeCheck(); check.visitToken(sync); fail("exception expected"); } catch (IllegalArgumentException ex) { Assert.assertEquals("Found unsupported token: LITERAL_SYNCHRONIZED", ex.getMessage()); } }