mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 06:17:44 +00:00
Removed the WeakHashMap for caching EclipseAST objects; obviously wasn't working due to
circular reference from the EclipseAST back to the CUD. Now, patched a field into CompilationUnitDeclaration and using that, which works much better together with the garbage collector.
This commit is contained in:
1 parent
0ef6792608
commit
7d24f9c9a5
4 files changed
+52
-5
No files matched your search
@@ -281,7 +281,7 @@ public class EclipseAST {
|
||||
this.dim = dim;
|
||||
}
|
||||
}
|
||||
private Map<Class<?>, Collection<FieldAccess>> fieldsOfASTClasses = new HashMap<Class<?>, Collection<FieldAccess>>();
|
||||
private static Map<Class<?>, Collection<FieldAccess>> fieldsOfASTClasses = new HashMap<Class<?>, Collection<FieldAccess>>();
|
||||
private Collection<FieldAccess> fieldsOf(Class<?> c) {
|
||||
Collection<FieldAccess> fields = fieldsOfASTClasses.get(c);
|
||||
if ( fields != null ) return fields;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package lombok.agent.eclipse;
|
||||
|
||||
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 {
|
||||
private final byte[] in;
|
||||
|
||||
EclipseCUDTransformer(byte[] classfileBuffer) {
|
||||
in = classfileBuffer;
|
||||
}
|
||||
|
||||
byte[] transform() {
|
||||
ClassReader reader = new ClassReader(in);
|
||||
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, "$lombokAST", "Ljava/lang/Object;", null, null);
|
||||
fv.visitEnd();
|
||||
cv.visitEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,21 @@ public class EclipseParserPatcher {
|
||||
ProtectionDomain protectionDomain, byte[] classfileBuffer)
|
||||
throws IllegalClassFormatException {
|
||||
|
||||
if ( !ECLIPSE_PARSER_CLASS_NAME.equals(className) ) return null;
|
||||
EclipseParserTransformer transformer = new EclipseParserTransformer(classfileBuffer);
|
||||
return transformer.transform();
|
||||
if ( ECLIPSE_PARSER_CLASS_NAME.equals(className) ) {
|
||||
EclipseParserTransformer transformer = new EclipseParserTransformer(classfileBuffer);
|
||||
return transformer.transform();
|
||||
}
|
||||
|
||||
if ( ECLIPSE_CUD_CLASS_NAME.equals(className) ) {
|
||||
EclipseCUDTransformer transformer = new EclipseCUDTransformer(classfileBuffer);
|
||||
return transformer.transform();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static final String ECLIPSE_CUD_CLASS_NAME = "org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration";
|
||||
static final String ECLIPSE_PARSER_CLASS_NAME = "org/eclipse/jdt/internal/compiler/parser/Parser";
|
||||
|
||||
public static void agentmain(String agentArgs, Instrumentation instrumentation) {
|
||||
|
||||
@@ -43,6 +43,7 @@ class EclipseParserTransformer {
|
||||
byte[] transform() {
|
||||
ClassReader reader = new ClassReader(in);
|
||||
ClassWriter writer = new ClassWriter(reader, 0);
|
||||
|
||||
ClassAdapter adapter = new ParserPatcherAdapter(writer);
|
||||
reader.accept(adapter, 0);
|
||||
return writer.toByteArray();
|
||||
|
||||
Reference in new issue
Block a user