src/share/classes/com/sun/tools/javac/comp/Check.java

changeset 1374
c002fdee76fd
parent 1366
12cf6bfd8c05
child 1384
bf54daa9dcd8
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Oct 23 13:58:56 2012 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Oct 25 11:09:36 2012 -0700
     1.3 @@ -48,8 +48,8 @@
     1.4  import static com.sun.tools.javac.code.Flags.ANNOTATION;
     1.5  import static com.sun.tools.javac.code.Flags.SYNCHRONIZED;
     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.TypeTags.WILDCARD;
     1.9 +import static com.sun.tools.javac.code.TypeTag.*;
    1.10 +import static com.sun.tools.javac.code.TypeTag.WILDCARD;
    1.11  
    1.12  import static com.sun.tools.javac.tree.JCTree.Tag.*;
    1.13  
    1.14 @@ -280,7 +280,7 @@
    1.15      Type typeTagError(DiagnosticPosition pos, Object required, Object found) {
    1.16          // this error used to be raised by the parser,
    1.17          // but has been delayed to this point:
    1.18 -        if (found instanceof Type && ((Type)found).tag == VOID) {
    1.19 +        if (found instanceof Type && ((Type)found).hasTag(VOID)) {
    1.20              log.error(pos, "illegal.start.of.type");
    1.21              return syms.errType;
    1.22          }
    1.23 @@ -358,7 +358,7 @@
    1.24              for (Scope.Entry e = s.next.lookup(c.name);
    1.25                   e.scope != null && e.sym.owner == c.owner;
    1.26                   e = e.next()) {
    1.27 -                if (e.sym.kind == TYP && e.sym.type.tag != TYPEVAR &&
    1.28 +                if (e.sym.kind == TYP && !e.sym.type.hasTag(TYPEVAR) &&
    1.29                      (e.sym.owner.kind & (VAR | MTH)) != 0 &&
    1.30                      c.name != names.error) {
    1.31                      duplicateError(pos, e.sym);
    1.32 @@ -527,14 +527,14 @@
    1.33                  }
    1.34              });
    1.35          }
    1.36 -        if (req.tag == ERROR)
    1.37 +        if (req.hasTag(ERROR))
    1.38              return req;
    1.39 -        if (req.tag == NONE)
    1.40 +        if (req.hasTag(NONE))
    1.41              return found;
    1.42          if (checkContext.compatible(found, req, checkContext.checkWarner(pos, found, req))) {
    1.43              return found;
    1.44          } else {
    1.45 -            if (found.tag <= DOUBLE && req.tag <= DOUBLE) {
    1.46 +            if (found.getTag().isSubRangeOf(DOUBLE) && req.getTag().isSubRangeOf(DOUBLE)) {
    1.47                  checkContext.report(pos, diags.fragment("possible.loss.of.precision", found, req));
    1.48                  return types.createErrorType(found);
    1.49              }
    1.50 @@ -594,7 +594,7 @@
    1.51           *  type variables?
    1.52           */
    1.53          boolean isTypeVar(Type t) {
    1.54 -            return t.tag == TYPEVAR || t.tag == ARRAY && isTypeVar(types.elemtype(t));
    1.55 +            return t.hasTag(TYPEVAR) || t.hasTag(ARRAY) && isTypeVar(types.elemtype(t));
    1.56          }
    1.57  
    1.58      /** Check that a type is within some bounds.
    1.59 @@ -607,7 +607,7 @@
    1.60      private boolean checkExtends(Type a, Type bound) {
    1.61           if (a.isUnbound()) {
    1.62               return true;
    1.63 -         } else if (a.tag != WILDCARD) {
    1.64 +         } else if (!a.hasTag(WILDCARD)) {
    1.65               a = types.upperBound(a);
    1.66               return types.isSubtype(a, bound);
    1.67           } else if (a.isExtendsBound()) {
    1.68 @@ -623,7 +623,7 @@
    1.69       *  @param t             The type to be checked.
    1.70       */
    1.71      Type checkNonVoid(DiagnosticPosition pos, Type t) {
    1.72 -        if (t.tag == VOID) {
    1.73 +        if (t.hasTag(VOID)) {
    1.74              log.error(pos, "void.not.allowed.here");
    1.75              return types.createErrorType(t);
    1.76          } else {
    1.77 @@ -636,10 +636,10 @@
    1.78       *  @param t             The type to be checked.
    1.79       */
    1.80      Type checkClassType(DiagnosticPosition pos, Type t) {
    1.81 -        if (t.tag != CLASS && t.tag != ERROR)
    1.82 +        if (!t.hasTag(CLASS) && !t.hasTag(ERROR))
    1.83              return typeTagError(pos,
    1.84                                  diags.fragment("type.req.class"),
    1.85 -                                (t.tag == TYPEVAR)
    1.86 +                                (t.hasTag(TYPEVAR))
    1.87                                  ? diags.fragment("type.parameter", t)
    1.88                                  : t);
    1.89          else
    1.90 @@ -650,7 +650,7 @@
    1.91       */
    1.92      Type checkConstructorRefType(DiagnosticPosition pos, Type t) {
    1.93          t = checkClassType(pos, t);
    1.94 -        if (t.tag == CLASS) {
    1.95 +        if (t.hasTag(CLASS)) {
    1.96              if ((t.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) {
    1.97                  log.error(pos, "abstract.cant.be.instantiated");
    1.98                  t = types.createErrorType(t);
    1.99 @@ -672,7 +672,7 @@
   1.100          if (noBounds && t.isParameterized()) {
   1.101              List<Type> args = t.getTypeArguments();
   1.102              while (args.nonEmpty()) {
   1.103 -                if (args.head.tag == WILDCARD)
   1.104 +                if (args.head.hasTag(WILDCARD))
   1.105                      return typeTagError(pos,
   1.106                                          diags.fragment("type.req.exact"),
   1.107                                          args.head);
   1.108 @@ -687,7 +687,7 @@
   1.109       *  @param t             The type to be checked.
   1.110       */
   1.111      Type checkReifiableReferenceType(DiagnosticPosition pos, Type t) {
   1.112 -        if (t.tag != CLASS && t.tag != ARRAY && t.tag != ERROR) {
   1.113 +        if (!t.hasTag(CLASS) && !t.hasTag(ARRAY) && !t.hasTag(ERROR)) {
   1.114              return typeTagError(pos,
   1.115                                  diags.fragment("type.req.class.array"),
   1.116                                  t);
   1.117 @@ -705,18 +705,12 @@
   1.118       *  @param t             The type to be checked.
   1.119       */
   1.120      Type checkRefType(DiagnosticPosition pos, Type t) {
   1.121 -        switch (t.tag) {
   1.122 -        case CLASS:
   1.123 -        case ARRAY:
   1.124 -        case TYPEVAR:
   1.125 -        case WILDCARD:
   1.126 -        case ERROR:
   1.127 +        if (t.isReference())
   1.128              return t;
   1.129 -        default:
   1.130 +        else
   1.131              return typeTagError(pos,
   1.132                                  diags.fragment("type.req.ref"),
   1.133                                  t);
   1.134 -        }
   1.135      }
   1.136  
   1.137      /** Check that each type is a reference type, i.e. a class, interface or array type
   1.138 @@ -738,19 +732,12 @@
   1.139       *  @param t             The type to be checked.
   1.140       */
   1.141      Type checkNullOrRefType(DiagnosticPosition pos, Type t) {
   1.142 -        switch (t.tag) {
   1.143 -        case CLASS:
   1.144 -        case ARRAY:
   1.145 -        case TYPEVAR:
   1.146 -        case WILDCARD:
   1.147 -        case BOT:
   1.148 -        case ERROR:
   1.149 +        if (t.isNullOrReference())
   1.150              return t;
   1.151 -        default:
   1.152 +        else
   1.153              return typeTagError(pos,
   1.154                                  diags.fragment("type.req.ref"),
   1.155                                  t);
   1.156 -        }
   1.157      }
   1.158  
   1.159      /** Check that flag set does not contain elements of two conflicting sets. s
   1.160 @@ -1054,7 +1041,7 @@
   1.161              bounds = bounds_buf.toList();
   1.162  
   1.163              for (Type arg : types.capture(type).getTypeArguments()) {
   1.164 -                if (arg.tag == TYPEVAR &&
   1.165 +                if (arg.hasTag(TYPEVAR) &&
   1.166                          arg.getUpperBound().isErroneous() &&
   1.167                          !bounds.head.isErroneous() &&
   1.168                          !isTypeArgErroneous(args.head)) {
   1.169 @@ -1309,7 +1296,7 @@
   1.170  
   1.171          @Override
   1.172          public void visitTypeApply(JCTypeApply tree) {
   1.173 -            if (tree.type.tag == CLASS) {
   1.174 +            if (tree.type.hasTag(CLASS)) {
   1.175                  List<JCExpression> args = tree.arguments;
   1.176                  List<Type> forms = tree.type.tsym.type.getTypeArguments();
   1.177  
   1.178 @@ -1360,7 +1347,7 @@
   1.179  
   1.180          @Override
   1.181          public void visitSelect(JCFieldAccess tree) {
   1.182 -            if (tree.type.tag == CLASS) {
   1.183 +            if (tree.type.hasTag(CLASS)) {
   1.184                  visitSelectInternal(tree);
   1.185  
   1.186                  // Check that this type is either fully parameterized, or
   1.187 @@ -1409,7 +1396,7 @@
   1.188  
   1.189          void checkRaw(JCTree tree, Env<AttrContext> env) {
   1.190              if (lint.isEnabled(LintCategory.RAW) &&
   1.191 -                tree.type.tag == CLASS &&
   1.192 +                tree.type.hasTag(CLASS) &&
   1.193                  !TreeInfo.isDiamond(tree) &&
   1.194                  !withinAnonConstr(env) &&
   1.195                  tree.type.isRaw()) {
   1.196 @@ -1511,9 +1498,9 @@
   1.197       */
   1.198      boolean isUnchecked(Type exc) {
   1.199          return
   1.200 -            (exc.tag == TYPEVAR) ? isUnchecked(types.supertype(exc)) :
   1.201 -            (exc.tag == CLASS) ? isUnchecked((ClassSymbol)exc.tsym) :
   1.202 -            exc.tag == BOT;
   1.203 +            (exc.hasTag(TYPEVAR)) ? isUnchecked(types.supertype(exc)) :
   1.204 +            (exc.hasTag(CLASS)) ? isUnchecked((ClassSymbol)exc.tsym) :
   1.205 +            exc.hasTag(BOT);
   1.206      }
   1.207  
   1.208      /** Same, but handling completion failures.
   1.209 @@ -1759,7 +1746,7 @@
   1.210              // case, we will have dealt with when examining the supertype classes
   1.211              ClassSymbol mc = m.enclClass();
   1.212              Type st = types.supertype(origin.type);
   1.213 -            if (st.tag != CLASS)
   1.214 +            if (!st.hasTag(CLASS))
   1.215                  return true;
   1.216              MethodSymbol stimpl = m.implementation((ClassSymbol)st.tsym, types, false);
   1.217  
   1.218 @@ -1782,7 +1769,7 @@
   1.219       */
   1.220      public void checkCompatibleConcretes(DiagnosticPosition pos, Type site) {
   1.221          Type sup = types.supertype(site);
   1.222 -        if (sup.tag != CLASS) return;
   1.223 +        if (!sup.hasTag(CLASS)) return;
   1.224  
   1.225          for (Type t1 = sup;
   1.226               t1.tsym.type.isParameterized();
   1.227 @@ -1803,7 +1790,7 @@
   1.228                  if (st1 == s1.type) continue;
   1.229  
   1.230                  for (Type t2 = sup;
   1.231 -                     t2.tag == CLASS;
   1.232 +                     t2.hasTag(CLASS);
   1.233                       t2 = types.supertype(t2)) {
   1.234                      for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name);
   1.235                           e2.scope != null;
   1.236 @@ -1876,7 +1863,7 @@
   1.237  
   1.238      /** Compute all the supertypes of t, indexed by type symbol. */
   1.239      private void closure(Type t, Map<TypeSymbol,Type> typeMap) {
   1.240 -        if (t.tag != CLASS) return;
   1.241 +        if (!t.hasTag(CLASS)) return;
   1.242          if (typeMap.put(t.tsym, t) == null) {
   1.243              closure(types.supertype(t), typeMap);
   1.244              for (Type i : types.interfaces(t))
   1.245 @@ -1886,7 +1873,7 @@
   1.246  
   1.247      /** Compute all the supertypes of t, indexed by type symbol (except thise in typesSkip). */
   1.248      private void closure(Type t, Map<TypeSymbol,Type> typesSkip, Map<TypeSymbol,Type> typeMap) {
   1.249 -        if (t.tag != CLASS) return;
   1.250 +        if (!t.hasTag(CLASS)) return;
   1.251          if (typesSkip.get(t.tsym) != null) return;
   1.252          if (typeMap.put(t.tsym, t) == null) {
   1.253              closure(types.supertype(t), typesSkip, typeMap);
   1.254 @@ -1916,7 +1903,8 @@
   1.255                      Type rt2 = types.subst(st2.getReturnType(), tvars2, tvars1);
   1.256                      boolean compat =
   1.257                          types.isSameType(rt1, rt2) ||
   1.258 -                        rt1.tag >= CLASS && rt2.tag >= CLASS &&
   1.259 +                        !rt1.isPrimitiveOrVoid() &&
   1.260 +                        !rt2.isPrimitiveOrVoid() &&
   1.261                          (types.covariantReturnType(rt1, rt2, Warner.noWarnings) ||
   1.262                           types.covariantReturnType(rt2, rt1, Warner.noWarnings)) ||
   1.263                           checkCommonOverriderIn(s1,s2,site);
   1.264 @@ -1961,7 +1949,8 @@
   1.265                      Type rt13 = types.subst(st3.getReturnType(), tvars3, tvars1);
   1.266                      Type rt23 = types.subst(st3.getReturnType(), tvars3, tvars2);
   1.267                      boolean compat =
   1.268 -                        rt13.tag >= CLASS && rt23.tag >= CLASS &&
   1.269 +                        !rt13.isPrimitiveOrVoid() &&
   1.270 +                        !rt23.isPrimitiveOrVoid() &&
   1.271                          (types.covariantReturnType(rt13, rt1, Warner.noWarnings) &&
   1.272                           types.covariantReturnType(rt23, rt2, Warner.noWarnings));
   1.273                      if (compat)
   1.274 @@ -1984,7 +1973,7 @@
   1.275                  log.error(tree.pos(), "enum.no.finalize");
   1.276                  return;
   1.277              }
   1.278 -        for (Type t = origin.type; t.tag == CLASS;
   1.279 +        for (Type t = origin.type; t.hasTag(CLASS);
   1.280               t = types.supertype(t)) {
   1.281              if (t != origin.type) {
   1.282                  checkOverride(tree, t, origin, m);
   1.283 @@ -2064,7 +2053,7 @@
   1.284                  }
   1.285                  if (undef == null) {
   1.286                      Type st = types.supertype(c.type);
   1.287 -                    if (st.tag == CLASS)
   1.288 +                    if (st.hasTag(CLASS))
   1.289                          undef = firstUndef(impl, (ClassSymbol)st.tsym);
   1.290                  }
   1.291                  for (List<Type> l = types.interfaces(c.type);
   1.292 @@ -2155,7 +2144,7 @@
   1.293              } else if (!c.type.isErroneous()) {
   1.294                  try {
   1.295                      seenClasses = seenClasses.prepend(c);
   1.296 -                    if (c.type.tag == CLASS) {
   1.297 +                    if (c.type.hasTag(CLASS)) {
   1.298                          if (supertypes.nonEmpty()) {
   1.299                              scan(supertypes);
   1.300                          }
   1.301 @@ -2200,13 +2189,13 @@
   1.302  
   1.303      private void checkNonCyclic1(DiagnosticPosition pos, Type t, List<TypeVar> seen) {
   1.304          final TypeVar tv;
   1.305 -        if  (t.tag == TYPEVAR && (t.tsym.flags() & UNATTRIBUTED) != 0)
   1.306 +        if  (t.hasTag(TYPEVAR) && (t.tsym.flags() & UNATTRIBUTED) != 0)
   1.307              return;
   1.308          if (seen.contains(t)) {
   1.309              tv = (TypeVar)t;
   1.310              tv.bound = types.createErrorType(t);
   1.311              log.error(pos, "cyclic.inheritance", t);
   1.312 -        } else if (t.tag == TYPEVAR) {
   1.313 +        } else if (t.hasTag(TYPEVAR)) {
   1.314              tv = (TypeVar)t;
   1.315              seen = seen.prepend(tv);
   1.316              for (Type b : types.getBounds(tv))
   1.317 @@ -2232,14 +2221,14 @@
   1.318          } else if (!c.type.isErroneous()) {
   1.319              try {
   1.320                  c.flags_field |= LOCKED;
   1.321 -                if (c.type.tag == CLASS) {
   1.322 +                if (c.type.hasTag(CLASS)) {
   1.323                      ClassType clazz = (ClassType)c.type;
   1.324                      if (clazz.interfaces_field != null)
   1.325                          for (List<Type> l=clazz.interfaces_field; l.nonEmpty(); l=l.tail)
   1.326                              complete &= checkNonCyclicInternal(pos, l.head);
   1.327                      if (clazz.supertype_field != null) {
   1.328                          Type st = clazz.supertype_field;
   1.329 -                        if (st != null && st.tag == CLASS)
   1.330 +                        if (st != null && st.hasTag(CLASS))
   1.331                              complete &= checkNonCyclicInternal(pos, st);
   1.332                      }
   1.333                      if (c.owner.kind == TYP)
   1.334 @@ -2261,7 +2250,7 @@
   1.335          for (List<Type> l=types.interfaces(c.type); l.nonEmpty(); l=l.tail)
   1.336              l.head = types.createErrorType((ClassSymbol)l.head.tsym, Type.noType);
   1.337          Type st = types.supertype(c.type);
   1.338 -        if (st.tag == CLASS)
   1.339 +        if (st.hasTag(CLASS))
   1.340              ((ClassType)c.type).supertype_field = types.createErrorType((ClassSymbol)st.tsym, Type.noType);
   1.341          c.type = types.createErrorType(c, c.type);
   1.342          c.flags_field |= ACYCLIC;
   1.343 @@ -2313,7 +2302,7 @@
   1.344      void checkCompatibleSupertypes(DiagnosticPosition pos, Type c) {
   1.345          List<Type> supertypes = types.interfaces(c);
   1.346          Type supertype = types.supertype(c);
   1.347 -        if (supertype.tag == CLASS &&
   1.348 +        if (supertype.hasTag(CLASS) &&
   1.349              (supertype.tsym.flags() & ABSTRACT) != 0)
   1.350              supertypes = supertypes.prepend(supertype);
   1.351          for (List<Type> l = supertypes; l.nonEmpty(); l = l.tail) {
   1.352 @@ -2542,7 +2531,7 @@
   1.353       * @jls 9.6 Annotation Types
   1.354       */
   1.355      void validateAnnotationMethod(DiagnosticPosition pos, MethodSymbol m) {
   1.356 -        for (Type sup = syms.annotationType; sup.tag == CLASS; sup = types.supertype(sup)) {
   1.357 +        for (Type sup = syms.annotationType; sup.hasTag(CLASS); sup = types.supertype(sup)) {
   1.358              Scope s = sup.tsym.members();
   1.359              for (Scope.Entry e = s.lookup(m.name); e.scope != null; e = e.next()) {
   1.360                  if (e.sym.kind == MTH &&
   1.361 @@ -2855,7 +2844,7 @@
   1.362                  { if (s.kind == TYP ||
   1.363                        s.kind == VAR ||
   1.364                        (s.kind == MTH && !s.isConstructor() &&
   1.365 -                       s.type.getReturnType().tag != VOID))
   1.366 +                       !s.type.getReturnType().hasTag(VOID)))
   1.367                      return true;
   1.368                  }
   1.369              else
   1.370 @@ -3016,12 +3005,12 @@
   1.371      }
   1.372  
   1.373      void checkAnnotationResType(DiagnosticPosition pos, Type type) {
   1.374 -        switch (type.tag) {
   1.375 -        case TypeTags.CLASS:
   1.376 +        switch (type.getTag()) {
   1.377 +        case CLASS:
   1.378              if ((type.tsym.flags() & ANNOTATION) != 0)
   1.379                  checkNonCyclicElementsInternal(pos, type.tsym);
   1.380              break;
   1.381 -        case TypeTags.ARRAY:
   1.382 +        case ARRAY:
   1.383              checkAnnotationResType(pos, types.elemtype(type));
   1.384              break;
   1.385          default:
   1.386 @@ -3114,7 +3103,7 @@
   1.387      void checkDivZero(DiagnosticPosition pos, Symbol operator, Type operand) {
   1.388          if (operand.constValue() != null
   1.389              && lint.isEnabled(LintCategory.DIVZERO)
   1.390 -            && operand.tag <= LONG
   1.391 +            && (operand.getTag().isSubRangeOf(LONG))
   1.392              && ((Number) (operand.constValue())).longValue() == 0) {
   1.393              int opc = ((OperatorSymbol)operator).opcode;
   1.394              if (opc == ByteCodes.idiv || opc == ByteCodes.imod

mercurial