Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javax/ide/model/java/declaration/Declaration.java


1   /*
2    * @(#)Declaration.java
3    */
4   
5   package javax.ide.model.java.declaration;
6   
7   import java.util.HashMap;
8   import java.util.Map;
9   import java.util.Set;
10  import javax.ide.model.java.source.util.SourcePosition;
11  
12  /**
13   * Common supertype of all Mirror elements. A Mirror element
14   * represents a declarative element in Java.
15   *
16   * @author Andy Yu
17   */
18  public interface Declaration
19  {
20    // ----------------------------------------------------------------------
21  
22    /**
23     * Gets this Mirror's kind.
24     *
25     * @return This Mirror's kind.
26     */
27    public DeclarationKind getDeclarationKind();
28  
29    /**
30     * Gets the position in a source compilation unit that declares that
31     * declaration, null if none or if it could not be determined.
32     *
33     * @return Gets the position in a source compilation unit that
34     * declares this declaration, null if none or if it could not be
35     * determined.
36     */
37    public SourcePosition getPosition();
38  
39  
40    // ----------------------------------------------------------------------
41  
42    /**
43     * True if this is a synthetic element.
44     *
45     * @return True if this Mirror represents a synthetic element.
46     */
47    public boolean isSynthetic();
48  
49  
50    // ----------------------------------------------------------------------
51  
52    /**
53     * Identifies a Mirror.
54     */
55    public static final class DeclarationKind
56    {
57      public static final int DECL_base = 0;
58  
59      /** An annotation. AnnotationD. */
60      public static final int DECL_ANNOTATION = DECL_base + 0;
61  
62      /** A class, interface, enum, or annotation type. ClassD. */
63      public static final int DECL_CLASS = DECL_base + 1;
64  
65      /** A field or enum constant. ConstructorD. */
66      public static final int DECL_CONSTRUCTOR = DECL_base + 2;
67  
68      /** A field or enum constant. FieldD. */
69      public static final int DECL_FIELD = DECL_base + 3;
70  
71      /** A method, constructor, or annotation element. MethodD. */
72      public static final int DECL_METHOD = DECL_base + 4;
73      
74      /** A method, constructor, or annotation element. PackageD. */
75      public static final int DECL_PACKAGE = DECL_base + 5;
76      
77      /** A parameter. ParameterD. */
78      public static final int DECL_PARAMETER = DECL_base + 6;
79  
80      /** A type variable. TypeVariableD. */
81      public static final int DECL_TYPE_VARIABLE = DECL_base + 7;
82  
83      /** A wildcard type. WildcardTypeD. */
84      public static final int DECL_WILDCARD_TYPE = DECL_base + 8;
85  
86      ;
87  
88      public static final int DECL_max = DECL_base + 9;
89  
90      private final int ordinal;
91      
92      private final String name;
93  
94      private final Class declClass;
95  
96      private DeclarationKind(int ordinal, String name, Class c)
97      {
98        this.ordinal = ordinal;
99        this.name = name;
100       this.declClass = c;
101     }
102 
103     public Class getDeclarationClass()
104     {
105       return declClass;
106     }
107 
108 
109     // ----------------------------------------------------------------------
110 
111     // Begin enum compatibility section.
112     
113     public String name()
114     {
115       return name;
116     }
117     
118     public String toString()
119     {
120       return name();
121     }
122     
123     public int ordinal()
124     {
125       return ordinal;
126     }
127     
128     public int hashCode()
129     {
130       return ordinal();
131     }
132     
133     public int compareTo(DeclarationKind other)
134     {
135       return ordinal() - other.ordinal();
136     }
137     
138     public boolean equals(Object other)
139     {
140       if (other instanceof DeclarationKind)
141       {
142         final DeclarationKind tk = (DeclarationKind) other;
143         return ordinal() == tk.ordinal();
144       }
145       
146       return false;
147     }
148 
149     public Class getDeclaringClass()
150     {
151       return DeclarationKind.class;
152     }
153 
154 
155     // ----------------------------------------------------------------------
156 
157     private static final Map values = new HashMap();
158 
159     private static final String[] DECL_names =
160     {
161       "DECL_ANNOTATION",
162       "DECL_CLASS",
163       "DECL_CONSTRUCTOR",
164       "DECL_FIELD",
165       "DECL_METHOD",
166       "DECL_PACKAGE",
167       "DECL_PARAMETER",
168       "DECL_TYPE_VARIABLE",
169       "DECL_WILDCARD_TYPE",
170     };
171 
172     private static final Class[] DECL_classes =
173     {
174       AnnotationD.class,
175       ClassD.class,
176       ConstructorD.class,
177       FieldD.class,
178       MethodD.class,
179       PackageD.class,
180       ParameterD.class,
181       TypeVariableD.class,
182       WildcardTypeD.class,
183     };
184 
185     static
186     {
187       for ( int i = DECL_base; i < DECL_max; i++ )
188       {
189         final String name = DECL_names[i - DECL_base];
190         values.put( name, new DeclarationKind(i, name, DECL_classes[i-DECL_base]));
191       }
192     }
193 
194     public static DeclarationKind valueOf(int ordinal)
195     {
196       return valueOf(null, DECL_names[ordinal]);
197     }
198 
199     public static DeclarationKind valueOf(Class ignored, String name)
200     {
201       return (DeclarationKind) values.get(name);
202     }
203 
204     public static DeclarationKind[] values()
205     {
206       final Set entries = values.entrySet();
207       return (DeclarationKind[])
208         entries.toArray(new DeclarationKind[entries.size()]);
209     }
210 
211 
212     // ----------------------------------------------------------------------
213   }
214 }