/** * Returns the annotation instance for the given annotation type. * * @param annotationClass Tha annotation type to retrieve. * @param <A> Type of the annotation. * @return The annotation instance. */ public <A extends Annotation> A annotation(Class<A> annotationClass) { return field.getAnnotation(annotationClass); }
private boolean isTransient(Class c, Field field) { if (Modifier.isTransient(field.getModifiers())) return true; while (c.getName().indexOf("$") >= 0) { c = c.getSuperclass(); // patch fuer reallive queries, kontraktor spore } if ( field.getName().startsWith("this$") && c.getAnnotation(AnonymousTransient.class) != null ) return true; return (c.getAnnotation(Transient.class) != null && field.getAnnotation(Serialize.class) == null); }
@Override public <A extends Annotation> A getAnnotation(Class<A> annotationType) { A annotation; if (read != null) { annotation = read.getAnnotation(annotationType); } else if (field != null) { annotation = field.getAnnotation(annotationType); } else { annotation = delegate.getAnnotation(annotationType); } return annotation; }
public static <T extends Annotation> T getAnnotation(Class<?> clazz, String fieldName, Class<T> annotationClass) { try { Field field = getDeclaredField(clazz, fieldName); if (!field.isAccessible()) { field.setAccessible(true); } return field.getAnnotation(annotationClass); } catch (NoSuchFieldException e) { return null; } }
public static <T extends Annotation> T getAnnotation(Class<?> clazz, String fieldName, Class<T> annotationClass) { try { Field field = getDeclaredField(clazz, fieldName); if (!field.isAccessible()) { field.setAccessible(true); } return field.getAnnotation(annotationClass); } catch (NoSuchFieldException e) { return null; } }
/** * Retrieve a field/parameter annotation of the given type, if any. * @param annotationType the annotation type to retrieve * @return the annotation instance, or {@code null} if none found * @since 4.3.9 */ @Nullable public <A extends Annotation> A getAnnotation(Class<A> annotationType) { return (this.field != null ? this.field.getAnnotation(annotationType) : obtainMethodParameter().getParameterAnnotation(annotationType)); }
private static Collection<OptionWithMetaInfo> findCommonOptions(String rootDir, String module, String packageName, String pathPrefix) throws IOException, ClassNotFoundException { Collection<OptionWithMetaInfo> commonOptions = new ArrayList<>(32); processConfigOptions(rootDir, module, packageName, pathPrefix, optionsClass -> extractConfigOptions(optionsClass).stream() .filter(optionWithMetaInfo -> optionWithMetaInfo.field.getAnnotation(Documentation.CommonOption.class) != null) .forEachOrdered(commonOptions::add)); return commonOptions; }
/** * Build a {@link org.springframework.aop.aspectj.DeclareParentsAdvisor} * for the given introduction field. * <p>Resulting Advisors will need to be evaluated for targets. * @param introductionField the field to introspect * @return the Advisor instance, or {@code null} if not an Advisor */ @Nullable private Advisor getDeclareParentsAdvisor(Field introductionField) { DeclareParents declareParents = introductionField.getAnnotation(DeclareParents.class); if (declareParents == null) { // Not an introduction field return null; } if (DeclareParents.class == declareParents.defaultImpl()) { throw new IllegalStateException("'defaultImpl' attribute must be set on DeclareParents"); } return new DeclareParentsAdvisor( introductionField.getType(), declareParents.value(), declareParents.defaultImpl()); }
protected void storeIndex(Field field, Object me, Object arg) { if (field.getAnnotation(RIndex.class) != null) { NamingScheme namingScheme = objectBuilder.getNamingScheme(me.getClass().getSuperclass()); String indexName = namingScheme.getIndexName(me.getClass().getSuperclass(), field.getName()); RSetMultimap<Object, Object> map = redisson.getSetMultimap(indexName, namingScheme.getCodec()); map.put(arg, ((RLiveObject) me).getLiveObjectId()); } }
protected void storeIndex(Field field, Object me, Object arg) { if (field.getAnnotation(RIndex.class) != null) { NamingScheme namingScheme = objectBuilder.getNamingScheme(me.getClass().getSuperclass()); String indexName = namingScheme.getIndexName(me.getClass().getSuperclass(), field.getName()); RSetMultimap<Object, Object> map = redisson.getSetMultimap(indexName, namingScheme.getCodec()); map.put(arg, ((RLiveObject) me).getLiveObjectId()); } }
@Test public void testEquivalence() { assertTrue(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), field2.getAnnotation(TestAnnotation.class))); assertTrue(AnnotationUtils.equals(field2.getAnnotation(TestAnnotation.class), field1.getAnnotation(TestAnnotation.class))); }
@Test public void testNonEquivalentAnnotationsOfSameType() { assertFalse(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), field3.getAnnotation(TestAnnotation.class))); assertFalse(AnnotationUtils.equals(field3.getAnnotation(TestAnnotation.class), field1.getAnnotation(TestAnnotation.class))); }
@Test public void testAnnotationsOfDifferingTypes() { assertFalse(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), field4.getAnnotation(NestAnnotation.class))); assertFalse(AnnotationUtils.equals(field4.getAnnotation(NestAnnotation.class), field1.getAnnotation(TestAnnotation.class))); }
@Test public void testSameInstance() { assertTrue(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), field1.getAnnotation(TestAnnotation.class))); }
public ObjectFormatter build() { Formatter formatter = field.getAnnotation(Formatter.class); if (formatter != null && !formatter.formatter().equals(Formatter.DEFAULT_FORMATTER)) { return initFormatter(formatter.formatter(), formatter.value()); } if (formatter == null || formatter.subClazz().equals(Void.class)) { return initFormatterForType(field.getType(), formatter != null ? formatter.value() : null); } else { return initFormatterForType(formatter.subClazz(), formatter.value()); } } }
@Test(timeout = 666000) public void testHashCode() throws Exception { final Test test = getClass().getDeclaredMethod("testHashCode").getAnnotation(Test.class); assertEquals(test.hashCode(), AnnotationUtils.hashCode(test)); final TestAnnotation testAnnotation1 = field1.getAnnotation(TestAnnotation.class); assertEquals(testAnnotation1.hashCode(), AnnotationUtils.hashCode(testAnnotation1)); final TestAnnotation testAnnotation3 = field3.getAnnotation(TestAnnotation.class); assertEquals(testAnnotation3.hashCode(), AnnotationUtils.hashCode(testAnnotation3)); }
private <T> Object generateId(Class<T> entityClass) throws NoSuchFieldException { String idFieldName = getRIdFieldName(entityClass); RId annotation = ClassUtils.getDeclaredField(entityClass, idFieldName) .getAnnotation(RId.class); Resolver resolver = getResolver(entityClass, annotation.generator(), annotation); Object id = resolver.resolve(entityClass, annotation, idFieldName, redisson); return id; }
private <T> Object generateId(Class<T> entityClass) throws NoSuchFieldException { String idFieldName = getRIdFieldName(entityClass); RId annotation = ClassUtils.getDeclaredField(entityClass, idFieldName) .getAnnotation(RId.class); Resolver resolver = getResolver(entityClass, annotation.generator(), annotation); Object id = resolver.resolve(entityClass, annotation, idFieldName, redisson); return id; }
@Test public void testOneArgNull() { assertFalse(AnnotationUtils.equals(field1.getAnnotation(TestAnnotation.class), null)); assertFalse(AnnotationUtils.equals(null, field1.getAnnotation(TestAnnotation.class))); }
protected static String getPropertyKey(Field field) { JsonProperty jsonProperty = field.getAnnotation(JsonProperty.class); if (null != jsonProperty) { return getPropertyKey( (jsonProperty.value() == null || jsonProperty.value().isEmpty()) ? field.getName() : jsonProperty.value() ); } return null; }