/** * Create a new {@link StandardAnnotationMetadata} wrapper for the given Class, * providing the option to return any nested annotations or annotation arrays in the * form of {@link org.springframework.core.annotation.AnnotationAttributes} instead * of actual {@link Annotation} instances. * @param introspectedClass the Class to introspect * @param nestedAnnotationsAsMap return nested annotations and annotation arrays as * {@link org.springframework.core.annotation.AnnotationAttributes} for compatibility * with ASM-based {@link AnnotationMetadata} implementations * @since 3.1.1 */ public StandardAnnotationMetadata(Class<?> introspectedClass, boolean nestedAnnotationsAsMap) { super(introspectedClass); this.annotations = introspectedClass.getAnnotations(); this.nestedAnnotationsAsMap = nestedAnnotationsAsMap; }
/** * Returns the annotations on this class */ public Annotation[] getAnnotations() { if (clazz == null) { return new Annotation[0]; } return clazz.getAnnotations(); }
/** * Returns the annotations on this class */ public Annotation[] getAnnotations() { if (fClass == null) { return new Annotation[0]; } return fClass.getAnnotations(); }
public Annotation[] getAnnotations() { return clazz.getAnnotations(); }
public Annotation[] getAnnotations() { return clazz.getAnnotations(); }
private static boolean shouldUseFileSplitsFromInputFormat(InputFormat<?, ?> inputFormat) { return Arrays.stream(inputFormat.getClass().getAnnotations()) .map(Annotation::annotationType) .map(Class::getSimpleName) .anyMatch(name -> name.equals("UseFileSplitsFromInputFormat")); }
/** Returns an array of {@link Annotation} objects reflecting all annotations declared by the supplied class, and inherited * from its superclass. Returns an empty array if there are none. */ static public Annotation[] getAnnotations (Class c) { java.lang.annotation.Annotation[] annotations = c.getAnnotations(); Annotation[] result = new Annotation[annotations.length]; for (int i = 0; i < annotations.length; i++) { result[i] = new Annotation(annotations[i]); } return result; }
/** Returns an array of {@link Annotation} objects reflecting all annotations declared by the supplied class, and inherited * from its superclass. Returns an empty array if there are none. */ static public Annotation[] getAnnotations (Class c) { java.lang.annotation.Annotation[] annotations = c.getAnnotations(); Annotation[] result = new Annotation[annotations.length]; for (int i = 0; i < annotations.length; i++) { result[i] = new Annotation(annotations[i]); } return result; }
@Override public Boolean load(Class<? extends Annotation> annotationType) { for (Annotation annotation : annotationType.getAnnotations()) { if (annotationTypes.contains(annotation.annotationType())) { return true; } } return false; } };
private boolean isEjbComponent(Class<?> component) { for (Annotation a : component.getAnnotations()) { if (EjbComponentAnnotations.contains(a.annotationType().getName())) { return true; } } return false; }
/** * Returns {@code true} if type is a Kotlin class. */ public static boolean isKotlinClass(final Class type) { final Annotation[] annotations = type.getAnnotations(); for (Annotation annotation : annotations) { if (annotation.annotationType().getName().equals("kotlin.Metadata")) { return true; } } return false; }
/** * Create a <code>Description</code> named after <code>testClass</code> * * @param testClass A {@link Class} containing tests * @return a <code>Description</code> of <code>testClass</code> */ public static Description createSuiteDescription(Class<?> testClass) { return new Description(testClass, testClass.getName(), testClass.getAnnotations()); }
/** * Create a <code>Description</code> named after <code>testClass</code> * * @param testClass A {@link Class} containing tests * @return a <code>Description</code> of <code>testClass</code> */ public static Description createSuiteDescription(Class<?> testClass) { return new Description(testClass, testClass.getName(), testClass.getAnnotations()); }
protected Annotation[] classAnnotations() { return testClass.getJavaClass().getAnnotations(); }
protected Annotation[] classAnnotations() { return fTestClass.getJavaClass().getAnnotations(); }
private <T extends Annotation> T findDeepAnnotation( Annotation[] annotations, Class<T> annotationType, int depth) { if (depth == 0) { return null; } for (Annotation each : annotations) { if (annotationType.isInstance(each)) { return annotationType.cast(each); } Annotation candidate = findDeepAnnotation(each.annotationType() .getAnnotations(), annotationType, depth - 1); if (candidate != null) { return annotationType.cast(candidate); } } return null; }
/** Returns the scope annotation on {@code type}, or null if none is specified. */ public static Class<? extends Annotation> findScopeAnnotation( Errors errors, Class<?> implementation) { return findScopeAnnotation(errors, implementation.getAnnotations()); }
private void recursivelyCollectMetaAnnotations(Set<Annotation> visited, Annotation annotation) { Class<? extends Annotation> annotationType = annotation.annotationType(); String annotationName = annotationType.getName(); if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) && visited.add(annotation)) { try { // Only do attribute scanning for public annotations; we'd run into // IllegalAccessExceptions otherwise, and we don't want to mess with // accessibility in a SecurityManager environment. if (Modifier.isPublic(annotationType.getModifiers())) { this.attributesMap.add(annotationName, AnnotationUtils.getAnnotationAttributes(annotation, false, true)); } for (Annotation metaMetaAnnotation : annotationType.getAnnotations()) { recursivelyCollectMetaAnnotations(visited, metaMetaAnnotation); } } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("Failed to introspect meta-annotations on " + annotation + ": " + ex); } } } }
Annotation[] metaAnnotations = annotationClass.getAnnotations(); if (!ObjectUtils.isEmpty(metaAnnotations)) { Set<Annotation> visited = new LinkedHashSet<>();
/** * Factory method to obtain a {@link SourceClass} from a {@link Class}. */ SourceClass asSourceClass(@Nullable Class<?> classType) throws IOException { if (classType == null) { return new SourceClass(Object.class); } try { // Sanity test that we can reflectively read annotations, // including Class attributes; if not -> fall back to ASM for (Annotation ann : classType.getAnnotations()) { AnnotationUtils.validateAnnotation(ann); } return new SourceClass(classType); } catch (Throwable ex) { // Enforce ASM via class name resolution return asSourceClass(classType.getName()); } }