Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Oct 16, 2024
1 parent a228eb8 commit feb6a5f
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -29,9 +29,11 @@

/**
* A simple descriptor for an injection point, pointing to a method/constructor
* parameter or a field. Exposed by {@link UnsatisfiedDependencyException}.
* Also available as an argument for factory methods, reacting to the
* requesting injection point for building a customized bean instance.
* parameter or a field.
*
* <p>Exposed by {@link UnsatisfiedDependencyException}. Also available as an
* argument for factory methods, reacting to the requesting injection point
* for building a customized bean instance.
*
* @author Juergen Hoeller
* @since 4.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class DefaultBeanRegistrationCodeFragments implements BeanRegistrationCodeFragme
private final Supplier<InstantiationDescriptor> instantiationDescriptor;


DefaultBeanRegistrationCodeFragments(BeanRegistrationsCode beanRegistrationsCode,
RegisteredBean registeredBean,
DefaultBeanRegistrationCodeFragments(
BeanRegistrationsCode beanRegistrationsCode, RegisteredBean registeredBean,
BeanDefinitionMethodGeneratorFactory beanDefinitionMethodGeneratorFactory) {

this.beanRegistrationsCode = beanRegistrationsCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -148,10 +148,10 @@ public DependencyDescriptor(DependencyDescriptor original) {
this.parameterTypes = original.parameterTypes;
this.parameterIndex = original.parameterIndex;
this.fieldName = original.fieldName;
this.containingClass = original.containingClass;
this.required = original.required;
this.eager = original.eager;
this.nestingLevel = original.nestingLevel;
this.containingClass = original.containingClass;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ private <T> T resolveBean(ResolvableType requiredType, @Nullable Object[] args,
return namedBean.getBeanInstance();
}
BeanFactory parent = getParentBeanFactory();
if (parent instanceof DefaultListableBeanFactory dlfb) {
return dlfb.resolveBean(requiredType, args, nonUniqueAsNull);
if (parent instanceof DefaultListableBeanFactory dlbf) {
return dlbf.resolveBean(requiredType, args, nonUniqueAsNull);
}
else if (parent != null) {
ObjectProvider<T> parentProvider = parent.getBeanProvider(requiredType);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -68,8 +70,7 @@ public static AccessControl forMember(Member member) {
* @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));
}

/**
Expand All @@ -87,8 +88,8 @@ public static AccessControl forClass(Class<?> type) {
* @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];
}

Expand Down Expand Up @@ -125,6 +126,7 @@ public boolean isAccessibleFrom(ClassName type) {
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>
Expand Down Expand Up @@ -270,6 +272,6 @@ static int lowestIndex(Visibility... candidates) {
}
return index;
}

}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -28,21 +28,22 @@
* @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() {
Expand All @@ -56,16 +57,9 @@ public TypeReference getReachableType() {
}

@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
Expand All @@ -84,16 +78,13 @@ public static class Builder {
@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) {
Expand All @@ -108,6 +99,6 @@ public Builder onReachableType(TypeReference reachableType) {
JavaSerializationHint build() {
return new JavaSerializationHint(this);
}

}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -62,6 +62,7 @@ public static Builder of(Class<?>... proxiedInterfaces) {
return new Builder().proxiedInterfaces(proxiedInterfaces);
}


/**
* Return the interfaces to be proxied.
* @return the interfaces that the proxy should implement
Expand All @@ -77,16 +78,10 @@ public TypeReference getReachableType() {
}

@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
Expand All @@ -105,7 +100,6 @@ public static class Builder {
@Nullable
private TypeReference reachableType;


Builder() {
this.proxiedInterfaces = new LinkedList<>();
}
Expand All @@ -131,10 +125,8 @@ public Builder proxiedInterfaces(Class<?>... proxiedInterfaces) {
}

/**
* 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) {
Expand All @@ -160,7 +152,6 @@ private static List<TypeReference> toTypeReferences(Class<?>... proxiedInterface
}
return TypeReference.listOf(proxiedInterfaces);
}

}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -56,23 +56,17 @@ public TypeReference getReachableType() {
}

@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
public int hashCode() {
return Objects.hash(this.baseName, this.reachableType);
}


/**
* Builder for {@link ResourceBundleHint}.
*/
Expand All @@ -88,10 +82,8 @@ public static class Builder {
}

/**
* 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) {
Expand All @@ -109,14 +101,12 @@ public Builder baseName(String baseName) {
}

/**
* 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);
}

}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -71,15 +71,13 @@ 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;
}

/**
* 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("*") ? ".*" : "");
Expand All @@ -98,16 +96,9 @@ public TypeReference getReachableType() {
}

@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
Expand Down
Loading

0 comments on commit feb6a5f

Please sign in to comment.