aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse
diff options
context:
space:
mode:
authorpeichhorn <peichhor@web.de>2011-11-13 09:02:55 +0100
committerpeichhorn <peichhor@web.de>2011-11-13 09:06:57 +0100
commit0d75d56fcef943d1a35f1169386830066371c12d (patch)
treee274449da3344e8ba1e09da5878b5e4a2a51d5db /src/core/lombok/eclipse
parentfb4d2a45d21ed33405f8c2eddb05da6040ee3159 (diff)
downloadlombok-0d75d56fcef943d1a35f1169386830066371c12d.tar.gz
lombok-0d75d56fcef943d1a35f1169386830066371c12d.tar.bz2
lombok-0d75d56fcef943d1a35f1169386830066371c12d.zip
Eclipse/JavacHandlerUtil.injectField(...) inserts the new fields after the enum constants.
Also the new fields are ordered in the same way the method injectField() gets invoked.
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java18
1 files changed, 15 insertions, 3 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}.
*/