ContractsBoltReflector.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:storm-data-contracts 作者:
private void checkAnnotations(Class<?> contractClass) {
    Field[] fields = contractClass.getFields();
    for (Field field : fields) {
        Class fieldType = field.getType();
        if (Optional.class.isAssignableFrom(fieldType)) {
            checkAnnotation(contractClass, field,UnwrapValidatedValue.class);
            checkNoAnnotation(contractClass, field, NotNull.class);
        }
        else {
            checkNoAnnotation(contractClass, field, UnwrapValidatedValue.class);
            checkAnnotation(contractClass, field,NotNull.class);
        }
    }

    for(Method method : contractClass.getMethods()) {
        if(method.isAnnotationPresent(AssertTrue.class) || method.isAnnotationPresent(AssertFalse.class)) {
            if(method.getReturnType() != boolean.class && method.getReturnType() != Boolean.class) {
                throw new IllegalStateException("AssertTrue or AssertFalse annotations must be placed above methods that return boolean value");
            }

            if(!method.getName().startsWith("is")) {
                throw new IllegalStateException("Methods annotated with AssertTrue or AssertFalse must start with \"is\"");
            }
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号