aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java18
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java26
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java21
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java10
4 files changed, 71 insertions, 4 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 7f144c17..96dea22d 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -1013,9 +1013,17 @@ public class EclipseHandlerUtil {
parent.fields = new FieldDeclaration[1];
parent.fields[0] = field;
} else {
- FieldDeclaration[] newArray = new FieldDeclaration[parent.fields.length + 1];
- System.arraycopy(parent.fields, 0, newArray, 1, parent.fields.length);
- newArray[0] = field;
+ int size = parent.fields.length;
+ FieldDeclaration[] newArray = new FieldDeclaration[size + 1];
+ System.arraycopy(parent.fields, 0, newArray, 0, size);
+ int index = 0;
+ for (; index < size; index++) {
+ FieldDeclaration f = newArray[index];
+ if (isEnumConstant(f) || isGenerated(f)) continue;
+ break;
+ }
+ System.arraycopy(newArray, index, newArray, index + 1, size - index);
+ newArray[index] = field;
parent.fields = newArray;
}
@@ -1028,6 +1036,10 @@ public class EclipseHandlerUtil {
type.add(field, Kind.FIELD);
}
+ private static boolean isEnumConstant(final FieldDeclaration field) {
+ return ((field.initialization instanceof AllocationExpression) && (((AllocationExpression) field.initialization).enumConstant == field));
+ }
+
/**
* Inserts a method into an existing type. The type must represent a {@code TypeDeclaration}.
*/
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 00090be9..fc9435d8 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -532,11 +532,35 @@ public class JavacHandlerUtil {
JCClassDecl type = (JCClassDecl) typeNode.get();
if (addSuppressWarnings) addSuppressWarningsAll(field.mods, typeNode, field.pos, getGeneratedBy(field));
- type.defs = type.defs.append(field);
+
+ List<JCTree> insertAfter = null;
+ List<JCTree> insertBefore = type.defs;
+ while (insertBefore.tail != null) {
+ if (insertBefore.head instanceof JCVariableDecl) {
+ JCVariableDecl f = (JCVariableDecl) insertBefore.head;
+ if (isEnumConstant(f) || isGenerated(f)) {
+ insertAfter = insertBefore;
+ insertBefore = insertBefore.tail;
+ continue;
+ }
+ }
+ break;
+ }
+ List<JCTree> fieldEntry = List.<JCTree>of(field);
+ fieldEntry.tail = insertBefore;
+ if (insertAfter == null) {
+ type.defs = fieldEntry;
+ } else {
+ insertAfter.tail = fieldEntry;
+ }
typeNode.add(field, Kind.FIELD);
}
+ private static boolean isEnumConstant(final JCVariableDecl field) {
+ return (field.mods.flags & Flags.ENUM) != 0;
+ }
+
/**
* Adds the given new method declaration to the provided type AST Node.
* Can also inject constructors.
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
index b52a3b23..3a85c6e9 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
@@ -89,6 +89,7 @@ public class EclipsePatcher extends Agent {
patchHideGeneratedNodes(sm);
patchPostCompileHookEclipse(sm);
patchFixSourceTypeConverter(sm);
+ patchDisableLombokForCodeFormatterAndCleanup(sm);
} else {
patchPostCompileHookEcj(sm);
}
@@ -99,6 +100,26 @@ public class EclipsePatcher extends Agent {
if (reloadExistingClasses) sm.reloadClasses(instrumentation);
}
+ private static void patchDisableLombokForCodeFormatterAndCleanup(ScriptManager sm) {
+ sm.addScript(ScriptBuilder.setSymbolDuringMethodCall()
+ .target(new MethodTarget("org.eclipse.jdt.internal.formatter.DefaultCodeFormatter", "formatCompilationUnit"))
+ .callToWrap(new Hook("org.eclipse.jdt.internal.core.util.CodeSnippetParsingUtil", "parseCompilationUnit", "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration", "char[]", "java.util.Map", "boolean"))
+ .symbol("lombok.disable")
+ .build());
+
+ sm.addScript(ScriptBuilder.exitEarly()
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.ControlStatementsFix$ControlStatementFinder", "visit", "boolean", "org.eclipse.jdt.core.dom.DoStatement"))
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.ControlStatementsFix$ControlStatementFinder", "visit", "boolean", "org.eclipse.jdt.core.dom.EnhancedForStatement"))
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.ControlStatementsFix$ControlStatementFinder", "visit", "boolean", "org.eclipse.jdt.core.dom.ForStatement"))
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.ControlStatementsFix$ControlStatementFinder", "visit", "boolean", "org.eclipse.jdt.core.dom.IfStatement"))
+ .target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.ControlStatementsFix$ControlStatementFinder", "visit", "boolean", "org.eclipse.jdt.core.dom.WhileStatement"))
+ .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.Statement"))
+ .request(StackRequest.PARAM1)
+ .valueMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.Statement"))
+ .build());
+ }
+
+
private static void patchDomAstReparseIssues(ScriptManager sm) {
sm.addScript(ScriptBuilder.replaceMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer", "visit"))
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java
index 6d5fdaec..8da7f668 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java
@@ -41,6 +41,16 @@ import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner;
public class PatchFixes {
+ public static boolean isGenerated(org.eclipse.jdt.core.dom.Statement statement) {
+ boolean result = false;
+ try {
+ result = ((Boolean)statement.getClass().getField("$isGenerated").get(statement)).booleanValue();
+ } catch (Exception e) {
+ // better to assume it isn't generated
+ }
+ return result;
+ }
+
public static int fixRetrieveStartingCatchPosition(int original, int start) {
return original == -1 ? start : original;
}