Java Code Examples for org.springframework.core.annotation.MergedAnnotations

The following examples show how to use org.springframework.core.annotation.MergedAnnotations. These examples are extracted from open source projects. 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
@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 2
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 3
@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
@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 5
@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 6
@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 7
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 8
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 9
Source Project: spring-analysis-note   Source File: SimpleAnnotationMetadata.java    License: MIT License 5 votes vote down vote up
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
@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 11
Source Project: spring-analysis-note   Source File: SimpleMethodMetadata.java    License: MIT License 5 votes vote down vote up
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 12
Source Project: spring-analysis-note   Source File: AnnotationMetadata.java    License: MIT License 5 votes vote down vote up
/**
 * 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 13
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 14
@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 15
Source Project: sdn-rx   Source File: DataNeo4jTestContextBootstrapper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected String[] getProperties(Class<?> testClass) {
	return MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS).get(DataNeo4jTest.class)
		.getValue("properties", String[].class).orElse(null);
}
 
Example 16
Source Project: spring-analysis-note   Source File: StandardAnnotationMetadata.java    License: MIT License 4 votes vote down vote up
@Override
public MergedAnnotations getAnnotations() {
	return this.mergedAnnotations;
}
 
Example 17
Source Project: spring-analysis-note   Source File: StandardMethodMetadata.java    License: MIT License 4 votes vote down vote up
@Override
public MergedAnnotations getAnnotations() {
	return this.mergedAnnotations;
}
 
Example 18
Source Project: spring-analysis-note   Source File: SimpleAnnotationMetadata.java    License: MIT License 4 votes vote down vote up
@Override
public MergedAnnotations getAnnotations() {
	return this.annotations;
}
 
Example 19
@Override
public MergedAnnotations getAnnotations() {
	throw new UnsupportedOperationException();
}
 
Example 20
@Override
public MergedAnnotations getAnnotations() {
	throw new UnsupportedOperationException();
}
 
Example 21
Source Project: spring-analysis-note   Source File: SimpleMethodMetadata.java    License: MIT License 4 votes vote down vote up
@Override
public MergedAnnotations getAnnotations() {
	return this.annotations;
}
 
Example 22
@Override
@NonNull
public MergedAnnotations getAnnotations() {
  throw new UnsupportedOperationException("Not yet supported");
}
 
Example 23
Source Project: spring-analysis-note   Source File: StandardAnnotationMetadata.java    License: MIT License 3 votes vote down vote up
/**
 * 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 24
Source Project: spring-analysis-note   Source File: StandardMethodMetadata.java    License: MIT License 3 votes vote down vote up
/**
 * 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 25
Source Project: spring-analysis-note   Source File: AnnotatedTypeMetadata.java    License: MIT License 2 votes vote down vote up
/**
 * Return annotation details based on the direct annotations of the
 * underlying element.
 * @return merged annotations based on the direct annotations
 */
MergedAnnotations getAnnotations();