Java源码示例:com.badlogic.gdx.utils.reflect.Annotation
示例1
private Metadata findMetadata (Class<?> clazz) {
Metadata metadata = metadataCache.get(clazz);
if (metadata == null) {
Annotation tca = ClassReflection.getAnnotation(clazz, TaskConstraint.class);
if (tca != null) {
TaskConstraint taskConstraint = tca.getAnnotation(TaskConstraint.class);
ObjectMap<String, AttrInfo> taskAttributes = new ObjectMap<String, AttrInfo>();
Field[] fields = ClassReflection.getFields(clazz);
for (Field f : fields) {
Annotation a = f.getDeclaredAnnotation(TaskAttribute.class);
if (a != null) {
AttrInfo ai = new AttrInfo(f.getName(), a.getAnnotation(TaskAttribute.class));
taskAttributes.put(ai.name, ai);
}
}
metadata = new Metadata(taskConstraint.minChildren(), taskConstraint.maxChildren(), taskAttributes);
metadataCache.put(clazz, metadata);
}
}
return metadata;
}
示例2
public static <T extends java.lang.annotation.Annotation> T getMethodAnnotation(Class<T> annotationType, Object object) {
T result = null;
Method[] methods = ClassReflection.getMethods(object.getClass());
for (Method m : methods) {
Annotation[] annotations = m.getDeclaredAnnotations();
Annotation a = m.getDeclaredAnnotation(annotationType);
if (a != null) {
result = a.getAnnotation(annotationType);
break;
}
}
return result;
}
示例3
private static StringBuilder appendTaskAttributes (StringBuilder attrs, Task<?> task) {
Class<?> aClass = task.getClass();
Field[] fields = ClassReflection.getFields(aClass);
for (Field f : fields) {
Annotation a = f.getDeclaredAnnotation(TaskAttribute.class);
if (a == null) continue;
TaskAttribute annotation = a.getAnnotation(TaskAttribute.class);
attrs.append('\n');
appendFieldString(attrs, task, annotation, f);
}
return attrs;
}