-
Notifications
You must be signed in to change notification settings - Fork 0
/
HierarchyScanner.java
64 lines (54 loc) · 1.9 KB
/
HierarchyScanner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package bridge.asm;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import java.util.Objects;
public class HierarchyScanner extends ClassVisitor {
private KnownType compiled;
protected final TypeMap types;
protected int access;
protected String name, extended;
protected String[] implemented;
protected Object data;
public HierarchyScanner(TypeMap types) {
this(Opcodes.ASM9, null, types);
}
public HierarchyScanner(ClassVisitor delegate, TypeMap types) {
this(Opcodes.ASM9, delegate, types);
}
protected HierarchyScanner(int api, TypeMap types) {
this(api, null, types);
}
protected HierarchyScanner(int api, ClassVisitor delegate, TypeMap types) {
super(api, delegate);
this.types = Objects.requireNonNull(types);
}
@Override
public void visit(int version, int access, String name, String signature, String extended, String[] implemented) {
super.visit(
version,
this.access = access,
this.name = name,
signature,
this.extended = extended,
this.implemented = implemented
);
}
@Override
public void visitEnd() {
super.visitEnd();
compile().data = data;
}
protected final KnownType compile() {
KnownType type;
if ((type = compiled) == null) {
if (name == null) throw new IllegalStateException("Called to compile() before visit()");
(compiled = type = types.map.computeIfAbsent(Type.getObjectType(name), KnownType::new))
.extended = (extended == null)? types.get(Object.class) : types.loadClass(extended);
type.implemented = types.loadClass(implemented);
type.access = access;
type.data = data;
}
return type;
}
}