src/share/classes/com/sun/tools/javac/code/TypeTag.java

Tue, 30 Oct 2012 10:15:19 -0700

author
jjg
date
Tue, 30 Oct 2012 10:15:19 -0700
changeset 1381
23fe1a96bc0f
parent 1374
c002fdee76fd
child 1442
fcf89720ae71
permissions
-rw-r--r--

8001929: fix doclint errors in langtools doc comments
Reviewed-by: darcy

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

mercurial