/** Returns true if the field includes an annotation of the provided class type. */ public boolean isAnnotationPresent (Class<? extends java.lang.annotation.Annotation> annotationType) { return field.isAnnotationPresent(annotationType); }
/** Returns true if the field includes an annotation of the provided class type. */ public boolean isAnnotationPresent (Class<? extends java.lang.annotation.Annotation> annotationType) { return field.isAnnotationPresent(annotationType); }
/** * Check if the field is annotated by the given annotation. * * @param annotationClass The annotation type to check. * @return <code>true</code> if the field is annotated by this annotation, else <code>false</code>. */ public boolean isAnnotatedBy(Class<? extends Annotation> annotationClass) { return field.isAnnotationPresent(annotationClass); }
private boolean isAnnotatedByMockOrSpy(Field field) { return field.isAnnotationPresent(Spy.class) || field.isAnnotationPresent(Mock.class); }
/** * Check if the field is annotated by the given annotation. * * @param annotationClass The annotation type to check. * @return <code>true</code> if the field is annotated by this annotation, else <code>false</code>. */ public boolean isAnnotatedBy(Class<? extends Annotation> annotationClass) { return field.isAnnotationPresent(annotationClass); }
protected boolean pathParams(Object o) { for (Field field : o.getClass().getDeclaredFields()) { if (field.isAnnotationPresent(PathParam.class)) { return true; } } return false; }
private static void assertNoIncompatibleAnnotations(Class<? extends Annotation> annotation, Field field, Class<? extends Annotation>... undesiredAnnotations) { for (Class<? extends Annotation> u : undesiredAnnotations) { if (field.isAnnotationPresent(u)) { throw unsupportedCombinationOfAnnotations(annotation.getSimpleName(), u.getSimpleName()); } } } }
private static void assertNoAnnotations(Field field, Class<? extends Annotation>... annotations) { for (Class<? extends Annotation> annotation : annotations) { if (field.isAnnotationPresent(annotation)) { throw unsupportedCombinationOfAnnotations(annotation.getSimpleName(), InjectMocks.class.getSimpleName()); } } } }
@Override public void introspectField(Class clazz, Field f) { if (f.isAnnotationPresent(Named.class)) { String name = f.getAnnotation(Named.class).value(); if (name.isEmpty()) { name = f.getName(); } nameLocal.set(name); } } }
public static StaticInjection create(Class<?> injectedClass) { List<Field> fields = new ArrayList<Field>(); for (Field field : injectedClass.getDeclaredFields()) { if (Modifier.isStatic(field.getModifiers()) && field.isAnnotationPresent(Inject.class)) { field.setAccessible(true); fields.add(field); } } if (fields.isEmpty()) { throw new IllegalArgumentException("No static injections: " + injectedClass.getName()); } return new ReflectiveStaticInjection(injectedClass.getClassLoader(), fields.toArray(new Field[fields.size()])); } }
@Override public void introspectField(Class clazz, Field f) { if (f.isAnnotationPresent(PathParam.class)) { String name = f.getAnnotation(PathParam.class).value(); if (name.isEmpty()) { name = f.getName(); } pathLocal.set(name); } }
void assertNoIncompatibleAnnotations(Class annotation, Field field, Class... undesiredAnnotations) { for (Class u : undesiredAnnotations) { if (field.isAnnotationPresent(u)) { new Reporter().unsupportedCombinationOfAnnotations(annotation.getSimpleName(), annotation.getClass().getSimpleName()); } } } }
void assertNoAnnotations(final Field field, final Class... annotations) { for (Class annotation : annotations) { if (field.isAnnotationPresent(annotation)) { new Reporter().unsupportedCombinationOfAnnotations(annotation.getSimpleName(), InjectMocks.class.getSimpleName()); } } } }
private List<EntityField> getFieldsFromClazz(Class<?> parameterClass) { return ReflectionKit.getFieldList(parameterClass).stream().map(field -> { field.setAccessible(true); return field.isAnnotationPresent(Version.class) ? new EntityField(field, true) : new EntityField(field, false); }).collect(Collectors.toList()); }
/** * 反射检查参数类是否启动乐观锁 * * @param parameterClass 实体类 * @param tableInfo 实体数据库反射信息 * @return ignore */ private EntityField getVersionFieldRegular(Class<?> parameterClass, TableInfo tableInfo) { return Object.class.equals(parameterClass) ? null : ReflectionKit.getFieldList(parameterClass).stream().filter(e -> e.isAnnotationPresent(Version.class)).map(field -> { field.setAccessible(true); return new EntityField(field, true, tableInfo.getFieldList().stream().filter(e -> field.getName().equals(e.getProperty())).map(TableFieldInfo::getColumn).findFirst().orElse(null)); }).findFirst().orElseGet(() -> this.getVersionFieldRegular(parameterClass.getSuperclass(), tableInfo)); }
private void walkFields(Object current, ConfigSaveValidationContext ctx, Handler handler) { for (Field field : getAllFields(current.getClass())) { field.setAccessible(true); try { Object o = field.get(current); if (o == null || isAConstantField(field) || field.isAnnotationPresent(IgnoreTraversal.class)) { continue; } walkSubtree(o, ctx, handler); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } }
/** * WARNING: rEntity has to be the class of @This object. */ private Codec getFieldCodec(Class<?> rEntity, Class<? extends RObject> rObjectClass, String fieldName) throws Exception { Field field = ClassUtils.getDeclaredField(rEntity, fieldName); if (field.isAnnotationPresent(RObjectField.class)) { RObjectField anno = field.getAnnotation(RObjectField.class); return codecProvider.getCodec(anno, rEntity, rObjectClass, fieldName, config); } else { REntity anno = ClassUtils.getAnnotation(rEntity, REntity.class); return codecProvider.getCodec(anno, (Class<?>) rEntity, config); } }
/** * WARNING: rEntity has to be the class of @This object. */ private Codec getFieldCodec(Class<?> rEntity, Class<? extends RObject> rObjectClass, String fieldName) throws Exception { Field field = ClassUtils.getDeclaredField(rEntity, fieldName); if (field.isAnnotationPresent(RObjectField.class)) { RObjectField anno = field.getAnnotation(RObjectField.class); return codecProvider.getCodec(anno, rEntity, rObjectClass, fieldName, config); } else { REntity anno = ClassUtils.getAnnotation(rEntity, REntity.class); return codecProvider.getCodec(anno, (Class<?>) rEntity, config); } }
@GwtIncompatible // reflection public void testGetField() { Field foo = Enums.getField(AnEnum.FOO); assertEquals("FOO", foo.getName()); assertTrue(foo.isAnnotationPresent(ExampleAnnotation.class)); Field bar = Enums.getField(AnEnum.BAR); assertEquals("BAR", bar.getName()); assertFalse(bar.isAnnotationPresent(ExampleAnnotation.class)); }
@Override public void postProcessTestInstance( Object testInstance, ExtensionContext context ) throws Exception { Class<?> clazz = testInstance.getClass(); Object instance = createInstance( context ); List<Field> declaredFields = getAllFields( clazz ); for ( Field declaredField : declaredFields ) { if ( declaredField.isAnnotationPresent( Inject.class ) && getFieldType().equals( declaredField.getType() ) ) { declaredField.setAccessible( true ); declaredField.set( testInstance, instance ); } } }