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");
* 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.annotatedElement = annotatedElement;
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");
* 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> 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();
Object attributeValue = attributes.get(attributeName);
@@ -158,7 +158,7 @@ class MapAnnotationAttributeExtractor extends AbstractAliasAwareAnnotationAttrib
Class<? extends Annotation> nestedAnnotationType =
(Class<? extends Annotation>) requiredReturnType.getComponentType();
Map<String, Object>[] maps = (Map<String, Object>[]) attributeValue;
attributes.put(attributeName, AnnotationUtils.synthesizeAnnotationArray(maps, nestedAnnotationType));
attributes.put(attributeName, InternalAnnotationUtils.synthesizeAnnotationArray(maps, nestedAnnotationType));
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");
* you may not use this file except in compliance with the License.
@@ -70,10 +70,10 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
if (ReflectionUtils.isToStringMethod(method)) {
return annotationToString();
}
if (AnnotationUtils.isAnnotationTypeMethod(method)) {
if (InternalAnnotationUtils.isAnnotationTypeMethod(method)) {
return annotationType();
}
if (!AnnotationUtils.isAttributeMethod(method)) {
if (!InternalAnnotationUtils.isAttributeMethod(method)) {
throw new AnnotationConfigurationException(String.format(
"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.
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[]) {
value = AnnotationUtils.synthesizeAnnotationArray((Annotation[]) value, this.attributeExtractor.getAnnotatedElement());
value = InternalAnnotationUtils.synthesizeAnnotationArray((Annotation[]) value, this.attributeExtractor.getAnnotatedElement());
}
this.valueCache.put(attributeName, value);
@@ -161,7 +161,7 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
return false;
}
for (Method attributeMethod : AnnotationUtils.getAttributeMethods(annotationType())) {
for (Method attributeMethod : InternalAnnotationUtils.getAttributeMethods(annotationType())) {
Object thisValue = getAttributeValue(attributeMethod);
Object otherValue = ReflectionUtils.invokeMethod(attributeMethod, other);
if (!ObjectUtils.nullSafeEquals(thisValue, otherValue)) {
@@ -178,7 +178,7 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
private int annotationHashCode() {
int result = 0;
for (Method attributeMethod : AnnotationUtils.getAttributeMethods(annotationType())) {
for (Method attributeMethod : InternalAnnotationUtils.getAttributeMethods(annotationType())) {
Object value = getAttributeValue(attributeMethod);
int hashCode;
if (value.getClass().isArray()) {
@@ -236,7 +236,7 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
private String annotationToString() {
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()) {
Method attributeMethod = iterator.next();
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");
* 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());
}
@Override
public SynthesizingMethodParameter clone() {
return new SynthesizingMethodParameter(this);