1 11 12 package org.eclipse.jdt.apt.core.internal.declaration; 13 14 15 import com.sun.mirror.declaration.Declaration; 16 import com.sun.mirror.declaration.EnumConstantDeclaration; 17 import com.sun.mirror.declaration.EnumDeclaration; 18 import com.sun.mirror.type.EnumType; 19 import com.sun.mirror.util.DeclarationVisitor; 20 import com.sun.mirror.util.TypeVisitor; 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.List ; 24 25 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv; 26 import org.eclipse.jdt.apt.core.internal.util.Factory; 27 import org.eclipse.jdt.core.dom.ITypeBinding; 28 import org.eclipse.jdt.core.dom.IVariableBinding; 29 30 public class EnumDeclarationImpl extends ClassDeclarationImpl implements EnumDeclaration, EnumType 31 { 32 public EnumDeclarationImpl(final ITypeBinding binding, final BaseProcessorEnv env) 33 { 34 super(binding, env); 35 assert binding.isEnum() : "binding is not an enum."; } 37 38 public void accept(DeclarationVisitor visitor) 39 { 40 visitor.visitEnumDeclaration(this); 41 } 42 43 public Collection <EnumConstantDeclaration> getEnumConstants() 44 { 45 final ITypeBinding enumBinding = getDeclarationBinding(); 46 final IVariableBinding[] fields = enumBinding.getDeclaredFields(); 47 final List <EnumConstantDeclaration> results = new ArrayList <EnumConstantDeclaration>(4); 48 for( IVariableBinding field : fields ){ 49 if( field.isEnumConstant() ){ 50 final Declaration mirrorDecl = Factory.createDeclaration(field, _env); 51 if( mirrorDecl != null ) 52 results.add((EnumConstantDeclaration)mirrorDecl); 53 } 54 } 55 return results; 56 } 57 58 60 public void accept(TypeVisitor visitor) 62 { 63 visitor.visitEnumType(this); 64 } 65 66 public EnumDeclaration getDeclaration() 67 { 68 return (EnumDeclaration)super.getDeclaration(); 69 } 70 71 public MirrorKind kind(){ return MirrorKind.TYPE_ENUM; } 72 } 73 | Popular Tags |