diff options
author | Roel Spilker <r.spilker@gmail.com> | 2012-01-09 20:43:16 +0100 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2012-01-09 20:43:16 +0100 |
commit | f32dafed68c5caab5fe2502f0fec0543e2c53eb8 (patch) | |
tree | 7dfea447727d9497494afc7d709a4bcee07cc8da /src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java | |
parent | 2ea928229c0c7d362f6f3ef37dbf1f54c28cfbb4 (diff) | |
parent | 1085c902ca7942e1f972b3af9bc2c0e9c873978e (diff) | |
download | lombok-f32dafed68c5caab5fe2502f0fec0543e2c53eb8.tar.gz lombok-f32dafed68c5caab5fe2502f0fec0543e2c53eb8.tar.bz2 lombok-f32dafed68c5caab5fe2502f0fec0543e2c53eb8.zip |
Merge branch 'jvanderhel-Issue_86_Extract_Interface'
Diffstat (limited to 'src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java')
-rw-r--r-- | src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java | 65 |
1 files changed, 46 insertions, 19 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java index c1c1e988..69a3deaf 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java @@ -92,6 +92,7 @@ public class EclipsePatcher extends Agent { patchListRewriteHandleGeneratedMethods(sm); patchSyntaxAndOccurrencesHighlighting(sm); patchSortMembersOperation(sm); + patchExtractInterface(sm); } else { patchPostCompileHookEcj(sm); } @@ -103,6 +104,51 @@ public class EclipsePatcher extends Agent { if (reloadExistingClasses) sm.reloadClasses(instrumentation); } + private static void patchExtractInterface(ScriptManager sm) { + /* Fix sourceEnding for generated nodes to avoid null pointer */ + sm.addScript(ScriptBuilder.wrapMethodCall() + .target(new MethodTarget("org.eclipse.jdt.internal.compiler.SourceElementNotifier", "notifySourceElementRequestor", "void", "org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration", "org.eclipse.jdt.internal.compiler.ast.TypeDeclaration", "org.eclipse.jdt.internal.compiler.ast.ImportReference")) + .methodToWrap(new Hook("org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt", "get", "int", "java.lang.Object")) + .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "getSourceEndFixed", "int", "int", "org.eclipse.jdt.internal.compiler.ast.ASTNode")) + .requestExtra(StackRequest.PARAM1) + .transplant().build()); + + /* Make sure the generated source element is found instead of the annotation */ + sm.addScript(ScriptBuilder.wrapMethodCall() + .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMethodDeclaration", "void", + "org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite", + "org.eclipse.jdt.core.dom.rewrite.ASTRewrite", + "org.eclipse.jdt.core.dom.AbstractTypeDeclaration", + "org.eclipse.jdt.core.dom.MethodDeclaration" + )) + .methodToWrap(new Hook("org.eclipse.jface.text.IDocument", "get", "java.lang.String", "int", "int")) + .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "getRealMethodDeclarationSource", "java.lang.String", "java.lang.String", "org.eclipse.jdt.core.dom.MethodDeclaration")) + .requestExtra(StackRequest.PARAM4) + .build()); + + /* get real generated node in stead of a random one generated by the annotation */ + sm.addScript(ScriptBuilder.replaceMethodCall() + .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMemberDeclarations")) + .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMethodComments")) + .methodToReplace(new Hook("org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil", "getMethodDeclarationNode", "org.eclipse.jdt.core.dom.MethodDeclaration", "org.eclipse.jdt.core.IMethod", "org.eclipse.jdt.core.dom.CompilationUnit")) + .replacementMethod(new Hook("lombok.eclipse.agent.PatchFixes", "getRealMethodDeclarationNode", "org.eclipse.jdt.core.dom.MethodDeclaration", "org.eclipse.jdt.core.IMethod", "org.eclipse.jdt.core.dom.CompilationUnit")) + .build()); + + /* Do not add @Override's for generated methods */ + sm.addScript(ScriptBuilder.exitEarly() + .target(new MethodTarget("org.eclipse.jdt.core.dom.rewrite.ListRewrite", "insertFirst")) + .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isListRewriteOnGeneratedNode", "boolean", "org.eclipse.jdt.core.dom.rewrite.ListRewrite")) + .request(StackRequest.THIS) + .build()); + + /* Do not add comments for generated methods */ + sm.addScript(ScriptBuilder.exitEarly() + .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMethodComment")) + .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode")) + .request(StackRequest.PARAM2) + .build()); + } + private static void patchSyntaxAndOccurrencesHighlighting(ScriptManager sm) { /* * Skip generated nodes for "visual effects" (syntax highlighting && highlight occurrences) @@ -233,25 +279,6 @@ public class EclipsePatcher extends Agent { } private static void patchHideGeneratedNodes(ScriptManager sm) { - sm.addScript(ScriptBuilder.wrapMethodCall() - .target(new MethodTarget("org.eclipse.jdt.internal.compiler.SourceElementNotifier", "notifySourceElementRequestor", "void", "org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration", "org.eclipse.jdt.internal.compiler.ast.TypeDeclaration", "org.eclipse.jdt.internal.compiler.ast.ImportReference")) - .methodToWrap(new Hook("org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt", "get", "int", "java.lang.Object")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "getSourceEndFixed", "int", "int", "org.eclipse.jdt.internal.compiler.ast.ASTNode")) - .requestExtra(StackRequest.PARAM1) - .transplant().build()); - - sm.addScript(ScriptBuilder.wrapMethodCall() - .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMethodDeclaration", "void", - "org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite", - "org.eclipse.jdt.core.dom.rewrite.ASTRewrite", - "org.eclipse.jdt.core.dom.AbstractTypeDeclaration", - "org.eclipse.jdt.core.dom.MethodDeclaration" - )) - .methodToWrap(new Hook("org.eclipse.jface.text.IDocument", "get", "java.lang.String", "int", "int")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "getRealMethodDeclarationSource", "java.lang.String", "java.lang.String", "org.eclipse.jdt.core.dom.MethodDeclaration")) - .requestExtra(StackRequest.PARAM4) - .build()); - sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByNode")) .target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByBinding")) |