com.badlogic.gdx.utils.reflect.Annotation Java Examples

The following examples show how to use com.badlogic.gdx.utils.reflect.Annotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BehaviorTreeParser.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: AnnotationFinder.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #3
Source File: BehaviorTreeViewer.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
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;
}