/** * Inspect method. * * @param method the method * @return the annotated field method */ public static AnnotatedFieldMethod inspectMethod(Method method) { Dynamic runtime = method.getAnnotation(Dynamic.class); Field.Property function = runtime.value(); switch (function) { case LENGTH: case OFFSET: checkSignature(method, int.class); return new IntFunction(method, function); case MASK: checkSignature(method, long.class); return new LongFunction(method, function); case VALUE: checkSignature(method, Object.class); return new ObjectFunction(method, function); case CHECK: checkSignature(method, boolean.class); return new BooleanFunction(method, function); case DISPLAY: case DESCRIPTION: checkSignature(method, String.class); return new StringFunction(method, function); default: throw new HeaderDefinitionError("Unsupported Dynamic function type " + function.toString()); } }
/** * Instantiates a new annotated field method. * * @param method the method * @param function the function */ public AnnotatedFieldMethod(Method method, Field.Property function) { super(method); this.function = function; Dynamic runtime = method.getAnnotation(Dynamic.class); if (runtime == null) { throw new HeaderDefinitionError( method.getDeclaringClass(), "unable get field's annotated runtime"); } if (runtime.field().length() != 0) { this.field = runtime.field(); } else { this.field = guessFieldName(method.getName()); } }
/** * Check annotation. * * @param method the method * @param fields the fields */ public static void checkAnnotation(Method method, List<AnnotatedField> fields) { Dynamic runtime = method.getAnnotation(Dynamic.class); if (runtime.field().length() != 0) { boolean found = false; final String name = runtime.field(); for (AnnotatedField f : fields) { if (f.getName().equals(name)) { found = true; break; } } if (!found) { throw new HeaderDefinitionError("field name defined in annotation "); } } }