mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 18:18:48 +00:00
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.
This commit is contained in:
1 parent
d332b22fa9
commit
101adef99c
3 files changed
+33
-9
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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"))
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in new issue
Block a user