aboutsummaryrefslogtreecommitdiff
path: root/src_eclipseagent/lombok/eclipse/agent/EclipseCUDTransformer.java
blob: b1dc85cc00634584edf8f180c7e3b4264b4d25ab (plain)
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
package lombok.eclipse.agent;

import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Opcodes;

class EclipseCUDTransformer {
	public byte[] transform(byte[] classfileBuffer) {
		ClassReader reader = new ClassReader(classfileBuffer);
		ClassWriter writer = new ClassWriter(reader, 0);
	
		ClassAdapter adapter = new CUDPatcherAdapter(writer);
		reader.accept(adapter, 0);
		return writer.toByteArray();
	}
	
	private static class CUDPatcherAdapter extends ClassAdapter {
		CUDPatcherAdapter(ClassVisitor cv) {
			super(cv);
		}
		
		@Override public void visitEnd() {
			FieldVisitor fv = cv.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_TRANSIENT, "$lombokAST", "Ljava/lang/Object;", null, null);
			fv.visitEnd();
			cv.visitEnd();
		}
	}
}