Jsr305AnnotationsCheck extends AbstractCheck { private AbstractJsr305Handler handleDefinition(final DetailAST ast) { final DetailAST parent = ast.getParent(); AbstractJsr305Handler result = null; if (parent == null || parent.getType() != TokenTypes.LITERAL_CATCH) { final int type = ast.getType(); switch (type) { case TokenTypes.METHOD_DEF: result = new MethodJsr305Handler(ast); break; case TokenTypes.CTOR_DEF: result = new ConstructorJsr305Handler(ast); break; case TokenTypes.PARAMETER_DEF: result = new ParameterJsr305Handler(ast); break; case TokenTypes.CLASS_DEF: case TokenTypes.INTERFACE_DEF: case TokenTypes.ENUM_DEF: result = new ClassJsr305Handler(ast); break; default: SevntuUtil.reportInvalidToken(ast.getType()); break; } } return result; }  @Override final int[] getDefaultTokens(); @Override final int[] getRequiredTokens(); @Override final int[] getAcceptableTokens(); @Override void beginTree(DetailAST rootAST); @Override final void visitToken(final DetailAST ast); void setPackages(final String... packageNames); void setExcludePackages(final String... packageNames); void setAllowOverridingReturnValue(final boolean newAllowOverridingReturnValue); void setAllowOverridingParameter(final boolean newAllowOverridingParameter); static final String MSG_ILLEGAL_CLASS_LEVEL_ANNOTATION; static final String MSG_CONTRADICTING_CLASS_LEVEL_ANNOTATIONS; static final String MSG_PARAM_DEFINITIONS_WITH_CHECK; static final String MSG_PARAM_DEFINITION_WITH_OVERRIDE; static final String MSG_PARAM_DEFINITION_WITH_NONNULL_BY_DEFAULT; static final String MSG_PARAM_DEFINITION_WITH_NULLABLE_BY_DEFAULT; static final String MSG_PARAM_DEFINITION_WITH_RETURN_DEFAULT; static final String MSG_PARAM_NONNULL_AND_NULLABLE; static final String MSG_PRIMITIVES_WITH_NULLNESS_ANNOTATION; static final String MSG_OVERRIDDEN_WITH_INCREASED_CONSTRAINT; static final String MSG_REDUNDANT_NONNULL_PARAM_ANNOTATION; static final String MSG_REDUNDANT_NULLABLE_PARAM_ANNOTATION; static final String MSG_PARAMETER_WITHOUT_NULLNESS_ANNOTATION; static final String MSG_RETURN_VALUE_WITH_NONNULL_BY_DEFAULT; static final String MSG_RETURN_VALUE_WITH_NULLABLE; static final String MSG_CONTRADICTING_RETURN_VALUE_ANNOTATIONS; static final String MSG_OVERRIDDEN_METHOD_WITH_CHECK_RETURN_VALUE; static final String MSG_REDUNDANT_NONNULL_BY_DEFAULT_ANNOTATION; static final String MSG_REDUNDANT_NULLABLE_BY_DEFAULT_ANNOTATION; static final String MSG_VOID_WITH_CHECK_RETURN_VALUE_ANNOTATION; static final String MSG_REDUNDANT_NONNULL_RETURN_ANNOTATION; static final String MSG_RETURN_WITHOUT_NULLNESS_ANNOTATION; static final String MSG_OVERRIDDEN_METHODS_ALLOW_ONLY_NONNULL; static final String MSG_NEED_TO_INHERIT_PARAM_ANNOTATIONS; static final String MSG_CONSTRUCTOR_WITH_RETURN_ANNOTATION; }
@Test public void testHandleDefinition() throws Exception { final DetailAstImpl ast = new DetailAstImpl(); ast.setType(TokenTypes.WILDCARD_TYPE); final Method handleDefinition = TestUtil.getClassDeclaredMethod(Jsr305AnnotationsCheck.class, "handleDefinition"); try { handleDefinition.invoke(new Jsr305AnnotationsCheck(), ast); Assert.fail("Exception expected."); } catch (final InvocationTargetException exc) { Assert.assertTrue("IllegalArgumentException expected from 'handleDefinition'", exc.getCause().getClass().equals(IllegalArgumentException.class)); } }