diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2010-11-13 20:21:25 +0000 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2010-11-13 20:21:25 +0000 |
commit | 2ae0341a3f3656ec29094a16d9c9bbfc6f4ba1d3 (patch) | |
tree | e00faac7bb287bf8c6d674bdb1cda01fd5aad3af | |
parent | b30f8e351b241f8976c6b00ff402df39eedde2bc (diff) | |
download | lombok-2ae0341a3f3656ec29094a16d9c9bbfc6f4ba1d3.tar.gz lombok-2ae0341a3f3656ec29094a16d9c9bbfc6f4ba1d3.tar.bz2 lombok-2ae0341a3f3656ec29094a16d9c9bbfc6f4ba1d3.zip |
Jiggered the hook point a bit for eclipse 'delegate' support and it looks like this might just work.
-rw-r--r-- | src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java | 15 | ||||
-rw-r--r-- | src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java | 96 |
2 files changed, 82 insertions, 29 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java index c54ef604..5d24d81e 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java @@ -26,6 +26,9 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import org.eclipse.jdt.internal.compiler.env.AccessRestriction; +import org.eclipse.jdt.internal.compiler.lookup.ClassScope; + import lombok.core.Agent; import lombok.patcher.Hook; import lombok.patcher.MethodTarget; @@ -264,10 +267,18 @@ public class EclipsePatcher extends Agent { private static void patchDelegate(ScriptManager sm) { final String TYPEDECLARATION_SIG = "org.eclipse.jdt.internal.compiler.ast.TypeDeclaration"; +// sm.addScript(ScriptBuilder.exitEarly() +// .target(new MethodTarget(TYPEDECLARATION_SIG, "resolve", "void")) +// .request(StackRequest.THIS) +// .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "handleDelegateForType", "boolean", TYPEDECLARATION_SIG)) +// .build()); + + final String CLASSSCOPE_SIG = "org.eclipse.jdt.internal.compiler.lookup.ClassScope"; + sm.addScript(ScriptBuilder.exitEarly() - .target(new MethodTarget(TYPEDECLARATION_SIG, "resolve", "void")) + .target(new MethodTarget(CLASSSCOPE_SIG, "buildFieldsAndMethods", "void")) .request(StackRequest.THIS) - .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "handleDelegateForType", "boolean", TYPEDECLARATION_SIG)) + .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "handleDelegateForType2", "boolean", CLASSSCOPE_SIG)) .build()); } diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java index e71caa3d..341c54b3 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java @@ -71,6 +71,8 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; +import org.eclipse.jdt.internal.compiler.lookup.ClassScope; +import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; import org.eclipse.jdt.internal.compiler.lookup.MethodScope; import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding; @@ -348,10 +350,47 @@ public class PatchFixes { } public static boolean handleDelegateForType(TypeDeclaration decl) { - if (decl.scope == null) return false; - if (decl.fields == null) return false; + return false; + } + + public static boolean handleDelegateForType2(ClassScope scope) { + TypeDeclaration decl = scope.referenceContext; + if (decl == null) return false; - for (FieldDeclaration field : decl.fields) { + boolean continueAdding = false; + + /* debug */ try { + MethodBinding[] existingMethods = (MethodBinding[]) sourceTypeBindingMethodsField.get(decl.binding); + System.out.println("Existing method bindings in type.SourceTypeBinding: " + new String(scope.referenceContext.name)); + for (MethodBinding binding : existingMethods) { + System.out.println(" " + binding); + } + FieldBinding[] existingFields = (FieldBinding[]) sourceTypeBindingFieldsField.get(decl.binding); + System.out.println("Existing field bindings in type.SourceTypeBinding: "); + for (FieldBinding binding : existingFields) { + System.out.println(" " + binding); + } + + if (charArrayEquals("Test", scope.referenceContext.name)) { + for (AbstractMethodDeclaration m : scope.referenceContext.methods) { + if (m instanceof MethodDeclaration) { + if (charArrayEquals("example", m.selector)) { + System.out.println("Example scope now: " + m.scope); + System.out.println("Example binding now: " + m.binding); + if (m.scope == null && m.binding == null) continueAdding = true; + Thread.dumpStack(); + } + } + } + } + } catch (Exception e) { + System.err.println("EXCEPTION DURING DEBUG 1"); + e.printStackTrace(); + } + + if (!continueAdding) return false; + + if (decl.fields != null) for (FieldDeclaration field : decl.fields) { if (field.annotations == null) continue; for (Annotation ann : field.annotations) { if (ann.type == null) continue; @@ -397,11 +436,11 @@ public class PatchFixes { } private static final Method methodScopeCreateMethodMethod; - private static final Field sourceTypeBindingMethodsField; + private static final Field sourceTypeBindingMethodsField, sourceTypeBindingFieldsField; static { Method m = null; - Field f = null; + Field f = null, g = null; Exception ex = null; try { @@ -409,12 +448,15 @@ public class PatchFixes { m.setAccessible(true); f = SourceTypeBinding.class.getDeclaredField("methods"); f.setAccessible(true); + g = SourceTypeBinding.class.getDeclaredField("fields"); + g.setAccessible(true); } catch (Exception e) { ex = e; } methodScopeCreateMethodMethod = m; sourceTypeBindingMethodsField = f; + sourceTypeBindingFieldsField = g; if (ex != null) throw new RuntimeException(ex); } @@ -440,28 +482,28 @@ public class PatchFixes { newArray[insertionPoint] = method; type.methods = newArray; - MethodScope methodScope = new MethodScope(type.scope, method, false); - - try { - MethodBinding methodBinding = (MethodBinding) methodScopeCreateMethodMethod.invoke(methodScope, method); - System.out.println("SCOPE NOW: " + method.scope); - - method.resolve(type.scope); - System.out.println("Bind now: " + methodBinding.returnType); - - MethodBinding[] existing = (MethodBinding[]) sourceTypeBindingMethodsField.get(type.binding); - if (existing == null) existing = new MethodBinding[] {methodBinding}; - else { - MethodBinding[] copy = new MethodBinding[existing.length + 1]; - System.arraycopy(existing, 0, copy, 0, existing.length); - copy[existing.length] = methodBinding; - } - sourceTypeBindingMethodsField.set(type.binding, existing); - System.out.println("Added method binding: " + methodBinding); - System.out.println(method); - } catch (Exception e) { - throw new RuntimeException(e); - } +// MethodScope methodScope = new MethodScope(type.scope, method, false); +// +// try { +// MethodBinding methodBinding = (MethodBinding) methodScopeCreateMethodMethod.invoke(methodScope, method); +// System.out.println("SCOPE NOW: " + method.scope); +// +// method.resolve(type.scope); +// System.out.println("Bind now: " + methodBinding.returnType); +// +// MethodBinding[] existing = (MethodBinding[]) sourceTypeBindingMethodsField.get(type.binding); +// if (existing == null) existing = new MethodBinding[] {methodBinding}; +// else { +// MethodBinding[] copy = new MethodBinding[existing.length + 1]; +// System.arraycopy(existing, 0, copy, 0, existing.length); +// copy[existing.length] = methodBinding; +// } +// sourceTypeBindingMethodsField.set(type.binding, existing); +// System.out.println("Added method binding: " + methodBinding); +// System.out.println(method); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } } } } |