/** * Validates the type annotations on a formal type variable but not on its bounds.. * * @param typeVariable The type variable to validate. * @return {@code true} if the formal type variable declares invalid type annotations. */ public static boolean ofFormalTypeVariable(Generic typeVariable) { Set<TypeDescription> annotationTypes = new HashSet<TypeDescription>(); for (AnnotationDescription annotationDescription : typeVariable.getDeclaredAnnotations()) { if (!annotationDescription.getElementTypes().contains(INSTANCE.typeParameter) || !annotationTypes.add(annotationDescription.getAnnotationType())) { return false; } } return true; }
/** * Checks if the supplied type's type annotations are valid. * * @param typeDescription The type to validate. * @return {@code true} if the supplied type's type annotations are valid. */ private boolean isValid(Generic typeDescription) { Set<TypeDescription> annotationTypes = new HashSet<TypeDescription>(); for (AnnotationDescription annotationDescription : typeDescription.getDeclaredAnnotations()) { if (!annotationDescription.getElementTypes().contains(typeUse) || !annotationTypes.add(annotationDescription.getAnnotationType())) { return false; } } return true; } }
if (!returnType.represents(void.class)) { throw new IllegalStateException("A constructor must return void " + methodDescription); } else if (!returnType.getDeclaredAnnotations().isEmpty()) { throw new IllegalStateException("The void non-type must not be annotated for " + methodDescription);
private void visitFields(Set<Class<?>> types, AnnotationCache cache, TypeDescription typeDescription, boolean inheriting) { typeDescription.getDeclaredFields().forEach(f -> { Consumer<Annotation> addToCache = a -> types.forEach(t -> cache.addFieldAnnotation(t, f.getName(), a)); // Regular field annotations f.getDeclaredAnnotations() .forEach(a -> cacheSupportedAnnotations(a, types, cache, addToCache, inheriting)); // Type-use annotations f.getType().getDeclaredAnnotations() .forEach(a -> cacheSupportedAnnotations(a, types, cache, addToCache, inheriting)); }); typeDescription.getDeclaredMethods() .filter(m -> m.getName().startsWith("get") && m.getName().length() > 3) .forEach(m -> { String methodName = m.getName(); String correspondingFieldName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4); Consumer<Annotation> addToCache = a -> types.forEach(t -> cache.addFieldAnnotation(t, correspondingFieldName, a)); m.getDeclaredAnnotations() .forEach(a -> cacheSupportedAnnotations(a, types, cache, addToCache, inheriting)); }); }
for (AnnotationDescription annotationDescription : typeVariable.getDeclaredAnnotations()) { annotationAppender = annotationAppender.append(annotationDescription, annotationValueFilter, typeReference, EMPTY_TYPE_PATH);
/** * Writes all annotations of the supplied type to this instance's annotation appender. * * @param typeDescription The type of what all annotations should be written of. * @param typePath The type path to use. * @return The resulting annotation appender. */ private AnnotationAppender apply(TypeDescription.Generic typeDescription, String typePath) { AnnotationAppender annotationAppender = this.annotationAppender; for (AnnotationDescription annotationDescription : typeDescription.getDeclaredAnnotations()) { annotationAppender = annotationAppender.append(annotationDescription, annotationValueFilter, typeReference, typePath); } return annotationAppender; } }
/** * {@inheritDoc} */ public AnnotationList getDeclaredAnnotations() { return resolve().getDeclaredAnnotations(); }
/** * {@inheritDoc} */ public AnnotationList getDeclaredAnnotations() { return resolve().getDeclaredAnnotations(); }
/** * Transforms a type variable into a type variable token with its bounds detached. * * @param typeVariable A type variable in its attached state. * @param matcher A matcher that identifies types to detach from the upper bound types. * @return A token representing the detached type variable. */ public static TypeVariableToken of(TypeDescription.Generic typeVariable, ElementMatcher<? super TypeDescription> matcher) { return new TypeVariableToken(typeVariable.getSymbol(), typeVariable.getUpperBounds().accept(new TypeDescription.Generic.Visitor.Substitutor.ForDetachment(matcher)), typeVariable.getDeclaredAnnotations()); }
/** * {@inheritDoc} */ public AnnotationList getDeclaredAnnotations() { return resolve().getDeclaredAnnotations(); }
/** * {@inheritDoc} */ public AnnotationList getDeclaredAnnotations() { return delegate.getDeclaredAnnotations(); }
/** * {@inheritDoc} */ public AnnotationList getDeclaredAnnotations() { return typeVariable.getDeclaredAnnotations(); } }