Skip to content

Commit 7261f31

Browse files
authored
Merge pull request #3 from spring-projects/master
[pull] master from spring-projects:master
2 parents 1967c34 + 19ff7d8 commit 7261f31

File tree

16 files changed

+109
-215
lines changed

16 files changed

+109
-215
lines changed

spring-context/src/main/java/org/springframework/context/annotation/DeferredImportSelector.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.context.annotation;
1818

19-
import java.util.Objects;
20-
2119
import org.springframework.core.type.AnnotationMetadata;
2220
import org.springframework.lang.Nullable;
2321

@@ -108,13 +106,17 @@ public boolean equals(@Nullable Object other) {
108106
return false;
109107
}
110108
Entry entry = (Entry) other;
111-
return (Objects.equals(this.metadata, entry.metadata) &&
112-
Objects.equals(this.importClassName, entry.importClassName));
109+
return (this.metadata.equals(entry.metadata) && this.importClassName.equals(entry.importClassName));
113110
}
114111

115112
@Override
116113
public int hashCode() {
117-
return Objects.hash(this.metadata, this.importClassName);
114+
return (this.metadata.hashCode() * 31 + this.importClassName.hashCode());
115+
}
116+
117+
@Override
118+
public String toString() {
119+
return this.importClassName;
118120
}
119121
}
120122
}

spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMapping.java

+10-16
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.LinkedHashSet;
2828
import java.util.List;
2929
import java.util.Map;
30-
import java.util.Objects;
3130
import java.util.Set;
3231
import java.util.function.BiFunction;
3332

@@ -179,30 +178,25 @@ private Method resolveAliasTarget(Method attribute, AliasFor aliasFor, boolean c
179178
}
180179
if (isAliasPair(target) && checkAliasPair) {
181180
AliasFor targetAliasFor = target.getAnnotation(AliasFor.class);
182-
if (targetAliasFor == null) {
183-
throw new AnnotationConfigurationException(String.format(
184-
"%s must be declared as an @AliasFor '%s'.",
185-
StringUtils.capitalize(AttributeMethods.describe(target)),
186-
attribute.getName()));
187-
}
188-
Method mirror = resolveAliasTarget(target, targetAliasFor, false);
189-
if (!mirror.equals(attribute)) {
190-
throw new AnnotationConfigurationException(String.format(
191-
"%s must be declared as an @AliasFor '%s', not '%s'.",
192-
StringUtils.capitalize(AttributeMethods.describe(target)),
193-
attribute.getName(), mirror.getName()));
181+
if (targetAliasFor != null) {
182+
Method mirror = resolveAliasTarget(target, targetAliasFor, false);
183+
if (!mirror.equals(attribute)) {
184+
throw new AnnotationConfigurationException(String.format(
185+
"%s must be declared as an @AliasFor '%s', not '%s'.",
186+
StringUtils.capitalize(AttributeMethods.describe(target)),
187+
attribute.getName(), mirror.getName()));
188+
}
194189
}
195190
}
196191
return target;
197192
}
198193

199194
private boolean isAliasPair(Method target) {
200-
return target.getDeclaringClass().equals(this.annotationType);
195+
return (this.annotationType == target.getDeclaringClass());
201196
}
202197

203198
private boolean isCompatibleReturnType(Class<?> attributeType, Class<?> targetType) {
204-
return Objects.equals(attributeType, targetType) ||
205-
Objects.equals(attributeType, targetType.getComponentType());
199+
return (attributeType == targetType || attributeType == targetType.getComponentType());
206200
}
207201

208202
private void processAliases() {

spring-core/src/main/java/org/springframework/core/annotation/AttributeMethods.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.lang.Nullable;
2626
import org.springframework.util.Assert;
2727
import org.springframework.util.ConcurrentReferenceHashMap;
28+
import org.springframework.util.ReflectionUtils;
2829

2930
/**
3031
* Provides a quick way to access the attribute methods of an {@link Annotation}
@@ -73,15 +74,11 @@ private AttributeMethods(@Nullable Class<? extends Annotation> annotationType, M
7374
if (method.getDefaultValue() != null) {
7475
foundDefaultValueMethod = true;
7576
}
76-
if (type.isAnnotation() ||
77-
(type.isArray() && type.getComponentType().isAnnotation())) {
77+
if (type.isAnnotation() || (type.isArray() && type.getComponentType().isAnnotation())) {
7878
foundNestedAnnotation = true;
7979
}
80-
method.setAccessible(true);
81-
this.canThrowTypeNotPresentException[i] =
82-
type == Class.class ||
83-
type == Class[].class ||
84-
type.isEnum();
80+
ReflectionUtils.makeAccessible(method);
81+
this.canThrowTypeNotPresentException[i] = (type == Class.class || type == Class[].class || type.isEnum());
8582
}
8683
this.hasDefaultValueMethod = foundDefaultValueMethod;
8784
this.hasNestedAnnotation = foundNestedAnnotation;

spring-core/src/main/java/org/springframework/core/annotation/RepeatableContainers.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.lang.annotation.Repeatable;
2121
import java.lang.reflect.Method;
2222
import java.util.Map;
23-
import java.util.Objects;
2423

2524
import org.springframework.lang.Nullable;
2625
import org.springframework.util.Assert;
@@ -83,7 +82,7 @@ public boolean equals(@Nullable Object other) {
8382
if (other == null || getClass() != other.getClass()) {
8483
return false;
8584
}
86-
return Objects.equals(this.parent, ((RepeatableContainers) other).parent);
85+
return ObjectUtils.nullSafeEquals(this.parent, ((RepeatableContainers) other).parent);
8786
}
8887

8988
@Override

spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.lang.reflect.Proxy;
2424
import java.util.Arrays;
2525
import java.util.NoSuchElementException;
26-
import java.util.Objects;
2726

2827
import org.springframework.lang.Nullable;
2928
import org.springframework.util.Assert;
@@ -90,7 +89,7 @@ public Object invoke(Object proxy, Method method, Object[] args) {
9089
}
9190

9291
private boolean isAnnotationTypeMethod(Method method) {
93-
return (Objects.equals(method.getName(), "annotationType") && method.getParameterCount() == 0);
92+
return (method.getName().equals("annotationType") && method.getParameterCount() == 0);
9493
}
9594

9695
/**

spring-core/src/main/java/org/springframework/util/unit/DataUnit.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.util.unit;
1818

19-
import java.util.Objects;
20-
2119
/**
2220
* A standard set of {@link DataSize} units.
2321
*
@@ -92,7 +90,7 @@ DataSize size() {
9290
*/
9391
public static DataUnit fromSuffix(String suffix) {
9492
for (DataUnit candidate : values()) {
95-
if (Objects.equals(candidate.suffix, suffix)) {
93+
if (candidate.suffix.equals(suffix)) {
9694
return candidate;
9795
}
9896
}

spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ static class MetaCycleAnnotatedClass {
12001200
@AliasFor("basePackages")
12011201
String[] value() default {};
12021202

1203-
@AliasFor("value")
1203+
// Intentionally no alias declaration for "value"
12041204
String[] basePackages() default {};
12051205

12061206
Filter[] excludeFilters() default {};
@@ -1485,15 +1485,15 @@ class ForAnnotationsClass {
14851485
}
14861486

14871487
@Retention(RetentionPolicy.RUNTIME)
1488-
static @interface ValueAttribute {
1488+
@interface ValueAttribute {
14891489

14901490
String[] value();
14911491

14921492
}
14931493

14941494
@Retention(RetentionPolicy.RUNTIME)
14951495
@ValueAttribute("FromValueAttributeMeta")
1496-
static @interface ValueAttributeMeta {
1496+
@interface ValueAttributeMeta {
14971497

14981498
@AliasFor("alias")
14991499
String[] value() default {};
@@ -1505,7 +1505,7 @@ class ForAnnotationsClass {
15051505

15061506
@Retention(RetentionPolicy.RUNTIME)
15071507
@ValueAttributeMeta("FromValueAttributeMetaMeta")
1508-
static @interface ValueAttributeMetaMeta {
1508+
@interface ValueAttributeMetaMeta {
15091509
}
15101510

15111511
@ValueAttributeMetaMeta

0 commit comments

Comments
 (0)