List of usage examples for java.lang.reflect Field isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:gr.abiss.calipso.tiers.util.ModelContext.java
private boolean hasAnnotation(Field field, Class<?>... annotations) { for (Class<?> a : annotations) { if (field.isAnnotationPresent((Class<Annotation>) a)) { return true; }/*from w ww .j a va2s . c o m*/ } return false; }
From source file:com.github.fharms.camel.entitymanager.CamelEntityManagerHandler.java
/** * Scan all fields for the {@link PersistenceContext} annotation and verify the type and return * a list of annotated fields. If the field is also annotated with {@link IgnoreCamelEntityManager} * it will be ignored from the list/*from w ww . j a v a2s . c om*/ * * @param bean Name of the bean to scan for annotation * @return List of fields annotated with {@link PersistenceContext} */ private List<Field> getAnnotatedFields(Object bean) throws IllegalAccessException { List<Field> annotatedFields = new ArrayList<>(); if (bean == null) { return annotatedFields; } Field[] declaredFields = bean.getClass().getDeclaredFields(); for (Field field : declaredFields) { boolean currentAccessible = field.isAccessible(); field.setAccessible(true); if (EntityManager.class.isAssignableFrom(field.getType()) && (field.isAnnotationPresent(PersistenceContext.class)) && (!field.isAnnotationPresent(IgnoreCamelEntityManager.class)) && (field.get(bean) != null)) { annotatedFields.add(field); } field.setAccessible(currentAccessible); } return annotatedFields; }
From source file:es.caib.sgtsic.utils.ejb.AbstractService.java
public boolean borrable(Object id) { T item = this.find(id); log.debug("Entramos a borrable " + item); if (item == null) { return false; }/*from w w w . jav a 2s. c o m*/ log.debug("Entramos a borrable con no false " + item); for (Field f : entityClass.getDeclaredFields()) { boolean hasToManyAnnotations = (f.isAnnotationPresent(OneToMany.class)) || (f.isAnnotationPresent(ManyToMany.class)); if (hasToManyAnnotations) { Type type = f.getGenericType(); ParameterizedType pt = (ParameterizedType) type; List<Type> arguments = Arrays.asList(pt.getActualTypeArguments()); Class childEntityClass = null; for (Type argtype : arguments) { childEntityClass = (Class) argtype; break; } if (childEntityClass == null) { continue; } if (this.childrenCount(id, childEntityClass, entityClass) > 0) { log.debug("Cuenta positiva"); return false; } } } log.debug("Cuenta 0"); return true; }
From source file:com.all.testing.MockInyectRunner.java
private Field getUnderTestField(List<Field> fields) { Field result = null;//from ww w .ja v a 2 s. com boolean underTestFound = false; for (Field testField : fields) { if (testField.isAnnotationPresent(UnderTest.class)) { if (underTestFound) { throw new IllegalStateException("Solo puedes tener una sola propiedad con @UnderTest"); } underTestFound = true; result = testField; result.setAccessible(true); } } if (!underTestFound) { throw new IllegalStateException("Debes marcar una propiedad con @UnderTest"); } return result; }
From source file:com.nick.scalpel.Scalpel.java
public void wire(Activity activity, Scope scope) { if (isInScope(scope, Scope.Class)) wireClz(activity);/* ww w .j ava2s.c om*/ if (isInScope(scope, Scope.Field)) { Class clz = activity.getClass(); for (Field field : clz.getDeclaredFields()) { for (FieldWirer wirer : mFieldWirers) { if (field.isAnnotationPresent(wirer.annotationClass())) { wirer.wire(activity, field); } } } } }
From source file:com.nick.scalpel.Scalpel.java
public void wire(Service service, Scope scope) { if (isInScope(scope, Scope.Class)) wireClz(service);/*from ww w.j av a 2 s . c om*/ if (isInScope(scope, Scope.Field)) { Class clz = service.getClass(); for (Field field : clz.getDeclaredFields()) { for (FieldWirer wirer : mFieldWirers) { if (field.isAnnotationPresent(wirer.annotationClass())) { wirer.wire(service, field); } } } } }
From source file:com.nick.scalpel.Scalpel.java
public void wire(Fragment fragment, Scope scope) { if (isInScope(scope, Scope.Class)) wireClz(fragment);/*w w w . j ava 2s . com*/ if (isInScope(scope, Scope.Field)) { Class clz = fragment.getClass(); for (Field field : clz.getDeclaredFields()) { for (FieldWirer wirer : mFieldWirers) { if (field.isAnnotationPresent(wirer.annotationClass())) { wirer.wire(fragment, field); } } } } }
From source file:com.nick.scalpel.Scalpel.java
public void wire(Context context, Object target, Scope scope) { if (isInScope(scope, Scope.Class)) wireClz(target);/*from ww w . ja v a2 s . com*/ if (isInScope(scope, Scope.Field)) { Class clz = target.getClass(); for (Field field : clz.getDeclaredFields()) { for (FieldWirer wirer : mFieldWirers) { if (field.isAnnotationPresent(wirer.annotationClass())) { wirer.wire(context, target, field); break; } } } } }
From source file:com.nick.scalpel.Scalpel.java
public void wire(View rootView, Object target, Scope scope) { if (isInScope(scope, Scope.Class)) wireClz(target);//from w ww . j a v a2 s. c o m if (isInScope(scope, Scope.Field)) { Class clz = target.getClass(); for (Field field : clz.getDeclaredFields()) { for (FieldWirer wirer : mFieldWirers) { if (field.isAnnotationPresent(wirer.annotationClass())) { wirer.wire(rootView, target, field); break; } } } } }