Example usage for com.badlogic.gdx.utils.reflect Field isAnnotationPresent

List of usage examples for com.badlogic.gdx.utils.reflect Field isAnnotationPresent

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils.reflect Field isAnnotationPresent.

Prototype

public boolean isAnnotationPresent(Class<? extends java.lang.annotation.Annotation> annotationType) 

Source Link

Document

Returns true if the field includes an annotation of the provided class type.

Usage

From source file:es.eucm.ead.editor.view.controllers.ClassOptionsController.java

License:Open Source License

public ClassOptionsController(Controller controller, Skin skin, Class<T> reflectedClass, String i18nPrefix,
        Array<String> ignoreFields) {
    super(controller, skin);
    this.clazz = reflectedClass;
    i18nPrefix(i18nPrefix + ClassReflection.getSimpleName(clazz).toLowerCase());

    Class clazz = reflectedClass;
    while (clazz != null) {
        for (java.lang.reflect.Field field : clazz.getDeclaredFields()) {
            String fieldName = field.getName();
            if (ignoreFields != null && ignoreFields.contains(fieldName, false)) {
                continue;
            }/*from  w  w w .ja  v  a 2s  . c om*/
            if (field.isAnnotationPresent(Search.class)) {
                Search search = field.getAnnotation(Search.class);
                try {
                    FuzzyIndex index = controller.getIndex(ClassReflection.forName(search.index()));
                    search(fieldName, index);
                } catch (ReflectionException e) {
                    Gdx.app.error("ClassOptionsController", "No class for " + search.index());
                }
            } else if (field.isAnnotationPresent(Text.class)) {
                Text text = field.getAnnotation(Text.class);
                text(fieldName, text.lines());
            } else if (field.isAnnotationPresent(Fixed.class)) {
                fixed(fieldName);
            } else if (field.isAnnotationPresent(File.class)) {
                File file = field.getAnnotation(File.class);
                file(fieldName).folder(file.folder()).mustExist(file.mustExist());
            } else if (field.getType() == Integer.class || field.getType() == int.class) {
                this.intNumber(fieldName);
            } else if (field.getType() == Float.class || field.getType() == float.class) {
                floatNumber(fieldName);
            } else if (field.getType() == String.class) {
                string(fieldName);
            } else if (field.getType() == Boolean.class || field.getType() == boolean.class) {
                bool(fieldName);
            } else if (field.getType().isEnum()) {
                Map<String, Object> values = new LinkedHashMap<String, Object>();
                for (Object o : field.getType().getEnumConstants()) {
                    values.put(o.toString(), o);
                }
                select(fieldName, values);
            }
        }
        clazz = clazz.getSuperclass();
    }
}