KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > apt > core > internal > declaration > EnumDeclarationImpl


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * tyeung@bea.com - initial API and implementation
10  *******************************************************************************/

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 JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.List JavaDoc;
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."; //$NON-NLS-1$
36
}
37
38     public void accept(DeclarationVisitor visitor)
39     {
40         visitor.visitEnumDeclaration(this);
41     }
42
43     public Collection JavaDoc<EnumConstantDeclaration> getEnumConstants()
44     {
45         final ITypeBinding enumBinding = getDeclarationBinding();
46         final IVariableBinding[] fields = enumBinding.getDeclaredFields();
47         final List JavaDoc<EnumConstantDeclaration> results = new ArrayList JavaDoc<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     // start of implementation of EnumType API
59

60     // end of implementation of EnumType API
61
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