diff options
author | jvanderhel <Jappe.vanderhel@gmail.com> | 2011-11-25 21:22:24 +0100 |
---|---|---|
committer | jvanderhel <Jappe.vanderhel@gmail.com> | 2011-11-25 21:22:24 +0100 |
commit | 53ce4f61788ab62263d9e267b947303973d11a7f (patch) | |
tree | bf9dc58b447b28f131a757f1850aeef23718941f /src/eclipseAgent/lombok/eclipse | |
parent | ef820d8d5ab76c6db8335201da3c7ab9de7cb56a (diff) | |
download | lombok-53ce4f61788ab62263d9e267b947303973d11a7f.tar.gz lombok-53ce4f61788ab62263d9e267b947303973d11a7f.tar.bz2 lombok-53ce4f61788ab62263d9e267b947303973d11a7f.zip |
1) Fixed sourceEnds while determining which nodes should be copied
2) Put the method declaration in the interface instead of the annotation
Diffstat (limited to 'src/eclipseAgent/lombok/eclipse')
-rw-r--r-- | src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java | 19 | ||||
-rw-r--r-- | src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java | 36 |
2 files changed, 52 insertions, 3 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java index 0ad7102b..e4af78bf 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java @@ -167,6 +167,25 @@ 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")) diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java index 69024afa..77257931 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java @@ -43,16 +43,46 @@ import org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent; import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner; public class PatchFixes { - public static boolean isGenerated(org.eclipse.jdt.core.dom.Statement statement) { + public static boolean isGenerated(org.eclipse.jdt.core.dom.ASTNode node) { boolean result = false; try { - result = ((Boolean)statement.getClass().getField("$isGenerated").get(statement)).booleanValue(); + result = ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue(); + if (!result && node.getParent() != null && node.getParent() instanceof org.eclipse.jdt.core.dom.QualifiedName) + result = isGenerated(node.getParent()); } catch (Exception e) { // better to assume it isn't generated } return result; } - + + public static boolean returnFalse(java.lang.Object object) { + return false; + } + + /* Very practical implementation, but works for getter and setter even with type parameters */ + public static java.lang.String getRealMethodDeclarationSource(java.lang.String original, org.eclipse.jdt.core.dom.MethodDeclaration declaration) { + if(isGenerated(declaration)) { + String returnType = declaration.getReturnType2().toString(); + String params = ""; + for (Object object : declaration.parameters()) { + org.eclipse.jdt.core.dom.ASTNode parameter = ((org.eclipse.jdt.core.dom.ASTNode)object); + params += ","+parameter.toString(); + } + return returnType + " "+declaration.getName().getFullyQualifiedName()+"("+(params.isEmpty() ? "" : params.substring(1))+");"; + } + return original; + } + + public static int getSourceEndFixed(int sourceEnd, org.eclipse.jdt.internal.compiler.ast.ASTNode node) throws Exception { + if (sourceEnd == -1) { + org.eclipse.jdt.internal.compiler.ast.ASTNode object = (org.eclipse.jdt.internal.compiler.ast.ASTNode)node.getClass().getField("$generatedBy").get(node); + if (object != null) { + return object.sourceEnd; + } + } + return sourceEnd; + } + public static int fixRetrieveStartingCatchPosition(int original, int start) { return original == -1 ? start : original; } |