summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/analysis/IndexReferenceVisitor.java
blob: 552601b6a37e81bfd69791dc368c3836adeb696b (plain) (blame)
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
package cuchaz.enigma.analysis;

import cuchaz.enigma.bytecode.AccessFlags;
import cuchaz.enigma.mapping.*;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;

public class IndexReferenceVisitor extends ClassVisitor {
	private final JarIndex index;
	private final ReferencedEntryPool entryPool;
	private ClassEntry classEntry;

	public IndexReferenceVisitor(JarIndex index, ReferencedEntryPool entryPool, int api) {
		super(api);
		this.index = index;
		this.entryPool = entryPool;
	}

	@Override
	public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
		this.classEntry = new ClassEntry(name);
	}

	@Override
	public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
		MethodDefEntry entry = new MethodDefEntry(classEntry, name, new MethodDescriptor(desc), new AccessFlags(access));
		return new Method(this.index, entry, this.api);
	}

	private class Method extends MethodVisitor {
		private final JarIndex index;
		private final MethodDefEntry callerEntry;

		public Method(JarIndex index, MethodDefEntry callerEntry, int api) {
			super(api);
			this.index = index;
			this.callerEntry = callerEntry;
		}

		@Override
		public void visitFieldInsn(int opcode, String owner, String name, String desc) {
			this.index.indexFieldAccess(callerEntry, owner, name, desc);
		}

		@Override
		public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
			this.index.indexMethodCall(callerEntry, owner, name, desc);
		}
	}
}