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\""); } } } }