/** * {@inheritDoc} */ public boolean isAnnotationPresent(TypeDescription annotationType) { for (AnnotationDescription annotation : this) { if (annotation.getAnnotationType().equals(annotationType)) { return true; } } return false; }
/** * {@inheritDoc} */ public AnnotationDescription ofType(TypeDescription annotationType) { for (AnnotationDescription annotation : this) { if (annotation.getAnnotationType().equals(annotationType)) { return annotation; } } return AnnotationDescription.UNDEFINED; }
/** * Checks if the supplied enumeration descriptions describe the correct annotation type. * * @param annotationType The annotation type to check for. * @param annotationDescription The annotation descriptions to check. * @return {@code true} if all annotation descriptions represent the annotation type in question. */ private static boolean isAnnotationType(TypeDescription annotationType, AnnotationDescription... annotationDescription) { for (AnnotationDescription anAnnotationDescription : annotationDescription) { if (!anAnnotationDescription.getAnnotationType().equals(annotationType)) { return false; } } return true; }
/** * {@inheritDoc} */ public boolean matches(T target) { return matcher.matches(target.getAnnotationType()); }
/** * {@inheritDoc} */ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) { for (AnnotationDescription annotation : this) { if (annotation.getAnnotationType().represents(annotationType)) { return true; } } return false; }
/** * {@inheritDoc} */ public TypeList asTypeList() { List<TypeDescription> annotationTypes = new ArrayList<TypeDescription>(size()); for (AnnotationDescription annotation : this) { annotationTypes.add(annotation.getAnnotationType()); } return new TypeList.Explicit(annotationTypes); }
/** * 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; } }
/** * {@inheritDoc} */ public AnnotationList inherited(Set<? extends TypeDescription> ignoredTypes) { List<AnnotationDescription> inherited = new ArrayList<AnnotationDescription>(size()); for (AnnotationDescription annotation : this) { if (!ignoredTypes.contains(annotation.getAnnotationType()) && annotation.isInherited()) { inherited.add(annotation); } } return wrap(inherited); }
/** * Creates a new complex array of annotation descriptions. * * @param annotationType A description of the type of the annotation. * @param annotationDescription An array of annotation descriptions. * @param <W> The type of the annotation. * @return A description of the array of enumeration values. */ public static <W extends Annotation> AnnotationValue<AnnotationDescription[], W[]> of(TypeDescription annotationType, AnnotationDescription[] annotationDescription) { List<AnnotationValue<AnnotationDescription, W>> values = new ArrayList<AnnotationValue<AnnotationDescription, W>>(annotationDescription.length); for (AnnotationDescription value : annotationDescription) { if (!value.getAnnotationType().equals(annotationType)) { throw new IllegalArgumentException(value + " is not of " + annotationType); } values.add(new ForAnnotationDescription<W>(value)); } return new ForDescriptionArray<AnnotationDescription, W>(AnnotationDescription.class, annotationType, values); }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") public <T extends Annotation> AnnotationDescription.Loadable<T> ofType(Class<T> annotationType) { for (AnnotationDescription annotation : this) { if (annotation.getAnnotationType().represents(annotationType)) { return annotation.prepare(annotationType); } } return (AnnotationDescription.Loadable<T>) AnnotationDescription.UNDEFINED; }
/** * {@inheritDoc} */ public AnnotationValue.Loaded<U> load(ClassLoader classLoader) throws ClassNotFoundException { @SuppressWarnings("unchecked") Class<U> annotationType = (Class<U>) Class.forName(annotationDescription.getAnnotationType().getName(), false, classLoader); return new Loaded<U>(annotationDescription.prepare(annotationType).load()); }
/** * Tries to append a given annotation by reflectively reading an annotation. * * @param annotation The annotation to be written. * @param visible {@code true} if this annotation should be treated as visible at runtime. * @param annotationValueFilter The annotation value filter to apply. */ private void doAppend(AnnotationDescription annotation, boolean visible, AnnotationValueFilter annotationValueFilter) { handle(target.visit(annotation.getAnnotationType().getDescriptor(), visible), annotation, annotationValueFilter); }
@Override public boolean equals(Object other) { if (this == other) { return true; } else if (!(other instanceof AnnotationDescription)) { return false; } AnnotationDescription annotationDescription = ((AnnotationDescription) other); TypeDescription annotationType = getAnnotationType(); if (!annotationDescription.getAnnotationType().equals(annotationType)) { return false; } for (MethodDescription.InDefinedShape methodDescription : annotationType.getDeclaredMethods()) { if (!getValue(methodDescription).equals(annotationDescription.getValue(methodDescription))) { return false; } } return true; }
/** * Tries to append a given annotation by reflectively reading an annotation. * * @param annotation The annotation to be written. * @param visible {@code true} if this annotation should be treated as visible at runtime. * @param annotationValueFilter The annotation value filter to apply. * @param typeReference The type annotation's type reference. * @param typePath The type annotation's type path. */ private void doAppend(AnnotationDescription annotation, boolean visible, AnnotationValueFilter annotationValueFilter, int typeReference, String typePath) { handle(target.visit(annotation.getAnnotationType().getDescriptor(), visible, typeReference, typePath), annotation, annotationValueFilter); } }
/** * Locates a handler which is responsible for processing the given parameter. If no explicit handler can * be located, a fallback handler is provided. * * @param target The target parameter being handled. * @return A handler for processing the parameter with the given annotations. */ protected Handler prepare(ParameterDescription target) { Assigner.Typing typing = RuntimeType.Verifier.check(target); Handler handler = new Handler.Unbound(target, typing); for (AnnotationDescription annotation : target.getDeclaredAnnotations()) { ParameterBinder<?> parameterBinder = parameterBinders.get(annotation.getAnnotationType()); if (parameterBinder != null && handler.isBound()) { throw new IllegalStateException("Ambiguous binding for parameter annotated with two handled annotation types"); } else if (parameterBinder != null /* && !handler.isBound() */) { handler = Handler.Bound.of(target, parameterBinder, annotation, typing); } } return handler; }
/** * {@inheritDoc} */ public AnnotationList getInheritedAnnotations() { Generic superClass = getSuperClass(); AnnotationList declaredAnnotations = getDeclaredAnnotations(); if (superClass == null) { return declaredAnnotations; } else { Set<TypeDescription> annotationTypes = new HashSet<TypeDescription>(); for (AnnotationDescription annotationDescription : declaredAnnotations) { annotationTypes.add(annotationDescription.getAnnotationType()); } return new AnnotationList.Explicit(CompoundList.of(declaredAnnotations, superClass.asErasure().getInheritedAnnotations().inherited(annotationTypes))); } }
OffsetMapping offsetMapping = null; for (AnnotationDescription annotationDescription : parameterDescription.getDeclaredAnnotations()) { OffsetMapping.Factory<?> factory = offsetMappings.get(annotationDescription.getAnnotationType()); if (factory != null) { @SuppressWarnings("unchecked")
/** * Handles the writing of a single annotation to an annotation visitor. * * @param annotationVisitor The annotation visitor the write process is to be applied on. * @param annotation The annotation to be written. * @param annotationValueFilter The value filter to apply for discovering which values of an annotation should be written. */ private static void handle(AnnotationVisitor annotationVisitor, AnnotationDescription annotation, AnnotationValueFilter annotationValueFilter) { for (MethodDescription.InDefinedShape methodDescription : annotation.getAnnotationType().getDeclaredMethods()) { if (annotationValueFilter.isRelevant(annotation, methodDescription)) { apply(annotationVisitor, methodDescription.getReturnType().asErasure(), methodDescription.getName(), annotation.getValue(methodDescription).resolve()); } } annotationVisitor.visitEnd(); }
|| (value instanceof AnnotationDescription && ((AnnotationDescription) value).getAnnotationType().equals(this)) || (value instanceof EnumerationDescription && ((EnumerationDescription) value).getEnumerationType().equals(this)) || (represents(String.class) && value instanceof String) } else if (isAssignableTo(Annotation[].class) && value instanceof AnnotationDescription[]) { for (AnnotationDescription annotationDescription : (AnnotationDescription[]) value) { if (!annotationDescription.getAnnotationType().equals(getComponentType())) { return false;