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

Quick Search    Search Deep

Source code: javax/ide/model/java/source/tree/TypeArgumentT.java


1   /*
2    * @(#)TypeArgumentT.java
3    */
4   
5   package javax.ide.model.java.source.tree;
6   import java.util.LinkedHashMap;
7   import java.util.Map;
8   import java.util.Set;
9   
10  /**
11   * A type argument for a type reference. </p>
12   *
13   * @author Andy Yu
14   * */
15  public interface TypeArgumentT
16    extends Tree
17  {
18    // ----------------------------------------------------------------------
19  
20    public static final TypeArgumentT[] EMPTY_ARRAY =
21      new TypeArgumentT[ 0 ];
22  
23    // ----------------------------------------------------------------------
24  
25    /**
26     * Gets the bound kind. <p/>
27     *
28     * <pre>
29     * EXACT. The exact type is specified.
30     * EXTENDS. Type specifies an "extends" bound. Only types that
31     *                extend the given bound are allowed.
32     * SUPER. Type specifies a "super" bound. Only super types of
33     *              the given bound are allowed.
34     * UNBOUNDED. No explicit bound. Implies "extends" java/lang/Object.
35     * </pre>
36     */
37    public BoundKind getBoundKind();
38  
39    /**
40     * Gets the bound's type reference. <p/>
41     *
42     * <pre>
43     * EXACT. Returns the specified type.
44     * EXTENDS. Returns the "extends" bound.
45     * SUPER. Returns the "super" bound.
46     * UNBOUNDED. Returns null.
47     * </pre>
48     *
49     * @return This element's type reference.
50     */
51    public TypeReferenceT getType();
52  
53    /**
54     * Unlinks the current source type and links the input element.
55     * 
56     * @param type The new type reference.
57     *
58     * @throws IllegalStateException if the input type is already linked.
59     */
60    public void setType( TypeReferenceT type );
61  
62  
63    // ----------------------------------------------------------------------
64  
65    /**
66     * In this version, this class is 1.4 compatible. In a later version,
67     * it will be redone as an enum. <p/>
68     *
69     * @author Andy Yu
70     */
71    public static final class BoundKind
72    {
73      /** <code>T</code> */
74      public static final int EXACT = 0;
75  
76      /** <code>? extends T</code> */
77      public static final int EXTENDS = 1;
78  
79      /** <code>? super T</code> */
80      public static final int SUPER = 2;
81  
82      /** <code>?</code> */
83      public static final int UNBOUNDED = 3;
84  
85  
86      // ----------------------------------------------------------------------
87  
88      private final int ordinal;
89      
90      private final String name;
91  
92      private BoundKind(int ordinal, String name)
93      {
94        this.ordinal = ordinal;
95        this.name = name;
96      }
97  
98      // ----------------------------------------------------------------------
99  
100     // Begin enum compatibility section.
101     
102     public String name()
103     {
104       return name;
105     }
106     
107     public String toString()
108     {
109       return name();
110     }
111     
112     public int ordinal()
113     {
114       return ordinal;
115     }
116     
117     public int hashCode()
118     {
119       return ordinal();
120     }
121     
122     public int compareTo(BoundKind other)
123     {
124       return ordinal() - other.ordinal();
125     }
126     
127     public boolean equals(Object other)
128     {
129       if (other instanceof BoundKind)
130       {
131         final BoundKind tk = (BoundKind) other;
132         return ordinal() == tk.ordinal();
133       }
134       
135       return false;
136     }
137 
138     public Class getDeclaringClass()
139     {
140       return BoundKind.class;
141     }
142 
143 
144     // ----------------------------------------------------------------------
145 
146     private static final Map values = new LinkedHashMap();
147 
148     private static final String[] BOUND_names =
149     {
150       "EXACT",
151       "EXTENDS",
152       "SUPER",
153       "UNBOUNDED",
154     };
155 
156     static
157     {
158       for ( int i = 0; i < 4; i++ )
159       {
160         final String name = BOUND_names[i];
161         values.put( name, new BoundKind(i, name ) );
162       }
163     }
164 
165     public static BoundKind valueOf(int ordinal)
166     {
167       return valueOf(null, BOUND_names[ordinal]);
168     }
169 
170     public static BoundKind valueOf(Class ignored, String name)
171     {
172       return (BoundKind) values.get(name);
173     }
174 
175     public static BoundKind[] values()
176     {
177       final Set entries = values.entrySet();
178       return (BoundKind[])entries.toArray(new BoundKind[entries.size()]);
179     }
180 
181 
182     // ----------------------------------------------------------------------
183   }
184 }