Skip to content

Commit

Permalink
feat: read parameter names from bytecode if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbobbert committed Oct 19, 2022
1 parent fbb0aad commit 4b14eee
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/spoon/support/visitor/java/reflect/RtParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Parameter;
import java.lang.reflect.Type;

/**
Expand Down Expand Up @@ -143,7 +144,12 @@ public int hashCode() {
public static RtParameter[] parametersOf(RtMethod method) {
RtParameter[] parameters = new RtParameter[method.getParameterTypes().length];
for (int index = 0; index < method.getParameterTypes().length; index++) {
parameters[index] = new RtParameter(null, method.getParameterTypes()[index], method.getGenericParameterTypes()[index], method, null, index);
String name = null;
Parameter parameter = method.getMethod().getParameters()[index];
if (parameter.isNamePresent()) {
name = parameter.getName();
}
parameters[index] = new RtParameter(name, method.getParameterTypes()[index], method.getGenericParameterTypes()[index], method, null, index);
}
return parameters;
}
Expand Down Expand Up @@ -179,7 +185,12 @@ public static RtParameter[] parametersOf(Constructor constructor) {
}

for (int index = 0; index < constructor.getGenericParameterTypes().length; index++) {
parameters[index] = new RtParameter(null, constructor.getParameterTypes()[index + offset], constructor.getGenericParameterTypes()[index], null, constructor, index);
String name = null;
Parameter parameter = constructor.getParameters()[index + offset];
if (parameter.isNamePresent()) {
name = parameter.getName();
}
parameters[index] = new RtParameter(name, constructor.getParameterTypes()[index + offset], constructor.getGenericParameterTypes()[index], null, constructor, index);
}
return parameters;
}
Expand Down

0 comments on commit 4b14eee

Please sign in to comment.