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:
committed by
Juergen Hoeller
parent
7fbf3f97cd
commit
7031964e49
@@ -55,7 +55,7 @@ public class AnnotationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void standardAnnotationMetadata() {
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(AnnotatedComponent.class, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(AnnotatedComponent.class);
|
||||
doTestAnnotationInfo(metadata);
|
||||
doTestMethodAnnotationInfo(metadata);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class AnnotationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void standardAnnotationMetadataForSubclass() {
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(AnnotatedComponentSubClass.class, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(AnnotatedComponentSubClass.class);
|
||||
doTestSubClassAnnotationInfo(metadata);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class AnnotationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void standardAnnotationMetadataForInterface() {
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(AnnotationMetadata.class, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(AnnotationMetadata.class);
|
||||
doTestMetadataForInterfaceClass(metadata);
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public class AnnotationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void standardAnnotationMetadataForAnnotation() {
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(Component.class, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(Component.class);
|
||||
doTestMetadataForAnnotationClass(metadata);
|
||||
}
|
||||
|
||||
@@ -174,6 +174,7 @@ public class AnnotationMetadataTests {
|
||||
* 'true' as is done in the main test above.
|
||||
*/
|
||||
@Test
|
||||
@Deprecated
|
||||
public void standardAnnotationMetadata_nestedAnnotationsAsMap_false() {
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(AnnotatedComponent.class);
|
||||
AnnotationAttributes specialAttrs = (AnnotationAttributes) metadata.getAnnotationAttributes(SpecialAttr.class.getName());
|
||||
@@ -182,6 +183,7 @@ public class AnnotationMetadataTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void metaAnnotationOverridesUsingStandardAnnotationMetadata() {
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(ComposedConfigurationWithAttributeOverridesClass.class);
|
||||
assertMetaAnnotationOverrides(metadata);
|
||||
@@ -209,7 +211,7 @@ public class AnnotationMetadataTests {
|
||||
|
||||
@Test // SPR-11649
|
||||
public void multipleAnnotationsWithIdenticalAttributeNamesUsingStandardAnnotationMetadata() {
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(NamedAnnotationsClass.class);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(NamedAnnotationsClass.class);
|
||||
assertMultipleAnnotationsWithIdenticalAttributeNames(metadata);
|
||||
}
|
||||
|
||||
@@ -223,7 +225,7 @@ public class AnnotationMetadataTests {
|
||||
|
||||
@Test // SPR-11649
|
||||
public void composedAnnotationWithMetaAnnotationsWithIdenticalAttributeNamesUsingStandardAnnotationMetadata() {
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(NamedComposedAnnotationClass.class);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(NamedComposedAnnotationClass.class);
|
||||
assertMultipleAnnotationsWithIdenticalAttributeNames(metadata);
|
||||
}
|
||||
|
||||
@@ -237,7 +239,7 @@ public class AnnotationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void inheritedAnnotationWithMetaAnnotationsWithIdenticalAttributeNamesUsingStandardAnnotationMetadata() {
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(NamedComposedAnnotationExtended.class);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(NamedComposedAnnotationExtended.class);
|
||||
assertFalse(metadata.hasAnnotation(NamedComposedAnnotation.class.getName()));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ package org.springframework.core.type;
|
||||
public class StandardAnnotationMetadataTests extends AbstractAnnotationMetadataTests {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected AnnotationMetadata get(Class<?> source) {
|
||||
return new StandardAnnotationMetadata(source);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -25,6 +25,7 @@ public class StandardClassMetadataMemberClassTests
|
||||
extends AbstractClassMetadataMemberClassTests {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public ClassMetadata getClassMetadataFor(Class<?> clazz) {
|
||||
return new StandardClassMetadata(clazz);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class StandardMethodMetadataTests extends AbstractMethodMetadataTests {
|
||||
|
||||
@Override
|
||||
protected AnnotationMetadata get(Class<?> source) {
|
||||
return new StandardAnnotationMetadata(source);
|
||||
return AnnotationMetadata.introspect(source);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user