Polishing

This commit is contained in:
Juergen Hoeller
2024-10-16 11:35:23 +02:00
parent a228eb8bd6
commit feb6a5f52d
12 changed files with 75 additions and 124 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -45,11 +45,13 @@ public final class AccessControl {
private final Visibility visibility;
AccessControl(Class<?> target, Visibility visibility) {
this.target = target;
this.visibility = visibility;
}
/**
* Create an {@link AccessControl} for the given member. This considers the
* member modifier, parameter types, return types and any enclosing classes.
@@ -68,8 +70,7 @@ public final class AccessControl {
* @return the {@link AccessControl} for the type
*/
public static AccessControl forResolvableType(ResolvableType resolvableType) {
return new AccessControl(resolvableType.toClass(),
Visibility.forResolvableType(resolvableType));
return new AccessControl(resolvableType.toClass(), Visibility.forResolvableType(resolvableType));
}
/**
@@ -87,8 +88,8 @@ public final class AccessControl {
* @return the lowest {@link AccessControl} from the candidates
*/
public static AccessControl lowest(AccessControl... candidates) {
int index = Visibility.lowestIndex(Arrays.stream(candidates)
.map(AccessControl::getVisibility).toArray(Visibility[]::new));
int index = Visibility.lowestIndex(
Arrays.stream(candidates).map(AccessControl::getVisibility).toArray(Visibility[]::new));
return candidates[index];
}
@@ -125,6 +126,7 @@ public final class AccessControl {
return this.target.getPackageName().equals(type.packageName());
}
/**
* Access visibility types as determined by the <a href=
* "https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html">modifiers</a>
@@ -270,6 +272,6 @@ public final class AccessControl {
}
return index;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -28,21 +28,22 @@ import org.springframework.lang.Nullable;
* @author Brian Clozel
* @since 6.0
*/
public class JavaSerializationHint implements ConditionalHint {
public final class JavaSerializationHint implements ConditionalHint {
private final TypeReference type;
@Nullable
private final TypeReference reachableType;
JavaSerializationHint(Builder builder) {
this.type = builder.type;
this.reachableType = builder.reachableType;
}
/**
* Return the {@link TypeReference type} that needs to be serialized using
* Java serialization at runtime.
* Return the {@link TypeReference type} that needs to be serialized using Java serialization at runtime.
* @return a {@link Serializable} type
*/
public TypeReference getType() {
@@ -56,16 +57,9 @@ public class JavaSerializationHint implements ConditionalHint {
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
JavaSerializationHint that = (JavaSerializationHint) o;
return this.type.equals(that.type)
&& Objects.equals(this.reachableType, that.reachableType);
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof JavaSerializationHint that &&
this.type.equals(that.type) && Objects.equals(this.reachableType, that.reachableType)));
}
@Override
@@ -84,16 +78,13 @@ public class JavaSerializationHint implements ConditionalHint {
@Nullable
private TypeReference reachableType;
Builder(TypeReference type) {
this.type = type;
}
/**
* Make this hint conditional on the fact that the specified type
* can be resolved.
* @param reachableType the type that should be reachable for this
* hint to apply
* Make this hint conditional on the fact that the specified type can be resolved.
* @param reachableType the type that should be reachable for this hint to apply
* @return {@code this}, to facilitate method chaining
*/
public Builder onReachableType(TypeReference reachableType) {
@@ -108,6 +99,6 @@ public class JavaSerializationHint implements ConditionalHint {
JavaSerializationHint build() {
return new JavaSerializationHint(this);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -62,6 +62,7 @@ public final class JdkProxyHint implements ConditionalHint {
return new Builder().proxiedInterfaces(proxiedInterfaces);
}
/**
* Return the interfaces to be proxied.
* @return the interfaces that the proxy should implement
@@ -77,16 +78,10 @@ public final class JdkProxyHint implements ConditionalHint {
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
JdkProxyHint that = (JdkProxyHint) o;
return this.proxiedInterfaces.equals(that.proxiedInterfaces)
&& Objects.equals(this.reachableType, that.reachableType);
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof JdkProxyHint that &&
this.proxiedInterfaces.equals(that.proxiedInterfaces) &&
Objects.equals(this.reachableType, that.reachableType)));
}
@Override
@@ -105,7 +100,6 @@ public final class JdkProxyHint implements ConditionalHint {
@Nullable
private TypeReference reachableType;
Builder() {
this.proxiedInterfaces = new LinkedList<>();
}
@@ -131,10 +125,8 @@ public final class JdkProxyHint implements ConditionalHint {
}
/**
* Make this hint conditional on the fact that the specified type
* can be resolved.
* @param reachableType the type that should be reachable for this
* hint to apply
* Make this hint conditional on the fact that the specified type can be resolved.
* @param reachableType the type that should be reachable for this hint to apply
* @return {@code this}, to facilitate method chaining
*/
public Builder onReachableType(TypeReference reachableType) {
@@ -160,7 +152,6 @@ public final class JdkProxyHint implements ConditionalHint {
}
return TypeReference.listOf(proxiedInterfaces);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -41,9 +41,9 @@ public final class ResourceBundleHint implements ConditionalHint {
this.reachableType = builder.reachableType;
}
/**
* Return the {@code baseName} of the resource bundle.
* @return the base name
*/
public String getBaseName() {
return this.baseName;
@@ -56,16 +56,9 @@ public final class ResourceBundleHint implements ConditionalHint {
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ResourceBundleHint that = (ResourceBundleHint) o;
return this.baseName.equals(that.baseName)
&& Objects.equals(this.reachableType, that.reachableType);
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof ResourceBundleHint that &&
this.baseName.equals(that.baseName) && Objects.equals(this.reachableType, that.reachableType)));
}
@Override
@@ -73,6 +66,7 @@ public final class ResourceBundleHint implements ConditionalHint {
return Objects.hash(this.baseName, this.reachableType);
}
/**
* Builder for {@link ResourceBundleHint}.
*/
@@ -88,10 +82,8 @@ public final class ResourceBundleHint implements ConditionalHint {
}
/**
* Make this hint conditional on the fact that the specified type
* can be resolved.
* @param reachableType the type that should be reachable for this
* hint to apply
* Make this hint conditional on the fact that the specified type can be resolved.
* @param reachableType the type that should be reachable for this hint to apply
* @return {@code this}, to facilitate method chaining
*/
public Builder onReachableType(TypeReference reachableType) {
@@ -109,14 +101,12 @@ public final class ResourceBundleHint implements ConditionalHint {
}
/**
* Creates a {@link ResourceBundleHint} based on the state of this
* builder.
* Create a {@link ResourceBundleHint} based on the state of this builder.
* @return a resource bundle hint
*/
ResourceBundleHint build() {
return new ResourceBundleHint(this);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -71,7 +71,6 @@ public final class ResourcePatternHint implements ConditionalHint {
/**
* Return the pattern to use for identifying the resources to match.
* @return the pattern
*/
public String getPattern() {
return this.pattern;
@@ -79,7 +78,6 @@ public final class ResourcePatternHint implements ConditionalHint {
/**
* Return the regex {@link Pattern} to use for identifying the resources to match.
* @return the regex pattern
*/
public Pattern toRegex() {
String prefix = (this.pattern.startsWith("*") ? ".*" : "");
@@ -98,16 +96,9 @@ public final class ResourcePatternHint implements ConditionalHint {
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ResourcePatternHint that = (ResourcePatternHint) o;
return this.pattern.equals(that.pattern)
&& Objects.equals(this.reachableType, that.reachableType);
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof ResourcePatternHint that &&
this.pattern.equals(that.pattern) && Objects.equals(this.reachableType, that.reachableType)));
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -75,6 +74,7 @@ public final class TypeHint implements ConditionalHint {
return new Builder(type);
}
/**
* Return the type that this hint handles.
* @return the type
@@ -123,9 +123,7 @@ public final class TypeHint implements ConditionalHint {
@Override
public String toString() {
return new StringJoiner(", ", TypeHint.class.getSimpleName() + "[", "]")
.add("type=" + this.type)
.toString();
return TypeHint.class.getSimpleName() + "[type=" + this.type + "]";
}
/**
@@ -157,16 +155,14 @@ public final class TypeHint implements ConditionalHint {
private final Set<MemberCategory> memberCategories = new HashSet<>();
Builder(TypeReference type) {
this.type = type;
}
/**
* Make this hint conditional on the fact that the specified type
* is in a reachable code path from a static analysis point of view.
* @param reachableType the type that should be reachable for this
* hint to apply
* Make this hint conditional on the fact that the specified type is in a
* reachable code path from a static analysis point of view.
* @param reachableType the type that should be reachable for this hint to apply
* @return {@code this}, to facilitate method chaining
*/
public Builder onReachableType(TypeReference reachableType) {
@@ -175,10 +171,9 @@ public final class TypeHint implements ConditionalHint {
}
/**
* Make this hint conditional on the fact that the specified type
* is in a reachable code path from a static analysis point of view.
* @param reachableType the type that should be reachable for this
* hint to apply
* Make this hint conditional on the fact that the specified type is in a
* reachable code path from a static analysis point of view.
* @param reachableType the type that should be reachable for this hint to apply
* @return {@code this}, to facilitate method chaining
*/
public Builder onReachableType(Class<?> reachableType) {
@@ -215,8 +210,9 @@ public final class TypeHint implements ConditionalHint {
* constructor
* @return {@code this}, to facilitate method chaining
*/
private Builder withConstructor(List<TypeReference> parameterTypes,
Consumer<ExecutableHint.Builder> constructorHint) {
private Builder withConstructor(
List<TypeReference> parameterTypes, Consumer<ExecutableHint.Builder> constructorHint) {
ExecutableKey key = new ExecutableKey("<init>", parameterTypes);
ExecutableHint.Builder builder = this.constructors.computeIfAbsent(key,
k -> ExecutableHint.ofConstructor(parameterTypes));
@@ -271,38 +267,30 @@ public final class TypeHint implements ConditionalHint {
TypeHint build() {
return new TypeHint(this);
}
}
private static final class ExecutableKey {
private final String name;
private final List<String> parameterTypes;
private ExecutableKey(String name, List<TypeReference> parameterTypes) {
this.name = name;
this.parameterTypes = parameterTypes.stream().map(TypeReference::getCanonicalName).toList();
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ExecutableKey that = (ExecutableKey) o;
return this.name.equals(that.name) && this.parameterTypes.equals(that.parameterTypes);
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof ExecutableKey that &&
this.name.equals(that.name) && this.parameterTypes.equals(that.parameterTypes)));
}
@Override
public int hashCode() {
return Objects.hash(this.name, this.parameterTypes);
}
}
}