Polishing

This commit is contained in:
Juergen Hoeller
2020-04-25 16:37:16 +02:00
parent e5a292fb34
commit af65b1ca62
3 changed files with 21 additions and 23 deletions

View File

@@ -73,18 +73,19 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
private static final Map<Class<?>, Object> EMPTY_ARRAYS;
static {
Map<Class<?>, Object> emptyArrays = new HashMap<>();
emptyArrays.put(String.class, new String[] {});
emptyArrays.put(boolean.class, new boolean[] {});
emptyArrays.put(byte.class, new byte[] {});
emptyArrays.put(char.class, new char[] {});
emptyArrays.put(double.class, new double[] {});
emptyArrays.put(float.class, new float[] {});
emptyArrays.put(int.class, new int[] {});
emptyArrays.put(long.class, new long[] {});
emptyArrays.put(short.class, new short[] {});
emptyArrays.put(boolean.class, new boolean[0]);
emptyArrays.put(byte.class, new byte[0]);
emptyArrays.put(char.class, new char[0]);
emptyArrays.put(double.class, new double[0]);
emptyArrays.put(float.class, new float[0]);
emptyArrays.put(int.class, new int[0]);
emptyArrays.put(long.class, new long[0]);
emptyArrays.put(short.class, new short[0]);
emptyArrays.put(String.class, new String[0]);
EMPTY_ARRAYS = Collections.unmodifiableMap(emptyArrays);
}
private final AnnotationTypeMapping mapping;
@Nullable
@@ -427,9 +428,8 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
}
}
if (!forMirrorResolution) {
attributeIndex = (mapping.getDistance() != 0 ?
this.resolvedMirrors :
this.resolvedRootMirrors)[attributeIndex];
attributeIndex =
(mapping.getDistance() != 0 ? this.resolvedMirrors : this.resolvedRootMirrors)[attributeIndex];
}
if (attributeIndex == -1) {
return null;
@@ -437,15 +437,13 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
if (mapping.getDistance() == 0) {
Method attribute = mapping.getAttributes().get(attributeIndex);
Object result = this.valueExtractor.extract(attribute, this.rootAttributes);
return (result != null) ? result : attribute.getDefaultValue();
return (result != null ? result : attribute.getDefaultValue());
}
return getValueFromMetaAnnotation(attributeIndex, forMirrorResolution);
}
@Nullable
private Object getValueFromMetaAnnotation(int attributeIndex,
boolean forMirrorResolution) {
private Object getValueFromMetaAnnotation(int attributeIndex, boolean forMirrorResolution) {
Object value = null;
if (this.useMergedValues || forMirrorResolution) {
value = this.mapping.getMappedAnnotationValue(attributeIndex, forMirrorResolution);
@@ -479,7 +477,7 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
value = ClassUtils.resolveClassName((String) value, getClassLoader());
}
else if (value instanceof Class[] && type == String[].class) {
Class<?>[] classes = (Class[]) value;
Class<?>[] classes = (Class<?>[]) value;
String[] names = new String[classes.length];
for (int i = 0; i < classes.length; i++) {
names[i] = classes[i].getName();
@@ -522,10 +520,9 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
return adaptForAttribute(attribute, array);
}
if (attributeType.isAnnotation()) {
return adaptToMergedAnnotation(value,(Class<? extends Annotation>) attributeType);
return adaptToMergedAnnotation(value, (Class<? extends Annotation>) attributeType);
}
if (attributeType.isArray() && attributeType.getComponentType().isAnnotation() &&
value.getClass().isArray()) {
if (attributeType.isArray() && attributeType.getComponentType().isAnnotation()) {
MergedAnnotation<?>[] result = new MergedAnnotation<?>[Array.getLength(value)];
for (int i = 0; i < result.length; i++) {
result[i] = adaptToMergedAnnotation(Array.get(value, i),