diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2012-01-09 21:24:07 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2012-01-09 21:25:47 +0100 |
commit | 101adef99c670cd05951a1ef66c1530b4234c1ca (patch) | |
tree | 360ab04e04106f417aebadaf9c8dabf04745cf00 /src | |
parent | d332b22fa9e2da502d3230c2f44191d42cf90522 (diff) | |
download | lombok-101adef99c670cd05951a1ef66c1530b4234c1ca.tar.gz lombok-101adef99c670cd05951a1ef66c1530b4234c1ca.tar.bz2 lombok-101adef99c670cd05951a1ef66c1530b4234c1ca.zip |
Lombok now adds a line about itself to the Eclipse about dialog via patching. This can be used to check that lombok is managing to successfully inject code into the eclipse VM instance.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/lombok/core/Version.java | 4 | ||||
-rw-r--r-- | src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java | 26 | ||||
-rw-r--r-- | src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java | 12 |
3 files changed, 33 insertions, 9 deletions
diff --git a/src/core/lombok/core/Version.java b/src/core/lombok/core/Version.java index 24b4c59c..332bb7d6 100644 --- a/src/core/lombok/core/Version.java +++ b/src/core/lombok/core/Version.java @@ -40,7 +40,7 @@ public class Version { */ public static void main(String[] args) { if (args.length > 0) { - System.out.printf("Lombok %s", getFullVersion()); + System.out.printf("Lombok %s\n", getFullVersion()); } else { System.out.println(VERSION); } @@ -65,6 +65,6 @@ public class Version { } public static String getFullVersion() { - return String.format("v%s \"%s\"\n", VERSION, RELEASE_NAME); + return String.format("v%s \"%s\"", VERSION, RELEASE_NAME); } } diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java index 69a3deaf..220aa9e2 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java @@ -93,6 +93,7 @@ public class EclipsePatcher extends Agent { patchSyntaxAndOccurrencesHighlighting(sm); patchSortMembersOperation(sm); patchExtractInterface(sm); + patchAboutDialog(sm); } else { patchPostCompileHookEcj(sm); } @@ -103,7 +104,7 @@ 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() @@ -112,7 +113,7 @@ public class EclipsePatcher extends Agent { .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", @@ -125,7 +126,7 @@ public class EclipsePatcher extends Agent { .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")) @@ -133,7 +134,7 @@ public class EclipsePatcher extends Agent { .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")) @@ -148,10 +149,23 @@ public class EclipsePatcher extends Agent { .request(StackRequest.PARAM2) .build()); } - + + private static void patchAboutDialog(ScriptManager sm) { + /* + * Add a line about lombok (+ version info) to eclipse's about dialog. + * This is doable without patching, but we intentionally patch it so that presence of the lombok info + * in the about dialog can be used to ascertain that patching in general is doing something. + */ + sm.addScript(ScriptBuilder.wrapReturnValue() + .target(new MethodTarget("org.eclipse.core.internal.runtime.Product", "getProperty", "java.lang.String", "java.lang.String")) + .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "addLombokNotesToEclipseAboutDialog", "java.lang.String", "java.lang.String", "org.eclipse.core.internal.runtime.Product", "java.lang.String")) + .request(StackRequest.RETURN_VALUE, StackRequest.THIS, StackRequest.PARAM1) + .transplant().build()); + } + private static void patchSyntaxAndOccurrencesHighlighting(ScriptManager sm) { /* - * Skip generated nodes for "visual effects" (syntax highlighting && highlight occurrences) + * Skip generated nodes for "visual effects" (syntax highlighting && highlight occurrences) */ sm.addScript(ScriptBuilder.exitEarly() .target(new MethodTarget("org.eclipse.jdt.internal.ui.search.OccurrencesFinder", "addUsage")) diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java index a1825074..8103806b 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java @@ -32,7 +32,9 @@ import java.util.Stack; import lombok.core.DiagnosticsReceiver; import lombok.core.PostCompiler; +import lombok.core.Version; +import org.eclipse.core.internal.runtime.Product; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IAnnotatable; import org.eclipse.jdt.core.IAnnotation; @@ -48,6 +50,14 @@ import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner; import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; public class PatchFixes { + public static String addLombokNotesToEclipseAboutDialog(String origReturnValue, Product product, String key) { + if ("Eclipse SDK".equals(product.getName()) && "aboutText".equals(key)) { + return origReturnValue + "\n\nLombok " + Version.getFullVersion() + " is installed. http://projectlombok.org/"; + } + + return origReturnValue; + } + public static boolean isGenerated(org.eclipse.jdt.core.dom.ASTNode node) { boolean result = false; try { @@ -67,7 +77,7 @@ public class PatchFixes { public static boolean returnFalse(java.lang.Object object) { return false; } - + @java.lang.SuppressWarnings({"unchecked", "rawtypes"}) public static java.util.List removeGeneratedNodes(java.util.List list) { try { java.util.List realNodes = new java.util.ArrayList(list.size()); |