Syntax and occurrence highlighting now skip generated positions

This commit is contained in:
jvanderhel committed 2011-11-24 21:31:38 +01:00
1 parent ef820d8d5a
commit 4e831b05ec
2 files changed
+24 -3

No files matched your search

@@ -92,6 +92,7 @@ public class EclipsePatcher extends Agent {
patchFixSourceTypeConverter(sm);
patchDisableLombokForCodeFormatterAndCleanup(sm);
patchListRewriteHandleGeneratedMethods(sm);
patchSyntaxAndOccurrencesHighlighting(sm);
} else {
patchPostCompileHookEcj(sm);
}
@@ -101,6 +102,20 @@ public class EclipsePatcher extends Agent {
if (reloadExistingClasses) sm.reloadClasses(instrumentation);
}
private static void patchSyntaxAndOccurrencesHighlighting(ScriptManager sm) {
/*
* 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"))
.target(new MethodTarget("org.eclipse.jdt.internal.ui.search.OccurrencesFinder", "addWrite"))
.target(new MethodTarget("org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingReconciler$PositionCollector", "visit", "boolean", "org.eclipse.jdt.core.dom.SimpleName"))
.decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode"))
.valueMethod(new Hook("lombok.eclipse.agent.PatchFixes", "returnFalse", "boolean", "java.lang.Object"))
.request(StackRequest.PARAM1)
.build());
}
private static void patchDisableLombokForCodeFormatterAndCleanup(ScriptManager sm) {
sm.addScript(ScriptBuilder.setSymbolDuringMethodCall()
@@ -43,16 +43,22 @@ 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;
}
public static int fixRetrieveStartingCatchPosition(int original, int start) {
return original == -1 ? start : original;
}