Deprecate StandardMetadata constructors

Deprecate the public `StandardMetadata` constructors to make it clearer
that these classes should not be instantiated directly. A new
`AnnotationMetadata.introspect` factory method has been added which
can now be used to obtain instances.

This change will allow use to make the constructors package private
and drop the `nestedAnnotationsAsMap` parameter in a future release.

Closes gh-22906
This commit is contained in:
Phillip Webb
2019-05-06 09:46:11 -07:00
committed by Juergen Hoeller
parent 7fbf3f97cd
commit 7031964e49
12 changed files with 53 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,6 @@ import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.core.io.DescriptiveResource;
import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -104,7 +103,7 @@ final class ConfigurationClass {
*/
public ConfigurationClass(Class<?> clazz, String beanName) {
Assert.notNull(beanName, "Bean name must not be null");
this.metadata = new StandardAnnotationMetadata(clazz, true);
this.metadata = AnnotationMetadata.introspect(clazz);
this.resource = new DescriptiveResource(clazz.getName());
this.beanName = beanName;
}
@@ -118,7 +117,7 @@ final class ConfigurationClass {
* @since 3.1.1
*/
public ConfigurationClass(Class<?> clazz, @Nullable ConfigurationClass importedBy) {
this.metadata = new StandardAnnotationMetadata(clazz, true);
this.metadata = AnnotationMetadata.introspect(clazz);
this.resource = new DescriptiveResource(clazz.getName());
this.importedBy.add(importedBy);
}

View File

@@ -913,7 +913,7 @@ class ConfigurationClassParser {
public SourceClass(Object source) {
this.source = source;
if (source instanceof Class) {
this.metadata = new StandardAnnotationMetadata((Class<?>) source, true);
this.metadata = AnnotationMetadata.introspect((Class<?>) source);
}
else {
this.metadata = ((MetadataReader) source).getAnnotationMetadata();

View File

@@ -36,7 +36,6 @@ import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.lang.Nullable;
@@ -106,7 +105,7 @@ abstract class ConfigurationClassUtils {
EventListenerFactory.class.isAssignableFrom(beanClass)) {
return false;
}
metadata = new StandardAnnotationMetadata(beanClass, true);
metadata = AnnotationMetadata.introspect(beanClass);
}
else {
try {