7133238: Merge proto-kind and proto-type into a single result class

Tue, 06 Mar 2012 13:29:45 +0000

author
mcimadamore
date
Tue, 06 Mar 2012 13:29:45 +0000
changeset 1220
38ae13dcd215
parent 1219
48ee63caaa93
child 1221
c2234816495f

7133238: Merge proto-kind and proto-type into a single result class
Summary: Restructure attribution code so that the check-logic can be encapsulated into a single class
Reviewed-by: jjg, dlsmith

src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Mar 06 13:28:05 2012 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Mar 06 13:29:45 2012 +0000
     1.3 @@ -199,16 +199,15 @@
     1.4       *  @param tree     The tree whose kind and type is checked
     1.5       *  @param owntype  The computed type of the tree
     1.6       *  @param ownkind  The computed kind of the tree
     1.7 -     *  @param pkind    The expected kind (or: protokind) of the tree
     1.8 -     *  @param pt       The expected type (or: prototype) of the tree
     1.9 +     *  @param resultInfo  The expected result of the tree
    1.10       */
    1.11 -    Type check(JCTree tree, Type owntype, int ownkind, int pkind, Type pt) {
    1.12 -        if (owntype.tag != ERROR && pt.tag != METHOD && pt.tag != FORALL) {
    1.13 -            if ((ownkind & ~pkind) == 0) {
    1.14 -                owntype = chk.checkType(tree.pos(), owntype, pt, errKey);
    1.15 +    Type check(JCTree tree, Type owntype, int ownkind, ResultInfo resultInfo) {
    1.16 +        if (owntype.tag != ERROR && resultInfo.pt.tag != METHOD && resultInfo.pt.tag != FORALL) {
    1.17 +            if ((ownkind & ~resultInfo.pkind) == 0) {
    1.18 +                owntype = chk.checkType(tree.pos(), owntype, resultInfo.pt, errKey);
    1.19              } else {
    1.20                  log.error(tree.pos(), "unexpected.type",
    1.21 -                          kindNames(pkind),
    1.22 +                          kindNames(resultInfo.pkind),
    1.23                            kindName(ownkind));
    1.24                  owntype = types.createErrorType(owntype);
    1.25              }
    1.26 @@ -333,7 +332,16 @@
    1.27      public Type attribType(JCTree node, TypeSymbol sym) {
    1.28          Env<AttrContext> env = enter.typeEnvs.get(sym);
    1.29          Env<AttrContext> localEnv = env.dup(node, env.info.dup());
    1.30 -        return attribTree(node, localEnv, Kinds.TYP, Type.noType);
    1.31 +        return attribTree(node, localEnv, unknownTypeInfo);
    1.32 +    }
    1.33 +
    1.34 +    public Type attribImportQualifier(JCImport tree, Env<AttrContext> env) {
    1.35 +        // Attribute qualifying package or class.
    1.36 +        JCFieldAccess s = (JCFieldAccess)tree.qualid;
    1.37 +        return attribTree(s.selected,
    1.38 +                       env,
    1.39 +                       new ResultInfo(tree.staticImport ? TYP : (TYP | PCK),
    1.40 +                       Type.noType));
    1.41      }
    1.42  
    1.43      public Env<AttrContext> attribExprToTree(JCTree expr, Env<AttrContext> env, JCTree tree) {
    1.44 @@ -386,6 +394,28 @@
    1.45          }
    1.46      }
    1.47  
    1.48 +    static class ResultInfo {
    1.49 +        int pkind;
    1.50 +        Type pt;
    1.51 +
    1.52 +        ResultInfo(int pkind, Type pt) {
    1.53 +            this.pkind = pkind;
    1.54 +            this.pt = pt;
    1.55 +        }
    1.56 +    }
    1.57 +
    1.58 +    private final ResultInfo statInfo = new ResultInfo(NIL, Type.noType);
    1.59 +    private final ResultInfo varInfo = new ResultInfo(VAR, Type.noType);
    1.60 +    private final ResultInfo unknownExprInfo = new ResultInfo(VAL, Type.noType);
    1.61 +    private final ResultInfo unknownTypeInfo = new ResultInfo(TYP, Type.noType);
    1.62 +
    1.63 +    Type pt() {
    1.64 +        return resultInfo.pt;
    1.65 +    }
    1.66 +
    1.67 +    int pkind() {
    1.68 +        return resultInfo.pkind;
    1.69 +    }
    1.70  
    1.71  /* ************************************************************************
    1.72   * Visitor methods
    1.73 @@ -395,13 +425,9 @@
    1.74       */
    1.75      Env<AttrContext> env;
    1.76  
    1.77 -    /** Visitor argument: the currently expected proto-kind.
    1.78 +    /** Visitor argument: the currently expected attribution result.
    1.79       */
    1.80 -    int pkind;
    1.81 -
    1.82 -    /** Visitor argument: the currently expected proto-type.
    1.83 -     */
    1.84 -    Type pt;
    1.85 +    ResultInfo resultInfo;
    1.86  
    1.87      /** Visitor argument: the error key to be generated when a type error occurs
    1.88       */
    1.89 @@ -416,22 +442,19 @@
    1.90       *
    1.91       *  @param tree    The tree to be visited.
    1.92       *  @param env     The environment visitor argument.
    1.93 -     *  @param pkind   The protokind visitor argument.
    1.94 -     *  @param pt      The prototype visitor argument.
    1.95 +     *  @param resultInfo   The result info visitor argument.
    1.96       */
    1.97 -    Type attribTree(JCTree tree, Env<AttrContext> env, int pkind, Type pt) {
    1.98 -        return attribTree(tree, env, pkind, pt, "incompatible.types");
    1.99 +    private Type attribTree(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) {
   1.100 +        return attribTree(tree, env, resultInfo, "incompatible.types");
   1.101      }
   1.102  
   1.103 -    Type attribTree(JCTree tree, Env<AttrContext> env, int pkind, Type pt, String errKey) {
   1.104 +    private Type attribTree(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo, String errKey) {
   1.105          Env<AttrContext> prevEnv = this.env;
   1.106 -        int prevPkind = this.pkind;
   1.107 -        Type prevPt = this.pt;
   1.108 +        ResultInfo prevResult = this.resultInfo;
   1.109          String prevErrKey = this.errKey;
   1.110          try {
   1.111              this.env = env;
   1.112 -            this.pkind = pkind;
   1.113 -            this.pt = pt;
   1.114 +            this.resultInfo = resultInfo;
   1.115              this.errKey = errKey;
   1.116              tree.accept(this);
   1.117              if (tree == breakTree)
   1.118 @@ -442,8 +465,7 @@
   1.119              return chk.completionError(tree.pos(), ex);
   1.120          } finally {
   1.121              this.env = prevEnv;
   1.122 -            this.pkind = prevPkind;
   1.123 -            this.pt = prevPt;
   1.124 +            this.resultInfo = prevResult;
   1.125              this.errKey = prevErrKey;
   1.126          }
   1.127      }
   1.128 @@ -451,18 +473,18 @@
   1.129      /** Derived visitor method: attribute an expression tree.
   1.130       */
   1.131      public Type attribExpr(JCTree tree, Env<AttrContext> env, Type pt) {
   1.132 -        return attribTree(tree, env, VAL, pt.tag != ERROR ? pt : Type.noType);
   1.133 +        return attribExpr(tree, env, pt, "incompatible.types");
   1.134      }
   1.135  
   1.136      public Type attribExpr(JCTree tree, Env<AttrContext> env, Type pt, String key) {
   1.137 -        return attribTree(tree, env, VAL, pt.tag != ERROR ? pt : Type.noType, key);
   1.138 +        return attribTree(tree, env, new ResultInfo(VAL, pt.tag != ERROR ? pt : Type.noType), key);
   1.139      }
   1.140  
   1.141      /** Derived visitor method: attribute an expression tree with
   1.142       *  no constraints on the computed type.
   1.143       */
   1.144      Type attribExpr(JCTree tree, Env<AttrContext> env) {
   1.145 -        return attribTree(tree, env, VAL, Type.noType);
   1.146 +        return attribTree(tree, env, unknownExprInfo);
   1.147      }
   1.148  
   1.149      /** Derived visitor method: attribute a type tree.
   1.150 @@ -475,14 +497,14 @@
   1.151      /** Derived visitor method: attribute a type tree.
   1.152       */
   1.153      Type attribType(JCTree tree, Env<AttrContext> env, Type pt) {
   1.154 -        Type result = attribTree(tree, env, TYP, pt);
   1.155 +        Type result = attribTree(tree, env, new ResultInfo(TYP, pt));
   1.156          return result;
   1.157      }
   1.158  
   1.159      /** Derived visitor method: attribute a statement or definition tree.
   1.160       */
   1.161      public Type attribStat(JCTree tree, Env<AttrContext> env) {
   1.162 -        return attribTree(tree, env, NIL, Type.noType);
   1.163 +        return attribTree(tree, env, statInfo);
   1.164      }
   1.165  
   1.166      /** Attribute a list of expressions, returning a list of types.
   1.167 @@ -507,7 +529,7 @@
   1.168          ListBuffer<Type> argtypes = new ListBuffer<Type>();
   1.169          for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail)
   1.170              argtypes.append(chk.checkNonVoid(
   1.171 -                l.head.pos(), types.upperBound(attribTree(l.head, env, VAL, Infer.anyPoly))));
   1.172 +                l.head.pos(), types.upperBound(attribExpr(l.head, env, Infer.anyPoly))));
   1.173          return argtypes.toList();
   1.174      }
   1.175  
   1.176 @@ -1181,7 +1203,7 @@
   1.177          result = check(tree,
   1.178                         capture(condType(tree.pos(), tree.cond.type,
   1.179                                          tree.truepart.type, tree.falsepart.type)),
   1.180 -                       VAL, pkind, pt);
   1.181 +                       VAL, resultInfo);
   1.182      }
   1.183      //where
   1.184          /** Compute the type of a conditional expression, after
   1.185 @@ -1500,8 +1522,8 @@
   1.186                      // ...and check that it is legal in the current context.
   1.187                      // (this will also set the tree's type)
   1.188                      Type mpt = newMethTemplate(argtypes, typeargtypes);
   1.189 -                    checkId(tree.meth, site, sym, localEnv, MTH,
   1.190 -                            mpt, tree.varargsElement != null);
   1.191 +                    checkId(tree.meth, site, sym, localEnv, new ResultInfo(MTH, mpt),
   1.192 +                            tree.varargsElement != null);
   1.193                  }
   1.194                  // Otherwise, `site' is an error type and we do nothing
   1.195              }
   1.196 @@ -1550,7 +1572,7 @@
   1.197  
   1.198              // Check that value of resulting type is admissible in the
   1.199              // current context.  Also, capture the return type
   1.200 -            result = check(tree, capture(restype), VAL, pkind, pt);
   1.201 +            result = check(tree, capture(restype), VAL, resultInfo);
   1.202  
   1.203              if (localEnv.info.varArgs)
   1.204                  Assert.check(result.isErroneous() || tree.varargsElement != null);
   1.205 @@ -1681,7 +1703,7 @@
   1.206              if (inferred != null &&
   1.207                      !inferred.isErroneous() &&
   1.208                      inferred.tag == CLASS &&
   1.209 -                    types.isAssignable(inferred, pt.tag == NONE ? clazztype : pt, Warner.noWarnings)) {
   1.210 +                    types.isAssignable(inferred, pt().tag == NONE ? clazztype : pt(), Warner.noWarnings)) {
   1.211                  String key = types.isSameType(clazztype, inferred) ?
   1.212                      "diamond.redundant.args" :
   1.213                      "diamond.redundant.args.1";
   1.214 @@ -1819,7 +1841,7 @@
   1.215              if (tree.constructor != null && tree.constructor.kind == MTH)
   1.216                  owntype = clazztype;
   1.217          }
   1.218 -        result = check(tree, owntype, VAL, pkind, pt);
   1.219 +        result = check(tree, owntype, VAL, resultInfo);
   1.220          chk.validate(tree.typeargs, localEnv);
   1.221      }
   1.222  
   1.223 @@ -1864,13 +1886,13 @@
   1.224              clazztype = syms.errType;
   1.225          }
   1.226  
   1.227 -        if (clazztype.tag == FORALL && !pt.isErroneous()) {
   1.228 +        if (clazztype.tag == FORALL && !pt().isErroneous()) {
   1.229              //if the resolved constructor's return type has some uninferred
   1.230              //type-variables, infer them using the expected type and declared
   1.231              //bounds (JLS 15.12.2.8).
   1.232              try {
   1.233                  clazztype = infer.instantiateExpr((ForAll) clazztype,
   1.234 -                        pt.tag == NONE ? syms.objectType : pt,
   1.235 +                        pt().tag == NONE ? syms.objectType : pt(),
   1.236                          Warner.noWarnings);
   1.237              } catch (Infer.InferenceException ex) {
   1.238                  //an error occurred while inferring uninstantiated type-variables
   1.239 @@ -1913,14 +1935,14 @@
   1.240          } else {
   1.241              // we are seeing an untyped aggregate { ... }
   1.242              // this is allowed only if the prototype is an array
   1.243 -            if (pt.tag == ARRAY) {
   1.244 -                elemtype = types.elemtype(pt);
   1.245 +            if (pt().tag == ARRAY) {
   1.246 +                elemtype = types.elemtype(pt());
   1.247              } else {
   1.248 -                if (pt.tag != ERROR) {
   1.249 +                if (pt().tag != ERROR) {
   1.250                      log.error(tree.pos(), "illegal.initializer.for.type",
   1.251 -                              pt);
   1.252 +                              pt());
   1.253                  }
   1.254 -                elemtype = types.createErrorType(pt);
   1.255 +                elemtype = types.createErrorType(pt());
   1.256              }
   1.257          }
   1.258          if (tree.elems != null) {
   1.259 @@ -1929,7 +1951,7 @@
   1.260          }
   1.261          if (!types.isReifiable(elemtype))
   1.262              log.error(tree.pos(), "generic.array.creation");
   1.263 -        result = check(tree, owntype, VAL, pkind, pt);
   1.264 +        result = check(tree, owntype, VAL, resultInfo);
   1.265      }
   1.266  
   1.267      @Override
   1.268 @@ -1943,23 +1965,23 @@
   1.269      }
   1.270  
   1.271      public void visitParens(JCParens tree) {
   1.272 -        Type owntype = attribTree(tree.expr, env, pkind, pt);
   1.273 -        result = check(tree, owntype, pkind, pkind, pt);
   1.274 +        Type owntype = attribTree(tree.expr, env, resultInfo);
   1.275 +        result = check(tree, owntype, pkind(), resultInfo);
   1.276          Symbol sym = TreeInfo.symbol(tree);
   1.277          if (sym != null && (sym.kind&(TYP|PCK)) != 0)
   1.278              log.error(tree.pos(), "illegal.start.of.type");
   1.279      }
   1.280  
   1.281      public void visitAssign(JCAssign tree) {
   1.282 -        Type owntype = attribTree(tree.lhs, env.dup(tree), VAR, Type.noType);
   1.283 +        Type owntype = attribTree(tree.lhs, env.dup(tree), varInfo);
   1.284          Type capturedType = capture(owntype);
   1.285          attribExpr(tree.rhs, env, owntype);
   1.286 -        result = check(tree, capturedType, VAL, pkind, pt);
   1.287 +        result = check(tree, capturedType, VAL, resultInfo);
   1.288      }
   1.289  
   1.290      public void visitAssignop(JCAssignOp tree) {
   1.291          // Attribute arguments.
   1.292 -        Type owntype = attribTree(tree.lhs, env, VAR, Type.noType);
   1.293 +        Type owntype = attribTree(tree.lhs, env, varInfo);
   1.294          Type operand = attribExpr(tree.rhs, env);
   1.295          // Find operator.
   1.296          Symbol operator = tree.operator = rs.resolveBinaryOperator(
   1.297 @@ -1979,13 +2001,13 @@
   1.298                                operator.type.getReturnType(),
   1.299                                owntype);
   1.300          }
   1.301 -        result = check(tree, owntype, VAL, pkind, pt);
   1.302 +        result = check(tree, owntype, VAL, resultInfo);
   1.303      }
   1.304  
   1.305      public void visitUnary(JCUnary tree) {
   1.306          // Attribute arguments.
   1.307          Type argtype = (tree.getTag().isIncOrDecUnaryOp())
   1.308 -            ? attribTree(tree.arg, env, VAR, Type.noType)
   1.309 +            ? attribTree(tree.arg, env, varInfo)
   1.310              : chk.checkNonVoid(tree.arg.pos(), attribExpr(tree.arg, env));
   1.311  
   1.312          // Find operator.
   1.313 @@ -2017,7 +2039,7 @@
   1.314                  }
   1.315              }
   1.316          }
   1.317 -        result = check(tree, owntype, VAL, pkind, pt);
   1.318 +        result = check(tree, owntype, VAL, resultInfo);
   1.319      }
   1.320  
   1.321      public void visitBinary(JCBinary tree) {
   1.322 @@ -2070,7 +2092,7 @@
   1.323  
   1.324              chk.checkDivZero(tree.rhs.pos(), operator, right);
   1.325          }
   1.326 -        result = check(tree, owntype, VAL, pkind, pt);
   1.327 +        result = check(tree, owntype, VAL, resultInfo);
   1.328      }
   1.329  
   1.330      public void visitTypeCast(JCTypeCast tree) {
   1.331 @@ -2083,7 +2105,7 @@
   1.332          Type owntype = chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
   1.333          if (exprtype.constValue() != null)
   1.334              owntype = cfolder.coerce(exprtype, owntype);
   1.335 -        result = check(tree, capture(owntype), VAL, pkind, pt);
   1.336 +        result = check(tree, capture(owntype), VAL, resultInfo);
   1.337      }
   1.338  
   1.339      public void visitTypeTest(JCInstanceOf tree) {
   1.340 @@ -2093,7 +2115,7 @@
   1.341              tree.clazz.pos(), attribType(tree.clazz, env));
   1.342          chk.validate(tree.clazz, env, false);
   1.343          chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
   1.344 -        result = check(tree, syms.booleanType, VAL, pkind, pt);
   1.345 +        result = check(tree, syms.booleanType, VAL, resultInfo);
   1.346      }
   1.347  
   1.348      public void visitIndexed(JCArrayAccess tree) {
   1.349 @@ -2104,8 +2126,8 @@
   1.350              owntype = types.elemtype(atype);
   1.351          else if (atype.tag != ERROR)
   1.352              log.error(tree.pos(), "array.req.but.found", atype);
   1.353 -        if ((pkind & VAR) == 0) owntype = capture(owntype);
   1.354 -        result = check(tree, owntype, VAR, pkind, pt);
   1.355 +        if ((pkind() & VAR) == 0) owntype = capture(owntype);
   1.356 +        result = check(tree, owntype, VAR, resultInfo);
   1.357      }
   1.358  
   1.359      public void visitIdent(JCIdent tree) {
   1.360 @@ -2113,16 +2135,16 @@
   1.361          boolean varArgs = false;
   1.362  
   1.363          // Find symbol
   1.364 -        if (pt.tag == METHOD || pt.tag == FORALL) {
   1.365 +        if (pt().tag == METHOD || pt().tag == FORALL) {
   1.366              // If we are looking for a method, the prototype `pt' will be a
   1.367              // method type with the type of the call's arguments as parameters.
   1.368              env.info.varArgs = false;
   1.369 -            sym = rs.resolveMethod(tree.pos(), env, tree.name, pt.getParameterTypes(), pt.getTypeArguments());
   1.370 +            sym = rs.resolveMethod(tree.pos(), env, tree.name, pt().getParameterTypes(), pt().getTypeArguments());
   1.371              varArgs = env.info.varArgs;
   1.372          } else if (tree.sym != null && tree.sym.kind != VAR) {
   1.373              sym = tree.sym;
   1.374          } else {
   1.375 -            sym = rs.resolveIdent(tree.pos(), env, tree.name, pkind);
   1.376 +            sym = rs.resolveIdent(tree.pos(), env, tree.name, pkind());
   1.377          }
   1.378          tree.sym = sym;
   1.379  
   1.380 @@ -2169,7 +2191,7 @@
   1.381  
   1.382              // If we are expecting a variable (as opposed to a value), check
   1.383              // that the variable is assignable in the current environment.
   1.384 -            if (pkind == VAR)
   1.385 +            if (pkind() == VAR)
   1.386                  checkAssignable(tree.pos(), v, null, env);
   1.387          }
   1.388  
   1.389 @@ -2190,7 +2212,7 @@
   1.390              while (env1.outer != null && !rs.isAccessible(env, env1.enclClass.sym.type, sym))
   1.391                  env1 = env1.outer;
   1.392          }
   1.393 -        result = checkId(tree, env1.enclClass.sym.type, sym, env, pkind, pt, varArgs);
   1.394 +        result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo, varArgs);
   1.395      }
   1.396  
   1.397      public void visitSelect(JCFieldAccess tree) {
   1.398 @@ -2201,14 +2223,14 @@
   1.399          {
   1.400              skind = TYP;
   1.401          } else {
   1.402 -            if ((pkind & PCK) != 0) skind = skind | PCK;
   1.403 -            if ((pkind & TYP) != 0) skind = skind | TYP | PCK;
   1.404 -            if ((pkind & (VAL | MTH)) != 0) skind = skind | VAL | TYP;
   1.405 +            if ((pkind() & PCK) != 0) skind = skind | PCK;
   1.406 +            if ((pkind() & TYP) != 0) skind = skind | TYP | PCK;
   1.407 +            if ((pkind() & (VAL | MTH)) != 0) skind = skind | VAL | TYP;
   1.408          }
   1.409  
   1.410          // Attribute the qualifier expression, and determine its symbol (if any).
   1.411 -        Type site = attribTree(tree.selected, env, skind, Infer.anyPoly);
   1.412 -        if ((pkind & (PCK | TYP)) == 0)
   1.413 +        Type site = attribTree(tree.selected, env, new ResultInfo(skind, Infer.anyPoly));
   1.414 +        if ((pkind() & (PCK | TYP)) == 0)
   1.415              site = capture(site); // Capture field access
   1.416  
   1.417          // don't allow T.class T[].class, etc
   1.418 @@ -2243,10 +2265,10 @@
   1.419  
   1.420          // Determine the symbol represented by the selection.
   1.421          env.info.varArgs = false;
   1.422 -        Symbol sym = selectSym(tree, sitesym, site, env, pt, pkind);
   1.423 -        if (sym.exists() && !isType(sym) && (pkind & (PCK | TYP)) != 0) {
   1.424 +        Symbol sym = selectSym(tree, sitesym, site, env, resultInfo);
   1.425 +        if (sym.exists() && !isType(sym) && (pkind() & (PCK | TYP)) != 0) {
   1.426              site = capture(site);
   1.427 -            sym = selectSym(tree, sitesym, site, env, pt, pkind);
   1.428 +            sym = selectSym(tree, sitesym, site, env, resultInfo);
   1.429          }
   1.430          boolean varArgs = env.info.varArgs;
   1.431          tree.sym = sym;
   1.432 @@ -2266,7 +2288,7 @@
   1.433  
   1.434              // If we are expecting a variable (as opposed to a value), check
   1.435              // that the variable is assignable in the current environment.
   1.436 -            if (pkind == VAR)
   1.437 +            if (pkind() == VAR)
   1.438                  checkAssignable(tree.pos(), v, tree.selected, env);
   1.439          }
   1.440  
   1.441 @@ -2282,8 +2304,8 @@
   1.442  
   1.443          // Disallow selecting a type from an expression
   1.444          if (isType(sym) && (sitesym==null || (sitesym.kind&(TYP|PCK)) == 0)) {
   1.445 -            tree.type = check(tree.selected, pt,
   1.446 -                              sitesym == null ? VAL : sitesym.kind, TYP|PCK, pt);
   1.447 +            tree.type = check(tree.selected, pt(),
   1.448 +                              sitesym == null ? VAL : sitesym.kind, new ResultInfo(TYP|PCK, pt()));
   1.449          }
   1.450  
   1.451          if (isType(sitesym)) {
   1.452 @@ -2323,7 +2345,7 @@
   1.453          }
   1.454  
   1.455          env.info.selectSuper = selectSuperPrev;
   1.456 -        result = checkId(tree, site, sym, env, pkind, pt, varArgs);
   1.457 +        result = checkId(tree, site, sym, env, resultInfo, varArgs);
   1.458          env.info.tvars = List.nil();
   1.459      }
   1.460      //where
   1.461 @@ -2332,34 +2354,25 @@
   1.462           *  @param tree   The select tree.
   1.463           *  @param site   The type of the selected expression,
   1.464           *  @param env    The current environment.
   1.465 -         *  @param pt     The current prototype.
   1.466 -         *  @param pkind  The expected kind(s) of the Select expression.
   1.467 +         *  @param resultInfo The current result.
   1.468           */
   1.469          private Symbol selectSym(JCFieldAccess tree,
   1.470 -                                     Type site,
   1.471 -                                     Env<AttrContext> env,
   1.472 -                                     Type pt,
   1.473 -                                     int pkind) {
   1.474 -            return selectSym(tree, site.tsym, site, env, pt, pkind);
   1.475 -        }
   1.476 -        private Symbol selectSym(JCFieldAccess tree,
   1.477                                   Symbol location,
   1.478                                   Type site,
   1.479                                   Env<AttrContext> env,
   1.480 -                                 Type pt,
   1.481 -                                 int pkind) {
   1.482 +                                 ResultInfo resultInfo) {
   1.483              DiagnosticPosition pos = tree.pos();
   1.484              Name name = tree.name;
   1.485              switch (site.tag) {
   1.486              case PACKAGE:
   1.487                  return rs.access(
   1.488 -                    rs.findIdentInPackage(env, site.tsym, name, pkind),
   1.489 +                    rs.findIdentInPackage(env, site.tsym, name, resultInfo.pkind),
   1.490                      pos, location, site, name, true);
   1.491              case ARRAY:
   1.492              case CLASS:
   1.493 -                if (pt.tag == METHOD || pt.tag == FORALL) {
   1.494 +                if (resultInfo.pt.tag == METHOD || resultInfo.pt.tag == FORALL) {
   1.495                      return rs.resolveQualifiedMethod(
   1.496 -                        pos, env, location, site, name, pt.getParameterTypes(), pt.getTypeArguments());
   1.497 +                        pos, env, location, site, name, resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments());
   1.498                  } else if (name == names._this || name == names._super) {
   1.499                      return rs.resolveSelf(pos, env, site.tsym, name);
   1.500                  } else if (name == names._class) {
   1.501 @@ -2374,8 +2387,8 @@
   1.502                          STATIC | PUBLIC | FINAL, names._class, t, site.tsym);
   1.503                  } else {
   1.504                      // We are seeing a plain identifier as selector.
   1.505 -                    Symbol sym = rs.findIdentInType(env, site, name, pkind);
   1.506 -                    if ((pkind & ERRONEOUS) == 0)
   1.507 +                    Symbol sym = rs.findIdentInType(env, site, name, resultInfo.pkind);
   1.508 +                    if ((resultInfo.pkind & ERRONEOUS) == 0)
   1.509                          sym = rs.access(sym, pos, location, site, name, true);
   1.510                      return sym;
   1.511                  }
   1.512 @@ -2389,7 +2402,7 @@
   1.513                  // other words, we are seeing this illegal program:
   1.514                  // class B<T> extends A<T.foo> {}
   1.515                  Symbol sym = (site.getUpperBound() != null)
   1.516 -                    ? selectSym(tree, location, capture(site.getUpperBound()), env, pt, pkind)
   1.517 +                    ? selectSym(tree, location, capture(site.getUpperBound()), env, resultInfo)
   1.518                      : null;
   1.519                  if (sym == null) {
   1.520                      log.error(pos, "type.var.cant.be.deref");
   1.521 @@ -2443,17 +2456,15 @@
   1.522           *                    expression, otherwise the type of the current class.
   1.523           *  @param sym        The symbol representing the identifier.
   1.524           *  @param env        The current environment.
   1.525 -         *  @param pkind      The set of expected kinds.
   1.526 -         *  @param pt         The expected type.
   1.527 +         *  @param resultInfo    The expected result
   1.528           */
   1.529          Type checkId(JCTree tree,
   1.530                       Type site,
   1.531                       Symbol sym,
   1.532                       Env<AttrContext> env,
   1.533 -                     int pkind,
   1.534 -                     Type pt,
   1.535 +                     ResultInfo resultInfo,
   1.536                       boolean useVarargs) {
   1.537 -            if (pt.isErroneous()) return types.createErrorType(site);
   1.538 +            if (resultInfo.pt.isErroneous()) return types.createErrorType(site);
   1.539              Type owntype; // The computed type of this identifier occurrence.
   1.540              switch (sym.kind) {
   1.541              case TYP:
   1.542 @@ -2498,7 +2509,7 @@
   1.543                  // which is being assigned to, issue an unchecked warning if
   1.544                  // its type changes under erasure.
   1.545                  if (allowGenerics &&
   1.546 -                    pkind == VAR &&
   1.547 +                    resultInfo.pkind == VAR &&
   1.548                      v.owner.kind == TYP &&
   1.549                      (v.flags() & STATIC) == 0 &&
   1.550                      (site.tag == CLASS || site.tag == TYPEVAR)) {
   1.551 @@ -2533,14 +2544,14 @@
   1.552                  if (v.getConstValue() != null && isStaticReference(tree))
   1.553                      owntype = owntype.constType(v.getConstValue());
   1.554  
   1.555 -                if (pkind == VAL) {
   1.556 +                if (resultInfo.pkind == VAL) {
   1.557                      owntype = capture(owntype); // capture "names as expressions"
   1.558                  }
   1.559                  break;
   1.560              case MTH: {
   1.561                  JCMethodInvocation app = (JCMethodInvocation)env.tree;
   1.562                  owntype = checkMethod(site, sym, env, app.args,
   1.563 -                                      pt.getParameterTypes(), pt.getTypeArguments(),
   1.564 +                                      resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments(),
   1.565                                        env.info.varArgs);
   1.566                  break;
   1.567              }
   1.568 @@ -2563,7 +2574,7 @@
   1.569  
   1.570              // Test (3): if symbol is a variable, check that its type and
   1.571              // kind are compatible with the prototype and protokind.
   1.572 -            return check(tree, owntype, sym.kind, pkind, pt);
   1.573 +            return check(tree, owntype, sym.kind, resultInfo);
   1.574          }
   1.575  
   1.576          /** Check that variable is initialized and evaluate the variable's
   1.577 @@ -2717,11 +2728,11 @@
   1.578          // If this fails, something went wrong; we should not have
   1.579          // found the identifier in the first place.
   1.580          if (owntype == null) {
   1.581 -            if (!pt.isErroneous())
   1.582 +            if (!pt().isErroneous())
   1.583                  log.error(env.tree.pos(),
   1.584                             "internal.error.cant.instantiate",
   1.585                             sym, site,
   1.586 -                          Type.toString(pt.getParameterTypes()));
   1.587 +                          Type.toString(pt().getParameterTypes()));
   1.588              owntype = types.createErrorType(site);
   1.589              return types.createErrorType(site);
   1.590          } else if (owntype.getReturnType().tag == FORALL) {
   1.591 @@ -2748,7 +2759,7 @@
   1.592  
   1.593      public void visitLiteral(JCLiteral tree) {
   1.594          result = check(
   1.595 -            tree, litType(tree.typetag).constType(tree.value), VAL, pkind, pt);
   1.596 +            tree, litType(tree.typetag).constType(tree.value), VAL, resultInfo);
   1.597      }
   1.598      //where
   1.599      /** Return the type of a literal with given type tag.
   1.600 @@ -2758,13 +2769,13 @@
   1.601      }
   1.602  
   1.603      public void visitTypeIdent(JCPrimitiveTypeTree tree) {
   1.604 -        result = check(tree, syms.typeOfTag[tree.typetag], TYP, pkind, pt);
   1.605 +        result = check(tree, syms.typeOfTag[tree.typetag], TYP, resultInfo);
   1.606      }
   1.607  
   1.608      public void visitTypeArray(JCArrayTypeTree tree) {
   1.609          Type etype = attribType(tree.elemtype, env);
   1.610          Type type = new ArrayType(etype, syms.arrayClass);
   1.611 -        result = check(tree, type, TYP, pkind, pt);
   1.612 +        result = check(tree, type, TYP, resultInfo);
   1.613      }
   1.614  
   1.615      /** Visitor method for parameterized types.
   1.616 @@ -2822,7 +2833,7 @@
   1.617                  owntype = types.createErrorType(tree.type);
   1.618              }
   1.619          }
   1.620 -        result = check(tree, owntype, TYP, pkind, pt);
   1.621 +        result = check(tree, owntype, TYP, resultInfo);
   1.622      }
   1.623  
   1.624      public void visitTypeUnion(JCTypeUnion tree) {
   1.625 @@ -2859,7 +2870,7 @@
   1.626                  all_multicatchTypes.append(ctype);
   1.627              }
   1.628          }
   1.629 -        Type t = check(tree, types.lub(multicatchTypes.toList()), TYP, pkind, pt);
   1.630 +        Type t = check(tree, types.lub(multicatchTypes.toList()), TYP, resultInfo);
   1.631          if (t.tag == CLASS) {
   1.632              List<Type> alternatives =
   1.633                  ((all_multicatchTypes == null) ? multicatchTypes : all_multicatchTypes).toList();
   1.634 @@ -2945,18 +2956,18 @@
   1.635          result = check(tree, new WildcardType(chk.checkRefType(tree.pos(), type),
   1.636                                                tree.kind.kind,
   1.637                                                syms.boundClass),
   1.638 -                       TYP, pkind, pt);
   1.639 +                       TYP, resultInfo);
   1.640      }
   1.641  
   1.642      public void visitAnnotation(JCAnnotation tree) {
   1.643 -        log.error(tree.pos(), "annotation.not.valid.for.type", pt);
   1.644 +        log.error(tree.pos(), "annotation.not.valid.for.type", pt());
   1.645          result = tree.type = syms.errType;
   1.646      }
   1.647  
   1.648      public void visitErroneous(JCErroneous tree) {
   1.649          if (tree.errs != null)
   1.650              for (JCTree err : tree.errs)
   1.651 -                attribTree(err, env, ERR, pt);
   1.652 +                attribTree(err, env, new ResultInfo(ERR, pt()));
   1.653          result = tree.type = syms.errType;
   1.654      }
   1.655  
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue Mar 06 13:28:05 2012 +0000
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue Mar 06 13:29:45 2012 +0000
     2.3 @@ -529,24 +529,17 @@
     2.4  
     2.5      // process the non-static imports and the static imports of types.
     2.6      public void visitImport(JCImport tree) {
     2.7 -        JCTree imp = tree.qualid;
     2.8 +        JCFieldAccess imp = (JCFieldAccess)tree.qualid;
     2.9          Name name = TreeInfo.name(imp);
    2.10 -        TypeSymbol p;
    2.11  
    2.12          // Create a local environment pointing to this tree to disable
    2.13          // effects of other imports in Resolve.findGlobalType
    2.14          Env<AttrContext> localEnv = env.dup(tree);
    2.15  
    2.16 -        // Attribute qualifying package or class.
    2.17 -        JCFieldAccess s = (JCFieldAccess) imp;
    2.18 -        p = attr.
    2.19 -            attribTree(s.selected,
    2.20 -                       localEnv,
    2.21 -                       tree.staticImport ? TYP : (TYP | PCK),
    2.22 -                       Type.noType).tsym;
    2.23 +        TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym;
    2.24          if (name == names.asterisk) {
    2.25              // Import on demand.
    2.26 -            chk.checkCanonical(s.selected);
    2.27 +            chk.checkCanonical(imp.selected);
    2.28              if (tree.staticImport)
    2.29                  importStaticAll(tree.pos, p, env);
    2.30              else
    2.31 @@ -555,7 +548,7 @@
    2.32              // Named type import.
    2.33              if (tree.staticImport) {
    2.34                  importNamedStatic(tree.pos(), p, name, localEnv);
    2.35 -                chk.checkCanonical(s.selected);
    2.36 +                chk.checkCanonical(imp.selected);
    2.37              } else {
    2.38                  TypeSymbol c = attribImportType(imp, localEnv).tsym;
    2.39                  chk.checkCanonical(imp);

mercurial