Skip to content

Commit

Permalink
Merge pull request #3 from spring-projects/master
Browse files Browse the repository at this point in the history
[pull] master from spring-projects:master
  • Loading branch information
pull[bot] committed Oct 30, 2019
2 parents 1967c34 + 19ff7d8 commit 7261f31
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.springframework.context.annotation;

import java.util.Objects;

import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;

Expand Down Expand Up @@ -108,13 +106,17 @@ public boolean equals(@Nullable Object other) {
return false;
}
Entry entry = (Entry) other;
return (Objects.equals(this.metadata, entry.metadata) &&
Objects.equals(this.importClassName, entry.importClassName));
return (this.metadata.equals(entry.metadata) && this.importClassName.equals(entry.importClassName));
}

@Override
public int hashCode() {
return Objects.hash(this.metadata, this.importClassName);
return (this.metadata.hashCode() * 31 + this.importClassName.hashCode());
}

@Override
public String toString() {
return this.importClassName;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiFunction;

Expand Down Expand Up @@ -179,30 +178,25 @@ private Method resolveAliasTarget(Method attribute, AliasFor aliasFor, boolean c
}
if (isAliasPair(target) && checkAliasPair) {
AliasFor targetAliasFor = target.getAnnotation(AliasFor.class);
if (targetAliasFor == null) {
throw new AnnotationConfigurationException(String.format(
"%s must be declared as an @AliasFor '%s'.",
StringUtils.capitalize(AttributeMethods.describe(target)),
attribute.getName()));
}
Method mirror = resolveAliasTarget(target, targetAliasFor, false);
if (!mirror.equals(attribute)) {
throw new AnnotationConfigurationException(String.format(
"%s must be declared as an @AliasFor '%s', not '%s'.",
StringUtils.capitalize(AttributeMethods.describe(target)),
attribute.getName(), mirror.getName()));
if (targetAliasFor != null) {
Method mirror = resolveAliasTarget(target, targetAliasFor, false);
if (!mirror.equals(attribute)) {
throw new AnnotationConfigurationException(String.format(
"%s must be declared as an @AliasFor '%s', not '%s'.",
StringUtils.capitalize(AttributeMethods.describe(target)),
attribute.getName(), mirror.getName()));
}
}
}
return target;
}

private boolean isAliasPair(Method target) {
return target.getDeclaringClass().equals(this.annotationType);
return (this.annotationType == target.getDeclaringClass());
}

private boolean isCompatibleReturnType(Class<?> attributeType, Class<?> targetType) {
return Objects.equals(attributeType, targetType) ||
Objects.equals(attributeType, targetType.getComponentType());
return (attributeType == targetType || attributeType == targetType.getComponentType());
}

private void processAliases() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ReflectionUtils;

/**
* Provides a quick way to access the attribute methods of an {@link Annotation}
Expand Down Expand Up @@ -73,15 +74,11 @@ private AttributeMethods(@Nullable Class<? extends Annotation> annotationType, M
if (method.getDefaultValue() != null) {
foundDefaultValueMethod = true;
}
if (type.isAnnotation() ||
(type.isArray() && type.getComponentType().isAnnotation())) {
if (type.isAnnotation() || (type.isArray() && type.getComponentType().isAnnotation())) {
foundNestedAnnotation = true;
}
method.setAccessible(true);
this.canThrowTypeNotPresentException[i] =
type == Class.class ||
type == Class[].class ||
type.isEnum();
ReflectionUtils.makeAccessible(method);
this.canThrowTypeNotPresentException[i] = (type == Class.class || type == Class[].class || type.isEnum());
}
this.hasDefaultValueMethod = foundDefaultValueMethod;
this.hasNestedAnnotation = foundNestedAnnotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.lang.annotation.Repeatable;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Objects;

import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -83,7 +82,7 @@ public boolean equals(@Nullable Object other) {
if (other == null || getClass() != other.getClass()) {
return false;
}
return Objects.equals(this.parent, ((RepeatableContainers) other).parent);
return ObjectUtils.nullSafeEquals(this.parent, ((RepeatableContainers) other).parent);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Objects;

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

private boolean isAnnotationTypeMethod(Method method) {
return (Objects.equals(method.getName(), "annotationType") && method.getParameterCount() == 0);
return (method.getName().equals("annotationType") && method.getParameterCount() == 0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.springframework.util.unit;

import java.util.Objects;

/**
* A standard set of {@link DataSize} units.
*
Expand Down Expand Up @@ -92,7 +90,7 @@ DataSize size() {
*/
public static DataUnit fromSuffix(String suffix) {
for (DataUnit candidate : values()) {
if (Objects.equals(candidate.suffix, suffix)) {
if (candidate.suffix.equals(suffix)) {
return candidate;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ static class MetaCycleAnnotatedClass {
@AliasFor("basePackages")
String[] value() default {};

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

Filter[] excludeFilters() default {};
Expand Down Expand Up @@ -1485,15 +1485,15 @@ class ForAnnotationsClass {
}

@Retention(RetentionPolicy.RUNTIME)
static @interface ValueAttribute {
@interface ValueAttribute {

String[] value();

}

@Retention(RetentionPolicy.RUNTIME)
@ValueAttribute("FromValueAttributeMeta")
static @interface ValueAttributeMeta {
@interface ValueAttributeMeta {

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

@Retention(RetentionPolicy.RUNTIME)
@ValueAttributeMeta("FromValueAttributeMetaMeta")
static @interface ValueAttributeMetaMeta {
@interface ValueAttributeMetaMeta {
}

@ValueAttributeMetaMeta
Expand Down
Loading

0 comments on commit 7261f31

Please sign in to comment.