From 0f05a2e153fad602734761d254448f608fe7290c Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Wed, 8 Apr 2026 11:37:05 +0200 Subject: [PATCH] Polish ClassFileMethodMetadata --- .../classreading/ClassFileMethodMetadata.java | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileMethodMetadata.java b/spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileMethodMetadata.java index 902774906f9..be4e0d4761f 100644 --- a/spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileMethodMetadata.java +++ b/spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileMethodMetadata.java @@ -55,18 +55,18 @@ final class ClassFileMethodMetadata implements MethodMetadata { // The source implements equals(), hashCode(), and toString() for the underlying method. private final Object source; - private final MergedAnnotations annotations; + private final MergedAnnotations mergedAnnotations; ClassFileMethodMetadata(String methodName, AccessFlags accessFlags, @Nullable String declaringClassName, - String returnTypeName, Object source, MergedAnnotations annotations) { + String returnTypeName, Object source, MergedAnnotations mergedAnnotations) { this.methodName = methodName; this.accessFlags = accessFlags; this.declaringClassName = declaringClassName; this.returnTypeName = returnTypeName; this.source = source; - this.annotations = annotations; + this.mergedAnnotations = mergedAnnotations; } @@ -119,7 +119,7 @@ final class ClassFileMethodMetadata implements MethodMetadata { @Override public MergedAnnotations getAnnotations() { - return this.annotations; + return this.mergedAnnotations; } @@ -142,16 +142,19 @@ final class ClassFileMethodMetadata implements MethodMetadata { static ClassFileMethodMetadata of(MethodModel methodModel, ClassLoader classLoader) { String methodName = methodModel.methodName().stringValue(); AccessFlags flags = methodModel.flags(); - String declaringClassName = methodModel.parent().map(parent -> ClassUtils.convertResourcePathToClassName(parent.thisClass().name().stringValue())).orElse(null); + String declaringClassName = methodModel.parent() + .map(parent -> ClassUtils.convertResourcePathToClassName(parent.thisClass().name().stringValue())) + .orElse(null); ClassDesc returnType = methodModel.methodTypeSymbol().returnType(); String returnTypeName = ClassFileAnnotationMetadata.resolveTypeName(returnType); Source source = new Source(declaringClassName, flags, methodName, methodModel.methodTypeSymbol()); - MergedAnnotations annotations = methodModel.elementStream() - .filter(element -> element instanceof RuntimeVisibleAnnotationsAttribute) + MergedAnnotations mergedAnnotations = methodModel.elementStream() + .filter(RuntimeVisibleAnnotationsAttribute.class::isInstance) + .map(RuntimeVisibleAnnotationsAttribute.class::cast) .findFirst() - .map(element -> ClassFileAnnotationDelegate.createMergedAnnotations(methodName, (RuntimeVisibleAnnotationsAttribute) element, classLoader)) - .orElse(MergedAnnotations.of(Collections.emptyList())); - return new ClassFileMethodMetadata(methodName, flags, declaringClassName, returnTypeName, source, annotations); + .map(annotations -> ClassFileAnnotationDelegate.createMergedAnnotations(methodName, annotations, classLoader)) + .orElseGet(() -> MergedAnnotations.of(Collections.emptyList())); + return new ClassFileMethodMetadata(methodName, flags, declaringClassName, returnTypeName, source, mergedAnnotations); } @@ -165,14 +168,12 @@ final class ClassFileMethodMetadata implements MethodMetadata { record Source(@Nullable String declaringClassName, AccessFlags flags, String methodName, MethodTypeDesc descriptor) { @Override - public boolean equals(Object o) { - if (!(o instanceof Source source)) { - return false; - } - return Objects.equals(this.flags.flagsMask(), source.flags.flagsMask()) && - Objects.equals(this.methodName, source.methodName) && - Objects.equals(this.declaringClassName, source.declaringClassName) && - Objects.equals(this.descriptor.descriptorString(), source.descriptor.descriptorString()); + public boolean equals(Object other) { + return (other instanceof Source that && + Objects.equals(this.flags.flagsMask(), that.flags.flagsMask()) && + Objects.equals(this.methodName, that.methodName) && + Objects.equals(this.declaringClassName, that.declaringClassName) && + Objects.equals(this.descriptor.descriptorString(), that.descriptor.descriptorString())); } @Override