Start migration annotation utility methods

Create internal variants of the existing `AnnotationUtils` and
`AnnotatedElementUtils` classes and migrate the existing classes to
use them.

The internal variants will be used to check that the same results are
given as we migrate the utils methods to use the new `MergedAnnotations`
API.

See gh-22562
This commit is contained in:
Phillip Webb 2018-11-21 21:35:48 -08:00 committed by Juergen Hoeller
parent 4972d85ae0
commit b91ccf038f
10 changed files with 4141 additions and 2676 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -64,7 +64,7 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor<S> implements Anno
this.annotationType = annotationType; this.annotationType = annotationType;
this.annotatedElement = annotatedElement; this.annotatedElement = annotatedElement;
this.source = source; this.source = source;
this.attributeAliasMap = AnnotationUtils.getAttributeAliasMap(annotationType); this.attributeAliasMap = InternalAnnotationUtils.getAttributeAliasMap(annotationType);
} }

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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -91,9 +91,9 @@ class MapAnnotationAttributeExtractor extends AbstractAliasAwareAnnotationAttrib
Map<String, Object> originalAttributes, Class<? extends Annotation> annotationType) { Map<String, Object> originalAttributes, Class<? extends Annotation> annotationType) {
Map<String, Object> attributes = new LinkedHashMap<>(originalAttributes); Map<String, Object> attributes = new LinkedHashMap<>(originalAttributes);
Map<String, List<String>> attributeAliasMap = AnnotationUtils.getAttributeAliasMap(annotationType); Map<String, List<String>> attributeAliasMap = InternalAnnotationUtils.getAttributeAliasMap(annotationType);
for (Method attributeMethod : AnnotationUtils.getAttributeMethods(annotationType)) { for (Method attributeMethod : InternalAnnotationUtils.getAttributeMethods(annotationType)) {
String attributeName = attributeMethod.getName(); String attributeName = attributeMethod.getName();
Object attributeValue = attributes.get(attributeName); Object attributeValue = attributes.get(attributeName);
@ -158,7 +158,7 @@ class MapAnnotationAttributeExtractor extends AbstractAliasAwareAnnotationAttrib
Class<? extends Annotation> nestedAnnotationType = Class<? extends Annotation> nestedAnnotationType =
(Class<? extends Annotation>) requiredReturnType.getComponentType(); (Class<? extends Annotation>) requiredReturnType.getComponentType();
Map<String, Object>[] maps = (Map<String, Object>[]) attributeValue; Map<String, Object>[] maps = (Map<String, Object>[]) attributeValue;
attributes.put(attributeName, AnnotationUtils.synthesizeAnnotationArray(maps, nestedAnnotationType)); attributes.put(attributeName, InternalAnnotationUtils.synthesizeAnnotationArray(maps, nestedAnnotationType));
converted = true; converted = true;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -70,10 +70,10 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
if (ReflectionUtils.isToStringMethod(method)) { if (ReflectionUtils.isToStringMethod(method)) {
return annotationToString(); return annotationToString();
} }
if (AnnotationUtils.isAnnotationTypeMethod(method)) { if (InternalAnnotationUtils.isAnnotationTypeMethod(method)) {
return annotationType(); return annotationType();
} }
if (!AnnotationUtils.isAttributeMethod(method)) { if (!InternalAnnotationUtils.isAttributeMethod(method)) {
throw new AnnotationConfigurationException(String.format( throw new AnnotationConfigurationException(String.format(
"Method [%s] is unsupported for synthesized annotation type [%s]", method, annotationType())); "Method [%s] is unsupported for synthesized annotation type [%s]", method, annotationType()));
} }
@ -97,10 +97,10 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
// Synthesize nested annotations before returning them. // Synthesize nested annotations before returning them.
if (value instanceof Annotation) { if (value instanceof Annotation) {
value = AnnotationUtils.synthesizeAnnotation((Annotation) value, this.attributeExtractor.getAnnotatedElement()); value = InternalAnnotationUtils.synthesizeAnnotation((Annotation) value, this.attributeExtractor.getAnnotatedElement());
} }
else if (value instanceof Annotation[]) { else if (value instanceof Annotation[]) {
value = AnnotationUtils.synthesizeAnnotationArray((Annotation[]) value, this.attributeExtractor.getAnnotatedElement()); value = InternalAnnotationUtils.synthesizeAnnotationArray((Annotation[]) value, this.attributeExtractor.getAnnotatedElement());
} }
this.valueCache.put(attributeName, value); this.valueCache.put(attributeName, value);
@ -161,7 +161,7 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
return false; return false;
} }
for (Method attributeMethod : AnnotationUtils.getAttributeMethods(annotationType())) { for (Method attributeMethod : InternalAnnotationUtils.getAttributeMethods(annotationType())) {
Object thisValue = getAttributeValue(attributeMethod); Object thisValue = getAttributeValue(attributeMethod);
Object otherValue = ReflectionUtils.invokeMethod(attributeMethod, other); Object otherValue = ReflectionUtils.invokeMethod(attributeMethod, other);
if (!ObjectUtils.nullSafeEquals(thisValue, otherValue)) { if (!ObjectUtils.nullSafeEquals(thisValue, otherValue)) {
@ -178,7 +178,7 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
private int annotationHashCode() { private int annotationHashCode() {
int result = 0; int result = 0;
for (Method attributeMethod : AnnotationUtils.getAttributeMethods(annotationType())) { for (Method attributeMethod : InternalAnnotationUtils.getAttributeMethods(annotationType())) {
Object value = getAttributeValue(attributeMethod); Object value = getAttributeValue(attributeMethod);
int hashCode; int hashCode;
if (value.getClass().isArray()) { if (value.getClass().isArray()) {
@ -236,7 +236,7 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
private String annotationToString() { private String annotationToString() {
StringBuilder sb = new StringBuilder("@").append(annotationType().getName()).append("("); StringBuilder sb = new StringBuilder("@").append(annotationType().getName()).append("(");
Iterator<Method> iterator = AnnotationUtils.getAttributeMethods(annotationType()).iterator(); Iterator<Method> iterator = InternalAnnotationUtils.getAttributeMethods(annotationType()).iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Method attributeMethod = iterator.next(); Method attributeMethod = iterator.next();
sb.append(attributeMethod.getName()); sb.append(attributeMethod.getName());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -104,7 +104,6 @@ public class SynthesizingMethodParameter extends MethodParameter {
return AnnotationUtils.synthesizeAnnotationArray(annotations, getAnnotatedElement()); return AnnotationUtils.synthesizeAnnotationArray(annotations, getAnnotatedElement());
} }
@Override @Override
public SynthesizingMethodParameter clone() { public SynthesizingMethodParameter clone() {
return new SynthesizingMethodParameter(this); return new SynthesizingMethodParameter(this);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -732,19 +732,19 @@ public class AnnotationUtilsTests {
public void getAttributeOverrideNameFromWrongTargetAnnotation() throws Exception { public void getAttributeOverrideNameFromWrongTargetAnnotation() throws Exception {
Method attribute = AliasedComposedContextConfig.class.getDeclaredMethod("xmlConfigFile"); Method attribute = AliasedComposedContextConfig.class.getDeclaredMethod("xmlConfigFile");
assertThat("xmlConfigFile is not an alias for @Component.", assertThat("xmlConfigFile is not an alias for @Component.",
getAttributeOverrideName(attribute, Component.class), is(nullValue())); InternalAnnotationUtils.getAttributeOverrideName(attribute, Component.class), is(nullValue()));
} }
@Test @Test
public void getAttributeOverrideNameForNonAliasedAttribute() throws Exception { public void getAttributeOverrideNameForNonAliasedAttribute() throws Exception {
Method nonAliasedAttribute = ImplicitAliasesContextConfig.class.getDeclaredMethod("nonAliasedAttribute"); Method nonAliasedAttribute = ImplicitAliasesContextConfig.class.getDeclaredMethod("nonAliasedAttribute");
assertThat(getAttributeOverrideName(nonAliasedAttribute, ContextConfig.class), is(nullValue())); assertThat(InternalAnnotationUtils.getAttributeOverrideName(nonAliasedAttribute, ContextConfig.class), is(nullValue()));
} }
@Test @Test
public void getAttributeOverrideNameFromAliasedComposedAnnotation() throws Exception { public void getAttributeOverrideNameFromAliasedComposedAnnotation() throws Exception {
Method attribute = AliasedComposedContextConfig.class.getDeclaredMethod("xmlConfigFile"); Method attribute = AliasedComposedContextConfig.class.getDeclaredMethod("xmlConfigFile");
assertEquals("location", getAttributeOverrideName(attribute, ContextConfig.class)); assertEquals("location", InternalAnnotationUtils.getAttributeOverrideName(attribute, ContextConfig.class));
} }
@Test @Test
@ -757,17 +757,17 @@ public class AnnotationUtilsTests {
Method location3 = ImplicitAliasesContextConfig.class.getDeclaredMethod("location3"); Method location3 = ImplicitAliasesContextConfig.class.getDeclaredMethod("location3");
// Meta-annotation attribute overrides // Meta-annotation attribute overrides
assertEquals("location", getAttributeOverrideName(xmlFile, ContextConfig.class)); assertEquals("location", InternalAnnotationUtils.getAttributeOverrideName(xmlFile, ContextConfig.class));
assertEquals("location", getAttributeOverrideName(groovyScript, ContextConfig.class)); assertEquals("location", InternalAnnotationUtils.getAttributeOverrideName(groovyScript, ContextConfig.class));
assertEquals("location", getAttributeOverrideName(value, ContextConfig.class)); assertEquals("location", InternalAnnotationUtils.getAttributeOverrideName(value, ContextConfig.class));
// Implicit aliases // Implicit aliases
assertThat(getAttributeAliasNames(xmlFile), containsInAnyOrder("value", "groovyScript", "location1", "location2", "location3")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(xmlFile), containsInAnyOrder("value", "groovyScript", "location1", "location2", "location3"));
assertThat(getAttributeAliasNames(groovyScript), containsInAnyOrder("value", "xmlFile", "location1", "location2", "location3")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(groovyScript), containsInAnyOrder("value", "xmlFile", "location1", "location2", "location3"));
assertThat(getAttributeAliasNames(value), containsInAnyOrder("xmlFile", "groovyScript", "location1", "location2", "location3")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(value), containsInAnyOrder("xmlFile", "groovyScript", "location1", "location2", "location3"));
assertThat(getAttributeAliasNames(location1), containsInAnyOrder("xmlFile", "groovyScript", "value", "location2", "location3")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(location1), containsInAnyOrder("xmlFile", "groovyScript", "value", "location2", "location3"));
assertThat(getAttributeAliasNames(location2), containsInAnyOrder("xmlFile", "groovyScript", "value", "location1", "location3")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(location2), containsInAnyOrder("xmlFile", "groovyScript", "value", "location1", "location3"));
assertThat(getAttributeAliasNames(location3), containsInAnyOrder("xmlFile", "groovyScript", "value", "location1", "location2")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(location3), containsInAnyOrder("xmlFile", "groovyScript", "value", "location1", "location2"));
} }
@Test @Test
@ -776,12 +776,12 @@ public class AnnotationUtilsTests {
Method groovyScript = ImplicitAliasesForAliasPairContextConfig.class.getDeclaredMethod("groovyScript"); Method groovyScript = ImplicitAliasesForAliasPairContextConfig.class.getDeclaredMethod("groovyScript");
// Meta-annotation attribute overrides // Meta-annotation attribute overrides
assertEquals("location", getAttributeOverrideName(xmlFile, ContextConfig.class)); assertEquals("location", InternalAnnotationUtils.getAttributeOverrideName(xmlFile, ContextConfig.class));
assertEquals("value", getAttributeOverrideName(groovyScript, ContextConfig.class)); assertEquals("value", InternalAnnotationUtils.getAttributeOverrideName(groovyScript, ContextConfig.class));
// Implicit aliases // Implicit aliases
assertThat(getAttributeAliasNames(xmlFile), containsInAnyOrder("groovyScript")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(xmlFile), containsInAnyOrder("groovyScript"));
assertThat(getAttributeAliasNames(groovyScript), containsInAnyOrder("xmlFile")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(groovyScript), containsInAnyOrder("xmlFile"));
} }
@Test @Test
@ -793,14 +793,14 @@ public class AnnotationUtilsTests {
Method xmlFile = ImplicitAliasesWithImpliedAliasNamesOmittedContextConfig.class.getDeclaredMethod("xmlFile"); Method xmlFile = ImplicitAliasesWithImpliedAliasNamesOmittedContextConfig.class.getDeclaredMethod("xmlFile");
// Meta-annotation attribute overrides // Meta-annotation attribute overrides
assertEquals("value", getAttributeOverrideName(value, ContextConfig.class)); assertEquals("value", InternalAnnotationUtils.getAttributeOverrideName(value, ContextConfig.class));
assertEquals("location", getAttributeOverrideName(location, ContextConfig.class)); assertEquals("location", InternalAnnotationUtils.getAttributeOverrideName(location, ContextConfig.class));
assertEquals("location", getAttributeOverrideName(xmlFile, ContextConfig.class)); assertEquals("location", InternalAnnotationUtils.getAttributeOverrideName(xmlFile, ContextConfig.class));
// Implicit aliases // Implicit aliases
assertThat(getAttributeAliasNames(value), containsInAnyOrder("location", "xmlFile")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(value), containsInAnyOrder("location", "xmlFile"));
assertThat(getAttributeAliasNames(location), containsInAnyOrder("value", "xmlFile")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(location), containsInAnyOrder("value", "xmlFile"));
assertThat(getAttributeAliasNames(xmlFile), containsInAnyOrder("value", "location")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(xmlFile), containsInAnyOrder("value", "location"));
} }
@Test @Test
@ -809,16 +809,16 @@ public class AnnotationUtilsTests {
Method groovy = TransitiveImplicitAliasesContextConfig.class.getDeclaredMethod("groovy"); Method groovy = TransitiveImplicitAliasesContextConfig.class.getDeclaredMethod("groovy");
// Explicit meta-annotation attribute overrides // Explicit meta-annotation attribute overrides
assertEquals("xmlFile", getAttributeOverrideName(xml, ImplicitAliasesContextConfig.class)); assertEquals("xmlFile", InternalAnnotationUtils.getAttributeOverrideName(xml, ImplicitAliasesContextConfig.class));
assertEquals("groovyScript", getAttributeOverrideName(groovy, ImplicitAliasesContextConfig.class)); assertEquals("groovyScript", InternalAnnotationUtils.getAttributeOverrideName(groovy, ImplicitAliasesContextConfig.class));
// Transitive meta-annotation attribute overrides // Transitive meta-annotation attribute overrides
assertEquals("location", getAttributeOverrideName(xml, ContextConfig.class)); assertEquals("location", InternalAnnotationUtils.getAttributeOverrideName(xml, ContextConfig.class));
assertEquals("location", getAttributeOverrideName(groovy, ContextConfig.class)); assertEquals("location", InternalAnnotationUtils.getAttributeOverrideName(groovy, ContextConfig.class));
// Transitive implicit aliases // Transitive implicit aliases
assertThat(getAttributeAliasNames(xml), containsInAnyOrder("groovy")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(xml), containsInAnyOrder("groovy"));
assertThat(getAttributeAliasNames(groovy), containsInAnyOrder("xml")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(groovy), containsInAnyOrder("xml"));
} }
@Test @Test
@ -827,12 +827,12 @@ public class AnnotationUtilsTests {
Method groovy = TransitiveImplicitAliasesForAliasPairContextConfig.class.getDeclaredMethod("groovy"); Method groovy = TransitiveImplicitAliasesForAliasPairContextConfig.class.getDeclaredMethod("groovy");
// Explicit meta-annotation attribute overrides // Explicit meta-annotation attribute overrides
assertEquals("xmlFile", getAttributeOverrideName(xml, ImplicitAliasesForAliasPairContextConfig.class)); assertEquals("xmlFile", InternalAnnotationUtils.getAttributeOverrideName(xml, ImplicitAliasesForAliasPairContextConfig.class));
assertEquals("groovyScript", getAttributeOverrideName(groovy, ImplicitAliasesForAliasPairContextConfig.class)); assertEquals("groovyScript", InternalAnnotationUtils.getAttributeOverrideName(groovy, ImplicitAliasesForAliasPairContextConfig.class));
// Transitive implicit aliases // Transitive implicit aliases
assertThat(getAttributeAliasNames(xml), containsInAnyOrder("groovy")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(xml), containsInAnyOrder("groovy"));
assertThat(getAttributeAliasNames(groovy), containsInAnyOrder("xml")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(groovy), containsInAnyOrder("xml"));
} }
@Test @Test
@ -843,23 +843,23 @@ public class AnnotationUtilsTests {
Method groovy = TransitiveImplicitAliasesWithImpliedAliasNamesOmittedContextConfig.class.getDeclaredMethod("groovy"); Method groovy = TransitiveImplicitAliasesWithImpliedAliasNamesOmittedContextConfig.class.getDeclaredMethod("groovy");
// Meta-annotation attribute overrides // Meta-annotation attribute overrides
assertEquals("location", getAttributeOverrideName(xml, ContextConfig.class)); assertEquals("location", InternalAnnotationUtils.getAttributeOverrideName(xml, ContextConfig.class));
assertEquals("location", getAttributeOverrideName(groovy, ContextConfig.class)); assertEquals("location", InternalAnnotationUtils.getAttributeOverrideName(groovy, ContextConfig.class));
// Explicit meta-annotation attribute overrides // Explicit meta-annotation attribute overrides
assertEquals("xmlFile", getAttributeOverrideName(xml, ImplicitAliasesWithImpliedAliasNamesOmittedContextConfig.class)); assertEquals("xmlFile", InternalAnnotationUtils.getAttributeOverrideName(xml, ImplicitAliasesWithImpliedAliasNamesOmittedContextConfig.class));
assertEquals("location", getAttributeOverrideName(groovy, ImplicitAliasesWithImpliedAliasNamesOmittedContextConfig.class)); assertEquals("location", InternalAnnotationUtils.getAttributeOverrideName(groovy, ImplicitAliasesWithImpliedAliasNamesOmittedContextConfig.class));
// Transitive implicit aliases // Transitive implicit aliases
assertThat(getAttributeAliasNames(groovy), containsInAnyOrder("xml")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(groovy), containsInAnyOrder("xml"));
assertThat(getAttributeAliasNames(xml), containsInAnyOrder("groovy")); assertThat(InternalAnnotationUtils.getAttributeAliasNames(xml), containsInAnyOrder("groovy"));
} }
@Test @Test
public void synthesizeAnnotationWithoutAttributeAliases() throws Exception { public void synthesizeAnnotationWithoutAttributeAliases() throws Exception {
Component component = WebController.class.getAnnotation(Component.class); Component component = WebController.class.getAnnotation(Component.class);
assertNotNull(component); assertNotNull(component);
Component synthesizedComponent = synthesizeAnnotation(component); Component synthesizedComponent = InternalAnnotationUtils.synthesizeAnnotation(component);
assertNotNull(synthesizedComponent); assertNotNull(synthesizedComponent);
assertSame(component, synthesizedComponent); assertSame(component, synthesizedComponent);
assertEquals("value attribute: ", "webController", synthesizedComponent.value()); assertEquals("value attribute: ", "webController", synthesizedComponent.value());
@ -870,9 +870,9 @@ public class AnnotationUtilsTests {
Method method = WebController.class.getMethod("handleMappedWithValueAttribute"); Method method = WebController.class.getMethod("handleMappedWithValueAttribute");
WebMapping webMapping = method.getAnnotation(WebMapping.class); WebMapping webMapping = method.getAnnotation(WebMapping.class);
assertNotNull(webMapping); assertNotNull(webMapping);
WebMapping synthesizedWebMapping = synthesizeAnnotation(webMapping); WebMapping synthesizedWebMapping = InternalAnnotationUtils.synthesizeAnnotation(webMapping);
assertNotSame(webMapping, synthesizedWebMapping); assertNotSame(webMapping, synthesizedWebMapping);
WebMapping synthesizedAgainWebMapping = synthesizeAnnotation(synthesizedWebMapping); WebMapping synthesizedAgainWebMapping = InternalAnnotationUtils.synthesizeAnnotation(synthesizedWebMapping);
assertThat(synthesizedAgainWebMapping, instanceOf(SynthesizedAnnotation.class)); assertThat(synthesizedAgainWebMapping, instanceOf(SynthesizedAnnotation.class));
assertSame(synthesizedWebMapping, synthesizedAgainWebMapping); assertSame(synthesizedWebMapping, synthesizedAgainWebMapping);
@ -888,7 +888,7 @@ public class AnnotationUtilsTests {
exception.expectMessage(startsWith("@AliasFor declaration on attribute 'foo' in annotation")); exception.expectMessage(startsWith("@AliasFor declaration on attribute 'foo' in annotation"));
exception.expectMessage(containsString(AliasForWithMissingAttributeDeclaration.class.getName())); exception.expectMessage(containsString(AliasForWithMissingAttributeDeclaration.class.getName()));
exception.expectMessage(containsString("points to itself")); exception.expectMessage(containsString("points to itself"));
synthesizeAnnotation(annotation); InternalAnnotationUtils.synthesizeAnnotation(annotation);
} }
@Test @Test
@ -898,7 +898,7 @@ public class AnnotationUtilsTests {
exception.expectMessage(startsWith("In @AliasFor declared on attribute 'foo' in annotation")); exception.expectMessage(startsWith("In @AliasFor declared on attribute 'foo' in annotation"));
exception.expectMessage(containsString(AliasForWithDuplicateAttributeDeclaration.class.getName())); exception.expectMessage(containsString(AliasForWithDuplicateAttributeDeclaration.class.getName()));
exception.expectMessage(containsString("attribute 'attribute' and its alias 'value' are present with values of [baz] and [bar]")); exception.expectMessage(containsString("attribute 'attribute' and its alias 'value' are present with values of [baz] and [bar]"));
synthesizeAnnotation(annotation); InternalAnnotationUtils.synthesizeAnnotation(annotation);
} }
@Test @Test
@ -908,7 +908,7 @@ public class AnnotationUtilsTests {
exception.expectMessage(startsWith("Attribute 'foo' in")); exception.expectMessage(startsWith("Attribute 'foo' in"));
exception.expectMessage(containsString(AliasForNonexistentAttribute.class.getName())); exception.expectMessage(containsString(AliasForNonexistentAttribute.class.getName()));
exception.expectMessage(containsString("is declared as an @AliasFor nonexistent attribute 'bar'")); exception.expectMessage(containsString("is declared as an @AliasFor nonexistent attribute 'bar'"));
synthesizeAnnotation(annotation); InternalAnnotationUtils.synthesizeAnnotation(annotation);
} }
@Test @Test
@ -919,7 +919,7 @@ public class AnnotationUtilsTests {
exception.expectMessage(startsWith("Attribute 'bar' in")); exception.expectMessage(startsWith("Attribute 'bar' in"));
exception.expectMessage(containsString(AliasForWithoutMirroredAliasFor.class.getName())); exception.expectMessage(containsString(AliasForWithoutMirroredAliasFor.class.getName()));
exception.expectMessage(containsString("@AliasFor [foo]")); exception.expectMessage(containsString("@AliasFor [foo]"));
synthesizeAnnotation(annotation); InternalAnnotationUtils.synthesizeAnnotation(annotation);
} }
@Test @Test
@ -931,7 +931,7 @@ public class AnnotationUtilsTests {
exception.expectMessage(containsString(AliasForWithMirroredAliasForWrongAttribute.class.getName())); exception.expectMessage(containsString(AliasForWithMirroredAliasForWrongAttribute.class.getName()));
exception.expectMessage(either(containsString("must be declared as an @AliasFor [foo], not [quux]")). exception.expectMessage(either(containsString("must be declared as an @AliasFor [foo], not [quux]")).
or(containsString("is declared as an @AliasFor nonexistent attribute 'quux'"))); or(containsString("is declared as an @AliasFor nonexistent attribute 'quux'")));
synthesizeAnnotation(annotation); InternalAnnotationUtils.synthesizeAnnotation(annotation);
} }
@Test @Test
@ -944,7 +944,7 @@ public class AnnotationUtilsTests {
exception.expectMessage(containsString("attribute 'foo'")); exception.expectMessage(containsString("attribute 'foo'"));
exception.expectMessage(containsString("attribute 'bar'")); exception.expectMessage(containsString("attribute 'bar'"));
exception.expectMessage(containsString("same return type")); exception.expectMessage(containsString("same return type"));
synthesizeAnnotation(annotation); InternalAnnotationUtils.synthesizeAnnotation(annotation);
} }
@Test @Test
@ -957,7 +957,7 @@ public class AnnotationUtilsTests {
exception.expectMessage(containsString("attribute 'foo' in annotation")); exception.expectMessage(containsString("attribute 'foo' in annotation"));
exception.expectMessage(containsString("attribute 'bar' in annotation")); exception.expectMessage(containsString("attribute 'bar' in annotation"));
exception.expectMessage(containsString("default values")); exception.expectMessage(containsString("default values"));
synthesizeAnnotation(annotation); InternalAnnotationUtils.synthesizeAnnotation(annotation);
} }
@Test @Test
@ -970,7 +970,7 @@ public class AnnotationUtilsTests {
exception.expectMessage(containsString("attribute 'foo' in annotation")); exception.expectMessage(containsString("attribute 'foo' in annotation"));
exception.expectMessage(containsString("attribute 'bar' in annotation")); exception.expectMessage(containsString("attribute 'bar' in annotation"));
exception.expectMessage(containsString("same default value")); exception.expectMessage(containsString("same default value"));
synthesizeAnnotation(annotation); InternalAnnotationUtils.synthesizeAnnotation(annotation);
} }
@Test @Test
@ -983,7 +983,7 @@ public class AnnotationUtilsTests {
exception.expectMessage(containsString("declares an alias for attribute 'location' in meta-annotation")); exception.expectMessage(containsString("declares an alias for attribute 'location' in meta-annotation"));
exception.expectMessage(containsString(ContextConfig.class.getName())); exception.expectMessage(containsString(ContextConfig.class.getName()));
exception.expectMessage(containsString("not meta-present")); exception.expectMessage(containsString("not meta-present"));
synthesizeAnnotation(annotation); InternalAnnotationUtils.synthesizeAnnotation(annotation);
} }
@Test @Test
@ -992,7 +992,7 @@ public class AnnotationUtilsTests {
WebMapping webMapping = method.getAnnotation(WebMapping.class); WebMapping webMapping = method.getAnnotation(WebMapping.class);
assertNotNull(webMapping); assertNotNull(webMapping);
WebMapping synthesizedWebMapping1 = synthesizeAnnotation(webMapping); WebMapping synthesizedWebMapping1 = InternalAnnotationUtils.synthesizeAnnotation(webMapping);
assertThat(synthesizedWebMapping1, instanceOf(SynthesizedAnnotation.class)); assertThat(synthesizedWebMapping1, instanceOf(SynthesizedAnnotation.class));
assertNotSame(webMapping, synthesizedWebMapping1); assertNotSame(webMapping, synthesizedWebMapping1);
@ -1000,7 +1000,7 @@ public class AnnotationUtilsTests {
assertArrayEquals("aliased path attribute: ", asArray("/test"), synthesizedWebMapping1.path()); assertArrayEquals("aliased path attribute: ", asArray("/test"), synthesizedWebMapping1.path());
assertArrayEquals("actual value attribute: ", asArray("/test"), synthesizedWebMapping1.value()); assertArrayEquals("actual value attribute: ", asArray("/test"), synthesizedWebMapping1.value());
WebMapping synthesizedWebMapping2 = synthesizeAnnotation(webMapping); WebMapping synthesizedWebMapping2 = InternalAnnotationUtils.synthesizeAnnotation(webMapping);
assertThat(synthesizedWebMapping2, instanceOf(SynthesizedAnnotation.class)); assertThat(synthesizedWebMapping2, instanceOf(SynthesizedAnnotation.class));
assertNotSame(webMapping, synthesizedWebMapping2); assertNotSame(webMapping, synthesizedWebMapping2);
@ -1021,7 +1021,7 @@ public class AnnotationUtilsTests {
ImplicitAliasesContextConfig config = clazz.getAnnotation(ImplicitAliasesContextConfig.class); ImplicitAliasesContextConfig config = clazz.getAnnotation(ImplicitAliasesContextConfig.class);
assertNotNull(config); assertNotNull(config);
ImplicitAliasesContextConfig synthesizedConfig = synthesizeAnnotation(config); ImplicitAliasesContextConfig synthesizedConfig = InternalAnnotationUtils.synthesizeAnnotation(config);
assertThat(synthesizedConfig, instanceOf(SynthesizedAnnotation.class)); assertThat(synthesizedConfig, instanceOf(SynthesizedAnnotation.class));
assertEquals("value: ", expected, synthesizedConfig.value()); assertEquals("value: ", expected, synthesizedConfig.value());
@ -1047,7 +1047,7 @@ public class AnnotationUtilsTests {
ImplicitAliasesWithImpliedAliasNamesOmittedContextConfig.class); ImplicitAliasesWithImpliedAliasNamesOmittedContextConfig.class);
assertNotNull(config); assertNotNull(config);
ImplicitAliasesWithImpliedAliasNamesOmittedContextConfig synthesizedConfig = synthesizeAnnotation(config); ImplicitAliasesWithImpliedAliasNamesOmittedContextConfig synthesizedConfig = InternalAnnotationUtils.synthesizeAnnotation(config);
assertThat(synthesizedConfig, instanceOf(SynthesizedAnnotation.class)); assertThat(synthesizedConfig, instanceOf(SynthesizedAnnotation.class));
assertEquals("value: ", expected, synthesizedConfig.value()); assertEquals("value: ", expected, synthesizedConfig.value());
@ -1061,7 +1061,7 @@ public class AnnotationUtilsTests {
ImplicitAliasesForAliasPairContextConfig config = clazz.getAnnotation(ImplicitAliasesForAliasPairContextConfig.class); ImplicitAliasesForAliasPairContextConfig config = clazz.getAnnotation(ImplicitAliasesForAliasPairContextConfig.class);
assertNotNull(config); assertNotNull(config);
ImplicitAliasesForAliasPairContextConfig synthesizedConfig = synthesizeAnnotation(config); ImplicitAliasesForAliasPairContextConfig synthesizedConfig = InternalAnnotationUtils.synthesizeAnnotation(config);
assertThat(synthesizedConfig, instanceOf(SynthesizedAnnotation.class)); assertThat(synthesizedConfig, instanceOf(SynthesizedAnnotation.class));
assertEquals("xmlFile: ", "test.xml", synthesizedConfig.xmlFile()); assertEquals("xmlFile: ", "test.xml", synthesizedConfig.xmlFile());
@ -1074,7 +1074,7 @@ public class AnnotationUtilsTests {
TransitiveImplicitAliasesContextConfig config = clazz.getAnnotation(TransitiveImplicitAliasesContextConfig.class); TransitiveImplicitAliasesContextConfig config = clazz.getAnnotation(TransitiveImplicitAliasesContextConfig.class);
assertNotNull(config); assertNotNull(config);
TransitiveImplicitAliasesContextConfig synthesizedConfig = synthesizeAnnotation(config); TransitiveImplicitAliasesContextConfig synthesizedConfig = InternalAnnotationUtils.synthesizeAnnotation(config);
assertThat(synthesizedConfig, instanceOf(SynthesizedAnnotation.class)); assertThat(synthesizedConfig, instanceOf(SynthesizedAnnotation.class));
assertEquals("xml: ", "test.xml", synthesizedConfig.xml()); assertEquals("xml: ", "test.xml", synthesizedConfig.xml());
@ -1087,7 +1087,7 @@ public class AnnotationUtilsTests {
TransitiveImplicitAliasesForAliasPairContextConfig config = clazz.getAnnotation(TransitiveImplicitAliasesForAliasPairContextConfig.class); TransitiveImplicitAliasesForAliasPairContextConfig config = clazz.getAnnotation(TransitiveImplicitAliasesForAliasPairContextConfig.class);
assertNotNull(config); assertNotNull(config);
TransitiveImplicitAliasesForAliasPairContextConfig synthesizedConfig = synthesizeAnnotation(config); TransitiveImplicitAliasesForAliasPairContextConfig synthesizedConfig = InternalAnnotationUtils.synthesizeAnnotation(config);
assertThat(synthesizedConfig, instanceOf(SynthesizedAnnotation.class)); assertThat(synthesizedConfig, instanceOf(SynthesizedAnnotation.class));
assertEquals("xml: ", "test.xml", synthesizedConfig.xml()); assertEquals("xml: ", "test.xml", synthesizedConfig.xml());
@ -1241,7 +1241,7 @@ public class AnnotationUtilsTests {
@Test @Test
public void synthesizeAnnotationWithAttributeAliasesWithDifferentValues() throws Exception { public void synthesizeAnnotationWithAttributeAliasesWithDifferentValues() throws Exception {
ContextConfig contextConfig = synthesizeAnnotation(ContextConfigMismatch.class.getAnnotation(ContextConfig.class)); ContextConfig contextConfig = InternalAnnotationUtils.synthesizeAnnotation(ContextConfigMismatch.class.getAnnotation(ContextConfig.class));
exception.expect(AnnotationConfigurationException.class); exception.expect(AnnotationConfigurationException.class);
getValue(contextConfig); getValue(contextConfig);
} }
@ -1357,9 +1357,9 @@ public class AnnotationUtilsTests {
WebMapping webMappingWithPathAndValue = methodWithPathAndValue.getAnnotation(WebMapping.class); WebMapping webMappingWithPathAndValue = methodWithPathAndValue.getAnnotation(WebMapping.class);
assertNotNull(webMappingWithPathAndValue); assertNotNull(webMappingWithPathAndValue);
WebMapping synthesizedWebMapping1 = synthesizeAnnotation(webMappingWithAliases); WebMapping synthesizedWebMapping1 = InternalAnnotationUtils.synthesizeAnnotation(webMappingWithAliases);
assertNotNull(synthesizedWebMapping1); assertNotNull(synthesizedWebMapping1);
WebMapping synthesizedWebMapping2 = synthesizeAnnotation(webMappingWithAliases); WebMapping synthesizedWebMapping2 = InternalAnnotationUtils.synthesizeAnnotation(webMappingWithAliases);
assertNotNull(synthesizedWebMapping2); assertNotNull(synthesizedWebMapping2);
assertThat(webMappingWithAliases.toString(), is(not(synthesizedWebMapping1.toString()))); assertThat(webMappingWithAliases.toString(), is(not(synthesizedWebMapping1.toString())));
@ -1388,9 +1388,9 @@ public class AnnotationUtilsTests {
WebMapping webMappingWithPathAndValue = methodWithPathAndValue.getAnnotation(WebMapping.class); WebMapping webMappingWithPathAndValue = methodWithPathAndValue.getAnnotation(WebMapping.class);
assertNotNull(webMappingWithPathAndValue); assertNotNull(webMappingWithPathAndValue);
WebMapping synthesizedWebMapping1 = synthesizeAnnotation(webMappingWithAliases); WebMapping synthesizedWebMapping1 = InternalAnnotationUtils.synthesizeAnnotation(webMappingWithAliases);
assertNotNull(synthesizedWebMapping1); assertNotNull(synthesizedWebMapping1);
WebMapping synthesizedWebMapping2 = synthesizeAnnotation(webMappingWithAliases); WebMapping synthesizedWebMapping2 = InternalAnnotationUtils.synthesizeAnnotation(webMappingWithAliases);
assertNotNull(synthesizedWebMapping2); assertNotNull(synthesizedWebMapping2);
// Equality amongst standard annotations // Equality amongst standard annotations
@ -1426,9 +1426,9 @@ public class AnnotationUtilsTests {
WebMapping webMappingWithPathAndValue = methodWithPathAndValue.getAnnotation(WebMapping.class); WebMapping webMappingWithPathAndValue = methodWithPathAndValue.getAnnotation(WebMapping.class);
assertNotNull(webMappingWithPathAndValue); assertNotNull(webMappingWithPathAndValue);
WebMapping synthesizedWebMapping1 = synthesizeAnnotation(webMappingWithAliases); WebMapping synthesizedWebMapping1 = InternalAnnotationUtils.synthesizeAnnotation(webMappingWithAliases);
assertNotNull(synthesizedWebMapping1); assertNotNull(synthesizedWebMapping1);
WebMapping synthesizedWebMapping2 = synthesizeAnnotation(webMappingWithAliases); WebMapping synthesizedWebMapping2 = InternalAnnotationUtils.synthesizeAnnotation(webMappingWithAliases);
assertNotNull(synthesizedWebMapping2); assertNotNull(synthesizedWebMapping2);
// Equality amongst standard annotations // Equality amongst standard annotations
@ -1470,7 +1470,7 @@ public class AnnotationUtilsTests {
Annotation annotation = clazz.getAnnotation(annotationType); Annotation annotation = clazz.getAnnotation(annotationType);
assertNotNull(annotation); assertNotNull(annotation);
Annotation synthesizedAnnotation = synthesizeAnnotation(annotation); Annotation synthesizedAnnotation = InternalAnnotationUtils.synthesizeAnnotation(annotation);
assertNotSame(annotation, synthesizedAnnotation); assertNotSame(annotation, synthesizedAnnotation);
assertNotNull(synthesizedAnnotation); assertNotNull(synthesizedAnnotation);
@ -1485,7 +1485,7 @@ public class AnnotationUtilsTests {
Hierarchy hierarchy = ConfigHierarchyTestCase.class.getAnnotation(Hierarchy.class); Hierarchy hierarchy = ConfigHierarchyTestCase.class.getAnnotation(Hierarchy.class);
assertNotNull(hierarchy); assertNotNull(hierarchy);
Hierarchy synthesizedHierarchy = synthesizeAnnotation(hierarchy); Hierarchy synthesizedHierarchy = InternalAnnotationUtils.synthesizeAnnotation(hierarchy);
assertNotSame(hierarchy, synthesizedHierarchy); assertNotSame(hierarchy, synthesizedHierarchy);
assertThat(synthesizedHierarchy, instanceOf(SynthesizedAnnotation.class)); assertThat(synthesizedHierarchy, instanceOf(SynthesizedAnnotation.class));
@ -1507,7 +1507,7 @@ public class AnnotationUtilsTests {
Hierarchy hierarchy = ConfigHierarchyTestCase.class.getAnnotation(Hierarchy.class); Hierarchy hierarchy = ConfigHierarchyTestCase.class.getAnnotation(Hierarchy.class);
assertNotNull(hierarchy); assertNotNull(hierarchy);
Hierarchy synthesizedHierarchy = synthesizeAnnotation(hierarchy); Hierarchy synthesizedHierarchy = InternalAnnotationUtils.synthesizeAnnotation(hierarchy);
assertThat(synthesizedHierarchy, instanceOf(SynthesizedAnnotation.class)); assertThat(synthesizedHierarchy, instanceOf(SynthesizedAnnotation.class));
ContextConfig contextConfig = SimpleConfigTestCase.class.getAnnotation(ContextConfig.class); ContextConfig contextConfig = SimpleConfigTestCase.class.getAnnotation(ContextConfig.class);
@ -1530,7 +1530,7 @@ public class AnnotationUtilsTests {
public void synthesizeAnnotationWithArrayOfChars() throws Exception { public void synthesizeAnnotationWithArrayOfChars() throws Exception {
CharsContainer charsContainer = GroupOfCharsClass.class.getAnnotation(CharsContainer.class); CharsContainer charsContainer = GroupOfCharsClass.class.getAnnotation(CharsContainer.class);
assertNotNull(charsContainer); assertNotNull(charsContainer);
CharsContainer synthesizedCharsContainer = synthesizeAnnotation(charsContainer); CharsContainer synthesizedCharsContainer = InternalAnnotationUtils.synthesizeAnnotation(charsContainer);
assertThat(synthesizedCharsContainer, instanceOf(SynthesizedAnnotation.class)); assertThat(synthesizedCharsContainer, instanceOf(SynthesizedAnnotation.class));
char[] chars = synthesizedCharsContainer.chars(); char[] chars = synthesizedCharsContainer.chars();
@ -1546,9 +1546,9 @@ public class AnnotationUtilsTests {
@Test @Test
public void interfaceWithAnnotatedMethods() { public void interfaceWithAnnotatedMethods() {
assertTrue(AnnotationUtils.getAnnotatedMethodsInBaseType(NonAnnotatedInterface.class).isEmpty()); assertTrue(InternalAnnotationUtils.getAnnotatedMethodsInBaseType(NonAnnotatedInterface.class).isEmpty());
assertFalse(AnnotationUtils.getAnnotatedMethodsInBaseType(AnnotatedInterface.class).isEmpty()); assertFalse(InternalAnnotationUtils.getAnnotatedMethodsInBaseType(AnnotatedInterface.class).isEmpty());
assertTrue(AnnotationUtils.getAnnotatedMethodsInBaseType(NullableAnnotatedInterface.class).isEmpty()); assertTrue(InternalAnnotationUtils.getAnnotatedMethodsInBaseType(NullableAnnotatedInterface.class).isEmpty());
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -122,7 +122,7 @@ public class MapAnnotationAttributeExtractorTests extends AbstractAliasAwareAnno
// we have to rig the attributeAliasesCache in AnnotationUtils so that the tests // we have to rig the attributeAliasesCache in AnnotationUtils so that the tests
// consistently fail in case enrichAndValidateAttributes() is buggy. // consistently fail in case enrichAndValidateAttributes() is buggy.
// Otherwise, these tests would intermittently pass even for an invalid implementation. // Otherwise, these tests would intermittently pass even for an invalid implementation.
Field cacheField = AnnotationUtils.class.getDeclaredField("attributeAliasesCache"); Field cacheField = InternalAnnotationUtils.class.getDeclaredField("attributeAliasesCache");
cacheField.setAccessible(true); cacheField.setAccessible(true);
Map<Class<? extends Annotation>, MultiValueMap<String, String>> attributeAliasesCache = Map<Class<? extends Annotation>, MultiValueMap<String, String>> attributeAliasesCache =
(Map<Class<? extends Annotation>, MultiValueMap<String, String>>) cacheField.get(null); (Map<Class<? extends Annotation>, MultiValueMap<String, String>>) cacheField.get(null);