org.springframework.core.annotation.MergedAnnotations Java Examples
The following examples show how to use
org.springframework.core.annotation.MergedAnnotations.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModifiedClassPathRunner.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
private URL[] processUrls(URL[] urls, Class<?> testClass) throws Exception { MergedAnnotations annotations = MergedAnnotations.from(testClass, SearchStrategy.TYPE_HIERARCHY); ClassPathEntryFilter filter = new ClassPathEntryFilter( annotations.get(ClassPathExclusions.class)); List<URL> processedUrls = new ArrayList<>(); List<URL> additionalUrls = getAdditionalUrls( annotations.get(ClassPathOverrides.class)); processedUrls.addAll(additionalUrls); for (URL url : urls) { if (!filter.isExcluded(url)) { processedUrls.add(url); } } return processedUrls.toArray(new URL[0]); }
Example #2
Source File: AnnotationJmxAttributeSource.java From spring-analysis-note with MIT License | 6 votes |
@Override @Nullable public org.springframework.jmx.export.metadata.ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException { MergedAnnotation<ManagedAttribute> ann = MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE) .get(ManagedAttribute.class).withNonMergedAttributes(); if (!ann.isPresent()) { return null; } org.springframework.jmx.export.metadata.ManagedAttribute bean = new org.springframework.jmx.export.metadata.ManagedAttribute(); Map<String, Object> map = ann.asMap(); MutablePropertyValues pvs = new MutablePropertyValues(map); pvs.removePropertyValue("defaultValue"); PropertyAccessorFactory.forBeanPropertyAccess(bean).setPropertyValues(pvs); String defaultValue = (String) map.get("defaultValue"); if (defaultValue.length() > 0) { bean.setDefaultValue(defaultValue); } return bean; }
Example #3
Source File: ReactiveDataNeo4jTestContextBootstrapper.java From sdn-rx with Apache License 2.0 | 5 votes |
@Override protected String[] getProperties(Class<?> testClass) { String[] properties = MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS) .get(ReactiveDataNeo4jTest.class) .getValue("properties", String[].class).orElseGet(() -> new String[0]); String[] finalProperties = new String[properties.length + 1]; System.arraycopy(properties, 0, finalProperties, 0, properties.length); finalProperties[finalProperties.length - 1] = "spring.data.neo4j.repositories.type=reactive"; return finalProperties; }
Example #4
Source File: AutowiredAnnotationBeanPostProcessor.java From spring-analysis-note with MIT License | 5 votes |
@Nullable private MergedAnnotation<?> findAutowiredAnnotation(AccessibleObject ao) { MergedAnnotations annotations = MergedAnnotations.from(ao, SearchStrategy.INHERITED_ANNOTATIONS); for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) { MergedAnnotation<?> annotation = annotations.get(type); if (annotation.isPresent()) { return annotation; } } return null; }
Example #5
Source File: RequestMappingHandlerMapping.java From spring-analysis-note with MIT License | 5 votes |
private void updateConsumesCondition(RequestMappingInfo info, Method method) { ConsumesRequestCondition condition = info.getConsumesCondition(); if (!condition.isEmpty()) { for (Parameter parameter : method.getParameters()) { MergedAnnotation<RequestBody> annot = MergedAnnotations.from(parameter).get(RequestBody.class); if (annot.isPresent()) { condition.setBodyRequired(annot.getBoolean("required")); break; } } } }
Example #6
Source File: AnnotationMetadata.java From spring-analysis-note with MIT License | 5 votes |
/** * Get the fully qualified class names of all meta-annotation types that * are <em>present</em> on the given annotation type on the underlying class. * @param annotationName the fully qualified class name of the meta-annotation * type to look for * @return the meta-annotation type names, or an empty set if none found */ default Set<String> getMetaAnnotationTypes(String annotationName) { MergedAnnotation<?> annotation = getAnnotations().get(annotationName, MergedAnnotation::isDirectlyPresent); if (!annotation.isPresent()) { return Collections.emptySet(); } return MergedAnnotations.from(annotation.getType(), SearchStrategy.INHERITED_ANNOTATIONS).stream() .map(mergedAnnotation -> mergedAnnotation.getType().getName()) .collect(Collectors.toCollection(LinkedHashSet::new)); }
Example #7
Source File: SimpleMethodMetadata.java From spring-analysis-note with MIT License | 5 votes |
public SimpleMethodMetadata(String methodName, int access, String declaringClassName, String returnTypeName, MergedAnnotations annotations) { this.methodName = methodName; this.access = access; this.declaringClassName = declaringClassName; this.returnTypeName = returnTypeName; this.annotations = annotations; }
Example #8
Source File: SimpleAnnotationMetadataReadingVisitor.java From spring-analysis-note with MIT License | 5 votes |
@Override public void visitEnd() { String[] memberClassNames = StringUtils.toStringArray(this.memberClassNames); MethodMetadata[] annotatedMethods = this.annotatedMethods.toArray(new MethodMetadata[0]); MergedAnnotations annotations = MergedAnnotations.of(this.annotations); this.metadata = new SimpleAnnotationMetadata(this.className, this.access, this.enclosingClassName, this.superClassName, this.independentInnerClass, this.interfaceNames, memberClassNames, annotatedMethods, annotations); }
Example #9
Source File: SimpleAnnotationMetadata.java From spring-analysis-note with MIT License | 5 votes |
SimpleAnnotationMetadata(String className, int access, @Nullable String enclosingClassName, @Nullable String superClassName, boolean independentInnerClass, String[] interfaceNames, String[] memberClassNames, MethodMetadata[] annotatedMethods, MergedAnnotations annotations) { this.className = className; this.access = access; this.enclosingClassName = enclosingClassName; this.superClassName = superClassName; this.independentInnerClass = independentInnerClass; this.interfaceNames = interfaceNames; this.memberClassNames = memberClassNames; this.annotatedMethods = annotatedMethods; this.annotations = annotations; }
Example #10
Source File: RequestMappingHandlerMapping.java From spring-analysis-note with MIT License | 5 votes |
private void updateConsumesCondition(RequestMappingInfo info, Method method) { ConsumesRequestCondition condition = info.getConsumesCondition(); if (!condition.isEmpty()) { for (Parameter parameter : method.getParameters()) { MergedAnnotation<RequestBody> annot = MergedAnnotations.from(parameter).get(RequestBody.class); if (annot.isPresent()) { condition.setBodyRequired(annot.getBoolean("required")); break; } } } }
Example #11
Source File: AnnotationJmxAttributeSource.java From spring-analysis-note with MIT License | 5 votes |
private static List<MergedAnnotation<? extends Annotation>> getRepeatableAnnotations( AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType, Class<? extends Annotation> containerAnnotationType) { return MergedAnnotations.from(annotatedElement, SearchStrategy.EXHAUSTIVE, RepeatableContainers.of(annotationType, containerAnnotationType), AnnotationFilter.PLAIN) .stream(annotationType) .filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex)) .map(MergedAnnotation::withNonMergedAttributes) .collect(Collectors.toList()); }
Example #12
Source File: AnnotationJmxAttributeSource.java From spring-analysis-note with MIT License | 5 votes |
@Override @Nullable public org.springframework.jmx.export.metadata.ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException { MergedAnnotation<ManagedOperation> ann = MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE) .get(ManagedOperation.class).withNonMergedAttributes(); return copyPropertiesToBean(ann, org.springframework.jmx.export.metadata.ManagedOperation.class); }
Example #13
Source File: AnnotationJmxAttributeSource.java From spring-analysis-note with MIT License | 5 votes |
@Override @Nullable public org.springframework.jmx.export.metadata.ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException { MergedAnnotation<ManagedMetric> ann = MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE) .get(ManagedMetric.class).withNonMergedAttributes(); return copyPropertiesToBean(ann, org.springframework.jmx.export.metadata.ManagedMetric.class); }
Example #14
Source File: AnnotationJmxAttributeSource.java From spring-analysis-note with MIT License | 5 votes |
@Override @Nullable public org.springframework.jmx.export.metadata.ManagedResource getManagedResource(Class<?> beanClass) throws InvalidMetadataException { MergedAnnotation<ManagedResource> ann = MergedAnnotations.from(beanClass, SearchStrategy.EXHAUSTIVE) .get(ManagedResource.class).withNonMergedAttributes(); if (!ann.isPresent()) { return null; } Class<?> declaringClass = (Class<?>) ann.getSource(); Class<?> target = (declaringClass != null && !declaringClass.isInterface() ? declaringClass : beanClass); if (!Modifier.isPublic(target.getModifiers())) { throw new InvalidMetadataException("@ManagedResource class '" + target.getName() + "' must be public"); } org.springframework.jmx.export.metadata.ManagedResource bean = new org.springframework.jmx.export.metadata.ManagedResource(); Map<String, Object> map = ann.asMap(); List<PropertyValue> list = new ArrayList<>(map.size()); map.forEach((attrName, attrValue) -> { if (!"value".equals(attrName)) { Object value = attrValue; if (this.embeddedValueResolver != null && value instanceof String) { value = this.embeddedValueResolver.resolveStringValue((String) value); } list.add(new PropertyValue(attrName, value)); } }); PropertyAccessorFactory.forBeanPropertyAccess(bean).setPropertyValues(new MutablePropertyValues(list)); return bean; }
Example #15
Source File: StandardAnnotationMetadata.java From spring-analysis-note with MIT License | 4 votes |
@Override public MergedAnnotations getAnnotations() { return this.mergedAnnotations; }
Example #16
Source File: StandardMethodMetadata.java From spring-analysis-note with MIT License | 4 votes |
@Override public MergedAnnotations getAnnotations() { return this.mergedAnnotations; }
Example #17
Source File: SimpleAnnotationMetadata.java From spring-analysis-note with MIT License | 4 votes |
@Override public MergedAnnotations getAnnotations() { return this.annotations; }
Example #18
Source File: AnnotationMetadataReadingVisitor.java From spring-analysis-note with MIT License | 4 votes |
@Override public MergedAnnotations getAnnotations() { throw new UnsupportedOperationException(); }
Example #19
Source File: MethodMetadataReadingVisitor.java From spring-analysis-note with MIT License | 4 votes |
@Override public MergedAnnotations getAnnotations() { throw new UnsupportedOperationException(); }
Example #20
Source File: SimpleMethodMetadata.java From spring-analysis-note with MIT License | 4 votes |
@Override public MergedAnnotations getAnnotations() { return this.annotations; }
Example #21
Source File: ConditionalAnnotationMetadata.java From mongodb-aggregate-query-support with Apache License 2.0 | 4 votes |
@Override @NonNull public MergedAnnotations getAnnotations() { throw new UnsupportedOperationException("Not yet supported"); }
Example #22
Source File: DataNeo4jTestContextBootstrapper.java From sdn-rx with Apache License 2.0 | 4 votes |
@Override protected String[] getProperties(Class<?> testClass) { return MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS).get(DataNeo4jTest.class) .getValue("properties", String[].class).orElse(null); }
Example #23
Source File: StandardMethodMetadata.java From spring-analysis-note with MIT License | 3 votes |
/** * Create a new StandardMethodMetadata wrapper for the given Method, * 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 java.lang.annotation.Annotation} instances. * @param introspectedMethod the Method 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 * @deprecated since 5.2 in favor of obtaining instances via {@link AnnotationMetadata} */ @Deprecated public StandardMethodMetadata(Method introspectedMethod, boolean nestedAnnotationsAsMap) { Assert.notNull(introspectedMethod, "Method must not be null"); this.introspectedMethod = introspectedMethod; this.nestedAnnotationsAsMap = nestedAnnotationsAsMap; this.mergedAnnotations = MergedAnnotations.from(introspectedMethod, SearchStrategy.DIRECT, RepeatableContainers.none(), AnnotationFilter.PLAIN); }
Example #24
Source File: StandardAnnotationMetadata.java From spring-analysis-note with MIT License | 3 votes |
/** * 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 * @deprecated since 5.2 in favor of the factory method {@link AnnotationMetadata#introspect(Class)}. * Use {@link MergedAnnotation#asMap(org.springframework.core.annotation.MergedAnnotation.Adapt...) MergedAnnotation.asMap} * from {@link #getAnnotations()} rather than {@link #getAnnotationAttributes(String)} * if {@code nestedAnnotationsAsMap} is {@code false} */ @Deprecated public StandardAnnotationMetadata(Class<?> introspectedClass, boolean nestedAnnotationsAsMap) { super(introspectedClass); this.mergedAnnotations = MergedAnnotations.from(introspectedClass, SearchStrategy.DIRECT, RepeatableContainers.none(), AnnotationFilter.NONE); this.nestedAnnotationsAsMap = nestedAnnotationsAsMap; }
Example #25
Source File: AnnotatedTypeMetadata.java From spring-analysis-note with MIT License | 2 votes |
/** * Return annotation details based on the direct annotations of the * underlying element. * @return merged annotations based on the direct annotations */ MergedAnnotations getAnnotations();