1.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java Tue Oct 23 13:58:56 2012 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Thu Oct 25 11:09:36 2012 -0700 1.3 @@ -38,7 +38,7 @@ 1.4 import static com.sun.tools.javac.code.BoundKind.*; 1.5 import static com.sun.tools.javac.code.Flags.*; 1.6 import static com.sun.tools.javac.code.Kinds.*; 1.7 -import static com.sun.tools.javac.code.TypeTags.*; 1.8 +import static com.sun.tools.javac.code.TypeTag.*; 1.9 1.10 /** This class represents Java types. The class itself defines the behavior of 1.11 * the following types: 1.12 @@ -66,7 +66,7 @@ 1.13 * This code and its internal interfaces are subject to change or 1.14 * deletion without notice.</b> 1.15 * 1.16 - * @see TypeTags 1.17 + * @see TypeTag 1.18 */ 1.19 public class Type implements PrimitiveType { 1.20 1.21 @@ -83,15 +83,77 @@ 1.22 1.23 /** The tag of this type. 1.24 * 1.25 - * @see TypeTags 1.26 + * @see TypeTag 1.27 */ 1.28 - public int tag; 1.29 + protected TypeTag tag; 1.30 1.31 /** The defining class / interface / package / type variable 1.32 */ 1.33 public TypeSymbol tsym; 1.34 1.35 /** 1.36 + * Checks if the current type tag is equal to the given tag. 1.37 + * @return true if tag is equal to the current type tag. 1.38 + */ 1.39 + public boolean hasTag(TypeTag tag) { 1.40 + return this.tag == tag; 1.41 + } 1.42 + 1.43 + /** 1.44 + * Returns the current type tag. 1.45 + * @return the value of the current type tag. 1.46 + */ 1.47 + public TypeTag getTag() { 1.48 + return tag; 1.49 + } 1.50 + 1.51 + public boolean isNumeric() { 1.52 + switch (tag) { 1.53 + case BYTE: case CHAR: 1.54 + case SHORT: 1.55 + case INT: case LONG: 1.56 + case FLOAT: case DOUBLE: 1.57 + return true; 1.58 + default: 1.59 + return false; 1.60 + } 1.61 + } 1.62 + 1.63 + public boolean isPrimitive() { 1.64 + return (isNumeric() || tag == BOOLEAN); 1.65 + } 1.66 + 1.67 + public boolean isPrimitiveOrVoid() { 1.68 + return (isPrimitive() || tag == VOID); 1.69 + } 1.70 + 1.71 + public boolean isReference() { 1.72 + switch (tag) { 1.73 + case CLASS: 1.74 + case ARRAY: 1.75 + case TYPEVAR: 1.76 + case WILDCARD: 1.77 + case ERROR: 1.78 + return true; 1.79 + default: 1.80 + return false; 1.81 + } 1.82 + } 1.83 + 1.84 + public boolean isNullOrReference() { 1.85 + return (tag == BOT || isReference()); 1.86 + } 1.87 + 1.88 + public boolean isPartial() { 1.89 + switch(tag) { 1.90 + case ERROR: case UNKNOWN: case UNDETVAR: 1.91 + return true; 1.92 + default: 1.93 + return false; 1.94 + } 1.95 + } 1.96 + 1.97 + /** 1.98 * The constant value of this type, null if this type does not 1.99 * have a constant value attribute. Only primitive types and 1.100 * strings (ClassType) can have a constant value attribute. 1.101 @@ -121,7 +183,7 @@ 1.102 1.103 /** Define a type given its tag and type symbol 1.104 */ 1.105 - public Type(int tag, TypeSymbol tsym) { 1.106 + public Type(TypeTag tag, TypeSymbol tsym) { 1.107 this.tag = tag; 1.108 this.tsym = tsym; 1.109 } 1.110 @@ -162,7 +224,7 @@ 1.111 */ 1.112 public Type constType(Object constValue) { 1.113 final Object value = constValue; 1.114 - Assert.check(tag <= BOOLEAN); 1.115 + Assert.check(isPrimitive()); 1.116 return new Type(tag, tsym) { 1.117 @Override 1.118 public Object constValue() { 1.119 @@ -352,10 +414,6 @@ 1.120 return (tsym.flags() & FINAL) != 0; 1.121 } 1.122 1.123 - public boolean isPrimitive() { 1.124 - return tag < VOID; 1.125 - } 1.126 - 1.127 /** 1.128 * Does this type contain occurrences of type t? 1.129 */ 1.130 @@ -808,7 +866,7 @@ 1.131 } 1.132 1.133 public int hashCode() { 1.134 - return (ARRAY << 5) + elemtype.hashCode(); 1.135 + return (ARRAY.ordinal() << 5) + elemtype.hashCode(); 1.136 } 1.137 1.138 public boolean isVarargs() { 1.139 @@ -915,7 +973,7 @@ 1.140 } 1.141 1.142 public int hashCode() { 1.143 - int h = METHOD; 1.144 + int h = METHOD.ordinal(); 1.145 for (List<Type> thisargs = this.argtypes; 1.146 thisargs.tail != null; /*inlined: thisargs.nonEmpty()*/ 1.147 thisargs = thisargs.tail) 1.148 @@ -1099,7 +1157,7 @@ 1.149 1.150 public static abstract class DelegatedType extends Type { 1.151 public Type qtype; 1.152 - public DelegatedType(int tag, Type qtype) { 1.153 + public DelegatedType(TypeTag tag, Type qtype) { 1.154 super(tag, qtype.tsym); 1.155 this.qtype = qtype; 1.156 } 1.157 @@ -1285,7 +1343,7 @@ 1.158 /** Represents VOID or NONE. 1.159 */ 1.160 static class JCNoType extends Type implements NoType { 1.161 - public JCNoType(int tag) { 1.162 + public JCNoType(TypeTag tag) { 1.163 super(tag, null); 1.164 } 1.165 1.166 @@ -1307,7 +1365,7 @@ 1.167 1.168 static class BottomType extends Type implements NullType { 1.169 public BottomType() { 1.170 - super(TypeTags.BOT, null); 1.171 + super(BOT, null); 1.172 } 1.173 1.174 @Override