fix asm parser for methods
This commit is contained in:
@@ -69,7 +69,7 @@ public class AsmParser {
|
||||
}
|
||||
|
||||
private AsmParseResult parseMethodExpression() throws Exception {
|
||||
var cls = method.getClass();
|
||||
var cls = method.getDeclaringClass();
|
||||
var loader = cls.getClassLoader();
|
||||
InputStream is = loader.getResourceAsStream(cls.getName().replace(".", "/") + ".class");
|
||||
Object[] args = new Object[0];//TODO capturing args here? or maybe not supported since this will only be user by getter evaluation
|
||||
|
||||
@@ -10,6 +10,7 @@ class FilterClassVisitor extends ClassVisitor {
|
||||
private final String lambdaname;
|
||||
private final Object[] args;
|
||||
|
||||
private String className;
|
||||
private FilterMethodVisitor mv;
|
||||
|
||||
protected FilterClassVisitor(int api, String lambdaname, Object[] args) {
|
||||
@@ -19,6 +20,12 @@ class FilterClassVisitor extends ClassVisitor {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
this.className = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
||||
if (!name.equals(lambdaname)) {
|
||||
@@ -28,7 +35,7 @@ class FilterClassVisitor extends ClassVisitor {
|
||||
if (mv != null) {
|
||||
throw new IllegalStateException("multiple lambda with same name found: " + lambdaname);
|
||||
}
|
||||
return mv = new FilterMethodVisitor(api, descriptor, args);
|
||||
return mv = new FilterMethodVisitor(api, className, descriptor, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,7 +30,6 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@@ -41,17 +40,22 @@ class FilterMethodVisitor extends MethodVisitor {
|
||||
private Expression lambdaExpr;
|
||||
private final Set<Field> accessedMembers = new HashSet<>();
|
||||
|
||||
protected FilterMethodVisitor(int api, String descriptor, Object[] args) {
|
||||
protected FilterMethodVisitor(int api, String className, String descriptor, Object[] args) {
|
||||
super(api);
|
||||
this.args = args;
|
||||
|
||||
//parameters
|
||||
var types = Type.getMethodType(descriptor).getArgumentTypes();
|
||||
if (types.length == 0) {// class method //TODO this is dirty, as only works for parameterless class methods
|
||||
this.args = new Object[]{null};
|
||||
parameterClasses = new String[]{className};
|
||||
} else {
|
||||
this.args = args;
|
||||
parameterClasses = new String[types.length];
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
parameterClasses[i] = types[i].getClassName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AsmParseResult getResult() {
|
||||
return new AsmParseResult(lambdaExpr, accessedMembers);
|
||||
|
||||
Reference in New Issue
Block a user