Mon, 17 Dec 2012 07:47:05 -0800
8004832: Add new doclint package
Reviewed-by: mcimadamore
1 /*
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.javac.code;
28 import com.sun.source.tree.Tree.Kind;
30 import javax.lang.model.type.TypeKind;
32 /** An interface for type tag values, which distinguish between different
33 * sorts of types.
34 *
35 * <p><b>This is NOT part of any supported API.
36 * If you write code that depends on this, you do so at your own risk.
37 * This code and its internal interfaces are subject to change or
38 * deletion without notice.</b>
39 */
40 public enum TypeTag {
41 /** The tag of the basic type `byte'.
42 */
43 BYTE(1),
45 /** The tag of the basic type `char'.
46 */
47 CHAR(2),
49 /** The tag of the basic type `short'.
50 */
51 SHORT(3),
53 /** The tag of the basic type `int'.
54 */
55 INT(4),
57 /** The tag of the basic type `long'.
58 */
59 LONG(5),
61 /** The tag of the basic type `float'.
62 */
63 FLOAT(6),
65 /** The tag of the basic type `double'.
66 */
67 DOUBLE(7),
69 /** The tag of the basic type `boolean'.
70 */
71 BOOLEAN,
73 /** The tag of the type `void'.
74 */
75 VOID,
77 /** The tag of all class and interface types.
78 */
79 CLASS,
81 /** The tag of all array types.
82 */
83 ARRAY,
85 /** The tag of all (monomorphic) method types.
86 */
87 METHOD,
89 /** The tag of all package "types".
90 */
91 PACKAGE,
93 /** The tag of all (source-level) type variables.
94 */
95 TYPEVAR,
97 /** The tag of all type arguments.
98 */
99 WILDCARD,
101 /** The tag of all polymorphic (method-) types.
102 */
103 FORALL,
105 /** The tag of deferred expression types in method context
106 */
107 DEFERRED,
109 /** The tag of the bottom type {@code <null>}.
110 */
111 BOT,
113 /** The tag of a missing type.
114 */
115 NONE,
117 /** The tag of the error type.
118 */
119 ERROR,
121 /** The tag of an unknown type
122 */
123 UNKNOWN,
125 /** The tag of all instantiatable type variables.
126 */
127 UNDETVAR,
129 /** Pseudo-types, these are special tags
130 */
131 UNINITIALIZED_THIS,
133 UNINITIALIZED_OBJECT;
135 /** This field will only be used for tags related with numeric types for
136 * optimization reasons.
137 */
138 private final int order;
140 private TypeTag() {
141 this(0);
142 }
144 private TypeTag(int order) {
145 this.order = order;
146 }
148 private static final int MIN_NUMERIC_TAG_ORDER = 1;
149 private static final int MAX_NUMERIC_TAG_ORDER = 7;
151 /** Returns the number of type tags.
152 */
153 public static int getTypeTagCount() {
154 // last two tags are not included in the total as long as they are pseudo-types
155 return (UNDETVAR.ordinal() + 1);
156 }
158 public boolean isSubRangeOf(TypeTag range) {
159 return (this == range) || isStrictSubRangeOf(range);
160 }
162 public boolean isStrictSubRangeOf(TypeTag range) {
163 if (this.order >= MIN_NUMERIC_TAG_ORDER && this.order <= MAX_NUMERIC_TAG_ORDER &&
164 range.order >= MIN_NUMERIC_TAG_ORDER && this.order <= MAX_NUMERIC_TAG_ORDER) {
165 if (this == range)
166 return false;
167 switch (this) {
168 case BYTE:
169 return true;
170 case CHAR: case SHORT: case INT:
171 case LONG: case FLOAT:
172 return this.order < range.order && range.order <= MAX_NUMERIC_TAG_ORDER;
173 default:
174 return false;
175 }
176 }
177 else
178 return false;
179 }
181 public Kind getKindLiteral() {
182 switch (this) {
183 case INT:
184 return Kind.INT_LITERAL;
185 case LONG:
186 return Kind.LONG_LITERAL;
187 case FLOAT:
188 return Kind.FLOAT_LITERAL;
189 case DOUBLE:
190 return Kind.DOUBLE_LITERAL;
191 case BOOLEAN:
192 return Kind.BOOLEAN_LITERAL;
193 case CHAR:
194 return Kind.CHAR_LITERAL;
195 case CLASS:
196 return Kind.STRING_LITERAL;
197 case BOT:
198 return Kind.NULL_LITERAL;
199 default:
200 throw new AssertionError("unknown literal kind " + this);
201 }
202 }
204 public TypeKind getPrimitiveTypeKind() {
205 switch (this) {
206 case BOOLEAN:
207 return TypeKind.BOOLEAN;
208 case BYTE:
209 return TypeKind.BYTE;
210 case SHORT:
211 return TypeKind.SHORT;
212 case INT:
213 return TypeKind.INT;
214 case LONG:
215 return TypeKind.LONG;
216 case CHAR:
217 return TypeKind.CHAR;
218 case FLOAT:
219 return TypeKind.FLOAT;
220 case DOUBLE:
221 return TypeKind.DOUBLE;
222 case VOID:
223 return TypeKind.VOID;
224 default:
225 throw new AssertionError("unknown primitive type " + this);
226 }
227 }
228 }