List of usage examples for java.lang.reflect Field getAnnotation
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
From source file:DataBeanTest.java
public static void main(String[] args) { Class d = DataBean.class; Field fs[] = d.getFields();/*from w w w.ja va 2s.c o m*/ for (Field f : fs) { System.out.println(f); Annotation a = f.getAnnotation(DataField.class); if (a != null) { System.out.println(f.getName()); } } }
From source file:Main.java
static String getElementName(Field field) { XmlElement element = (XmlElement) field.getAnnotation(XmlElement.class); return !DEFAULT_NAME.equals(element.name()) ? element.name() : field.getName(); }
From source file:Main.java
static String getAttributeName(Field field) { XmlAttribute attribute = (XmlAttribute) field.getAnnotation(XmlAttribute.class); return !DEFAULT_NAME.equals(attribute.name()) ? attribute.name() : field.getName(); }
From source file:net.eledge.android.toolkit.db.internal.SQLBuilder.java
public static String getFieldName(Field field) { Column column = field.getAnnotation(Column.class); return StringUtils.defaultIfBlank(column.name(), field.getName().toLowerCase(Locale.ENGLISH)); }
From source file:org.apache.aries.blueprint.plugin.model.Property.java
private static boolean needsInject(Field field) { return field.getAnnotation(Autowired.class) != null || field.getAnnotation(Inject.class) != null; }
From source file:Main.java
public static String value(Class<? extends Enum> aClass, String name) { try {//from w ww. j a v a 2 s . c o m Field field = aClass.getField(name); XmlEnumValue annotation = field.getAnnotation(XmlEnumValue.class); return annotation.value(); } catch (NoSuchFieldException e) { throw new IllegalStateException(); } }
From source file:org.apache.aries.blueprint.plugin.model.Property.java
/** * Assume it is defined in another manually created blueprint context with default name * @param field//from w ww .j a v a 2 s . c om * @return */ private static String getRefName(Field field) { Named named = field.getAnnotation(Named.class); return (named != null) ? named.value() : Bean.getBeanName(field.getType()); }
From source file:Main.java
public static <ENUM extends Enum> ENUM fromValue(Class<ENUM> aClass, String value) { try {/*from w w w.j av a2s. com*/ for (ENUM c : aClass.getEnumConstants()) { Field field = aClass.getField(c.name()); XmlEnumValue annotation = field.getAnnotation(XmlEnumValue.class); if (annotation.value().equals(value)) { return c; } } } catch (NoSuchFieldException e) { } throw new IllegalArgumentException(value); }
From source file:org.apache.aries.blueprint.plugin.model.Property.java
public static Property create(Matcher matcher, Field field) { Value value = field.getAnnotation(Value.class); if (needsInject(field)) { Bean matching = matcher.getMatching(field); String ref = (matching == null) ? getRefName(field) : matching.id; return new Property(field.getName(), ref, null); } else if (value != null) { return new Property(field.getName(), null, cleanValue(value.value())); } else {/*w w w. j a v a2 s .c o m*/ // Field is not a property return null; } }
From source file:Main.java
public static List<Field> getAllFieldsWithAnnotation(List<Field> fields, Class<?> type, Class<? extends Annotation> annotationType) { for (Field field : type.getDeclaredFields()) { if (annotationType == null || field.getAnnotation(annotationType) != null) { fields.add(field);/* w ww. j av a 2 s .co m*/ } } if (type.getSuperclass() != null) { fields = getAllFieldsWithAnnotation(fields, type.getSuperclass(), annotationType); } return fields; }