diff options
author | Roel Spilker <r.spilker@gmail.com> | 2010-11-06 16:41:17 +0100 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2010-11-06 16:41:17 +0100 |
commit | 0c7b29f8e7009d1433e2386f710c78801f119ebb (patch) | |
tree | 00c83f4ea3113cb07f4ce84cfd957dbc1f66124c /src/core/lombok/eclipse | |
parent | a48c335c7d8f1b361b134110219af8b0d3610101 (diff) | |
download | lombok-0c7b29f8e7009d1433e2386f710c78801f119ebb.tar.gz lombok-0c7b29f8e7009d1433e2386f710c78801f119ebb.tar.bz2 lombok-0c7b29f8e7009d1433e2386f710c78801f119ebb.zip |
Create Clinit if you create a static field and it doesn't yet exist
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r-- | src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 29937279..c37de8ea 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -23,6 +23,7 @@ package lombok.eclipse.handlers; import static lombok.eclipse.Eclipse.*; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -42,6 +43,7 @@ import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration; import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; import org.eclipse.jdt.internal.compiler.ast.Annotation; +import org.eclipse.jdt.internal.compiler.ast.Clinit; import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; import org.eclipse.jdt.internal.compiler.ast.EqualExpression; import org.eclipse.jdt.internal.compiler.ast.Expression; @@ -429,9 +431,24 @@ public class EclipseHandlerUtil { parent.fields = newArray; } + if ((field.modifiers & Modifier.STATIC) != 0) { + if (!hasClinit(parent)) { + parent.addClinit(); + } + } + type.add(field, Kind.FIELD).recursiveSetHandled(); } + private static boolean hasClinit(TypeDeclaration parent) { + if (parent.methods == null) return false; + + for (AbstractMethodDeclaration method : parent.methods) { + if (method instanceof Clinit) return true; + } + return false; + } + /** * Inserts a method into an existing type. The type must represent a {@code TypeDeclaration}. */ |