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; }
/** Injects actors from group into target's fields annotated with {@link InjectActor} using reflection. */ public static void injectActorFields(Object target, Group group) { Class<?> handledClass = target.getClass(); while (handledClass != null && !handledClass.equals(Object.class)) { for (final Field field : ClassReflection.getDeclaredFields(handledClass)) { if (field != null && field.isAnnotationPresent(InjectActor.class)) { try { InjectActor annotation = field.getDeclaredAnnotation(InjectActor.class).getAnnotation(InjectActor.class); String actorName = annotation.value(); if (actorName.length() == 0) { actorName = field.getName(); } Actor actor = group.findActor(actorName); if (actor == null && actorName.equals(group.getName())) { actor = group; } if (actor == null) { Gdx.app.error(TAG_INJECT_FIELDS, "Can't find actor with name: " + actorName + " in group: " + group + " to inject into: " + target); } else { field.setAccessible(true); field.set(target, actor); } } catch (final ReflectionException exception) { Gdx.app.error(TAG_INJECT_FIELDS, "Unable to set value into field: " + field + " of object: " + target, exception); } } } handledClass = handledClass.getSuperclass(); } }
field.setAccessible(true); Annotation annotation = field .getDeclaredAnnotation(org.mini2Dx.core.serialization.annotation.Field.class);
field.setAccessible(true); Annotation annotation = field .getDeclaredAnnotation(org.mini2Dx.core.serialization.annotation.Field.class);
field.setAccessible(true); Annotation annotation = field .getDeclaredAnnotation(org.mini2Dx.core.serialization.annotation.Field.class);
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; }