Add visibility and return type to SimpleMethodMetadata toString

Closes gh-34649
This commit is contained in:
Brian Clozel 2025-03-25 15:32:42 +01:00
parent 7d0cc6c83a
commit 20b35f068a
2 changed files with 32 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@ -128,7 +128,7 @@ class ConfigurationClassAndBeanMethodTests {
.startsWith("ConfigurationClass: beanName 'Config1', class path resource");
List<BeanMethod> beanMethods = getBeanMethods(configurationClass);
String prefix = "BeanMethod: " + Config1.class.getName();
String prefix = "BeanMethod: java.lang.String " + Config1.class.getName();
assertThat(beanMethods.get(0).toString()).isEqualTo(prefix + ".bean0()");
assertThat(beanMethods.get(1).toString()).isEqualTo(prefix + ".bean1(java.lang.String)");
assertThat(beanMethods.get(2).toString()).isEqualTo(prefix + ".bean2(java.lang.String,java.lang.Integer)");

View File

@ -24,6 +24,7 @@ import org.jspecify.annotations.Nullable;
import org.springframework.asm.AnnotationVisitor;
import org.springframework.asm.MethodVisitor;
import org.springframework.asm.Opcodes;
import org.springframework.asm.SpringAsmInfo;
import org.springframework.asm.Type;
import org.springframework.core.annotation.MergedAnnotation;
@ -87,7 +88,7 @@ final class SimpleMethodMetadataReadingVisitor extends MethodVisitor {
private Object getSource() {
Source source = this.source;
if (source == null) {
source = new Source(this.declaringClassName, this.methodName, this.descriptor);
source = new Source(this.declaringClassName, this.methodName, this.access, this.descriptor);
this.source = source;
}
return source;
@ -103,13 +104,16 @@ final class SimpleMethodMetadataReadingVisitor extends MethodVisitor {
private final String methodName;
private final int access;
private final String descriptor;
private @Nullable String toStringValue;
Source(String declaringClassName, String methodName, String descriptor) {
Source(String declaringClassName, String methodName, int access, String descriptor) {
this.declaringClassName = declaringClassName;
this.methodName = methodName;
this.access = access;
this.descriptor = descriptor;
}
@ -118,6 +122,7 @@ final class SimpleMethodMetadataReadingVisitor extends MethodVisitor {
int result = 1;
result = 31 * result + this.declaringClassName.hashCode();
result = 31 * result + this.methodName.hashCode();
result = 31 * result + this.access;
result = 31 * result + this.descriptor.hashCode();
return result;
}
@ -132,7 +137,8 @@ final class SimpleMethodMetadataReadingVisitor extends MethodVisitor {
}
Source otherSource = (Source) other;
return (this.declaringClassName.equals(otherSource.declaringClassName) &&
this.methodName.equals(otherSource.methodName) && this.descriptor.equals(otherSource.descriptor));
this.methodName.equals(otherSource.methodName) &&
this.access == otherSource.access && this.descriptor.equals(otherSource.descriptor));
}
@Override
@ -140,6 +146,27 @@ final class SimpleMethodMetadataReadingVisitor extends MethodVisitor {
String value = this.toStringValue;
if (value == null) {
StringBuilder builder = new StringBuilder();
if ((this.access & Opcodes.ACC_PUBLIC) != 0) {
builder.append("public ");
}
if ((this.access & Opcodes.ACC_PROTECTED) != 0) {
builder.append("protected ");
}
if ((this.access & Opcodes.ACC_PRIVATE) != 0) {
builder.append("private ");
}
if ((this.access & Opcodes.ACC_ABSTRACT) != 0) {
builder.append("abstract ");
}
if ((this.access & Opcodes.ACC_STATIC) != 0) {
builder.append("static ");
}
if ((this.access & Opcodes.ACC_FINAL) != 0) {
builder.append("final ");
}
Type returnType = Type.getReturnType(this.descriptor);
builder.append(returnType.getClassName());
builder.append(' ');
builder.append(this.declaringClassName);
builder.append('.');
builder.append(this.methodName);