Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

FORGE-570

  • Loading branch information...
commit 30de564201edcc152453db034b8d2845f5d80ab9 1 parent 8162d2f
@gastaldi gastaldi authored
View
25 ...r-java/src/main/java/org/jboss/forge/parser/java/impl/AbstractJavaSourceMemberHolder.java
@@ -29,12 +29,13 @@
/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
+ *
*/
public abstract class AbstractJavaSourceMemberHolder<O extends JavaSource<O>> extends AbstractJavaSource<O> implements
MethodHolder<O>, FieldHolder<O>
{
- public AbstractJavaSourceMemberHolder(JavaSource<?> enclosingType, final Document document, final CompilationUnit unit, BodyDeclaration declaration)
+ public AbstractJavaSourceMemberHolder(JavaSource<?> enclosingType, final Document document,
+ final CompilationUnit unit, BodyDeclaration declaration)
{
super(enclosingType, document, unit, declaration);
}
@@ -47,7 +48,7 @@ public AbstractJavaSourceMemberHolder(JavaSource<?> enclosingType, final Documen
public Field<O> addField()
{
Field<O> field = new FieldImpl<O>((O) this);
- getBodyDeclaration().bodyDeclarations().add(field.getInternal());
+ addField(field);
return field;
}
@@ -56,10 +57,26 @@ public AbstractJavaSourceMemberHolder(JavaSource<?> enclosingType, final Documen
public Field<O> addField(final String declaration)
{
Field<O> field = new FieldImpl<O>((O) this, declaration);
- getBodyDeclaration().bodyDeclarations().add(field.getInternal());
+ addField(field);
return field;
}
+ @SuppressWarnings("unchecked")
+ private void addField(Field<O> field)
+ {
+ List<Object> bodyDeclarations = getBodyDeclaration().bodyDeclarations();
+ int idx = 0;
+ for (Object object : bodyDeclarations)
+ {
+ if (!(object instanceof FieldDeclaration))
+ {
+ break;
+ }
+ idx++;
+ }
+ bodyDeclarations.add(idx, field.getInternal());
+ }
+
@Override
public List<Member<O, ?>> getMembers()
{
Please sign in to comment.
Something went wrong with that request. Please try again.