Skip to content

Commit

Permalink
[FORGE-1090] EnumConstant should support constructor arguments; [FORG…
Browse files Browse the repository at this point in the history
…E-1091] EnumConstant should support anonymous subclass body
  • Loading branch information
mbenson committed Aug 5, 2013
1 parent 31d9cb3 commit 6e6209e
Show file tree
Hide file tree
Showing 5 changed files with 950 additions and 2 deletions.
30 changes: 29 additions & 1 deletion api/src/main/java/org/jboss/forge/parser/java/EnumConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,47 @@
*/
package org.jboss.forge.parser.java;

import java.util.List;

import org.jboss.forge.parser.Internal;
import org.jboss.forge.parser.Origin;

public interface EnumConstant<O extends JavaSource<O>> extends Internal, Origin<O>,
AnnotationTarget<O, EnumConstant<O>>
{
/**
* Represents the anonymous subclass "body" of an enum constant.
*/
public interface Body extends JavaSource<Body>, FieldHolder<Body>, MethodHolder<Body> {
}

/**
* Get this enum constant name.
*/
String getName();

/**
* Set this enum constant name.
*/
EnumConstant<O> setName(String name);

/**
* Get the constructor arguments of this enum constant.
*/
List<String> getConstructorArguments();

/**
* Set the constructor arguments for this enum constant.
*/
EnumConstant<O> setConstructorArguments(String... literalArguments);

/**
* Get the {@link Body} of this enum constant.
*/
Body getBody();

/**
* Remove the {@link Body} of this enum constant.
*/
EnumConstant<O> removeBody();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.EnumDeclaration;
import org.eclipse.jdt.core.dom.MethodDeclaration;
Expand Down Expand Up @@ -51,6 +52,16 @@ public boolean visit(AnnotationTypeDeclaration node)
return super.visit(node);
}

@Override
public boolean visit(AnonymousClassDeclaration node)
{
parent = node;
@SuppressWarnings("unchecked")
final List<BodyDeclaration> bodyDeclarations = node.bodyDeclarations();
addMethods(bodyDeclarations);
return super.visit(node);
}

public List<MethodDeclaration> getMethods()
{
return Collections.unmodifiableList(methods);
Expand All @@ -65,6 +76,11 @@ private void addMethods(AbstractTypeDeclaration node)
{
@SuppressWarnings("unchecked")
final List<BodyDeclaration> bodyDeclarations = node.bodyDeclarations();
addMethods(bodyDeclarations);
}

private void addMethods(final List<BodyDeclaration> bodyDeclarations)
{
for (BodyDeclaration bodyDeclaration : bodyDeclarations)
{
if (bodyDeclaration instanceof MethodDeclaration) {
Expand Down
Loading

0 comments on commit 6e6209e

Please sign in to comment.