aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse/TransformEclipseAST.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-09-21 03:18:38 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-09-21 03:18:38 +0200
commit2547ee7b97657a9401b07a99fd19b10606673ca3 (patch)
tree757e77357a1f8c85df17730677d14e2d05038840 /src/lombok/eclipse/TransformEclipseAST.java
parent62fa41e0eb4678e9569bfd9744bec06979e27c66 (diff)
downloadlombok-2547ee7b97657a9401b07a99fd19b10606673ca3.tar.gz
lombok-2547ee7b97657a9401b07a99fd19b10606673ca3.tar.bz2
lombok-2547ee7b97657a9401b07a99fd19b10606673ca3.zip
This is a fix for the auto-format. The fix is NOT ready for proper release - it does rather a lot of stack introspection which may slow things down far too much.
Diffstat (limited to 'src/lombok/eclipse/TransformEclipseAST.java')
-rw-r--r--src/lombok/eclipse/TransformEclipseAST.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lombok/eclipse/TransformEclipseAST.java b/src/lombok/eclipse/TransformEclipseAST.java
index 9bc3326f..365b65a2 100644
--- a/src/lombok/eclipse/TransformEclipseAST.java
+++ b/src/lombok/eclipse/TransformEclipseAST.java
@@ -22,6 +22,9 @@
package lombok.eclipse;
import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import lombok.eclipse.EclipseAST.Node;
@@ -69,6 +72,24 @@ public class TransformEclipseAST {
handlers = l;
}
+ private static final List<String> DONT_RUN_LIST = Collections.unmodifiableList(Arrays.asList(
+ "org.eclipse.jdt.internal.corext.util.CodeFormatterUtil."
+ ));
+
+
+ /**
+ * Returns 'true' if the stack trace indicates lombok definitely SHOULD run for this parse job, by checking the context,
+ * and returns 'false' if the stack trace indicates lombok should definitely NOT run.
+ *
+ * Returns null if it can't tell (you probably should default to running lombok if you don't know).
+ */
+ private static Boolean analyzeStackTrace(StackTraceElement[] trace) {
+ for ( StackTraceElement e : trace )
+ if ( e.toString().contains(DONT_RUN_LIST.get(0)) ) return false;
+ return null;
+ //potential speedup: if trace contains org.eclipse.swt.widgets. -> stop - nothing interesting ever follows that. I think.
+ }
+
/**
* This method is called immediately after Eclipse finishes building a CompilationUnitDeclaration, which is
* the top-level AST node when Eclipse parses a source file. The signature is 'magic' - you should not
@@ -82,6 +103,11 @@ public class TransformEclipseAST {
*/
public static void transform(Parser parser, CompilationUnitDeclaration ast) {
if ( disableLombok ) return;
+
+ Boolean parse = analyzeStackTrace(new Throwable().getStackTrace());
+
+ if ( parse != null && parse == false ) return;
+
try {
EclipseAST existing = getCache(ast);
if ( existing == null ) {