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

changeset 1296
cddc2c894cc6
parent 1269
37dc15c68760
child 1297
e5cf1569d3a4
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Jul 26 16:48:41 2012 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Aug 02 18:22:41 2012 +0100
     1.3 @@ -1131,8 +1131,8 @@
     1.4          for (JCTree resource : tree.resources) {
     1.5              CheckContext twrContext = new Check.NestedCheckContext(resultInfo.checkContext) {
     1.6                  @Override
     1.7 -                public void report(DiagnosticPosition pos, Type found, Type req, JCDiagnostic details) {
     1.8 -                    chk.basicHandler.report(pos, found, req, diags.fragment("try.not.applicable.to.type", found));
     1.9 +                public void report(DiagnosticPosition pos, JCDiagnostic details) {
    1.10 +                    chk.basicHandler.report(pos, diags.fragment("try.not.applicable.to.type", details));
    1.11                  }
    1.12              };
    1.13              ResultInfo twrResult = new ResultInfo(VAL, syms.autoCloseableType, twrContext);
    1.14 @@ -1865,7 +1865,7 @@
    1.15  
    1.16      Type attribDiamond(Env<AttrContext> env,
    1.17                          final JCNewClass tree,
    1.18 -                        Type clazztype,
    1.19 +                        final Type clazztype,
    1.20                          List<Type> argtypes,
    1.21                          List<Type> typeargtypes) {
    1.22          if (clazztype.isErroneous() ||
    1.23 @@ -1892,27 +1892,26 @@
    1.24                      argtypes,
    1.25                      typeargtypes);
    1.26  
    1.27 +        Type owntype = types.createErrorType(clazztype);
    1.28          if (constructor.kind == MTH) {
    1.29 -            try {
    1.30 -                clazztype = rawCheckMethod(site,
    1.31 -                        constructor,
    1.32 -                        resultInfo,
    1.33 -                        localEnv,
    1.34 -                        tree.args,
    1.35 -                        argtypes,
    1.36 -                        typeargtypes,
    1.37 -                        localEnv.info.varArgs).getReturnType();
    1.38 -            } catch (Resolve.InapplicableMethodException ex) {
    1.39 -                //an error occurred while inferring uninstantiated type-variables
    1.40 -                resultInfo.checkContext.report(tree.clazz.pos(), clazztype, resultInfo.pt,
    1.41 -                        diags.fragment("cant.apply.diamond.1", diags.fragment("diamond", clazztype.tsym), ex.diagnostic));
    1.42 -                clazztype = syms.errType;
    1.43 -            }
    1.44 -        } else {
    1.45 -            clazztype = syms.errType;
    1.46 +            ResultInfo diamondResult = new ResultInfo(VAL, resultInfo.pt, new Check.NestedCheckContext(resultInfo.checkContext) {
    1.47 +                @Override
    1.48 +                public void report(DiagnosticPosition pos, JCDiagnostic details) {
    1.49 +                    enclosingContext.report(tree.clazz.pos(),
    1.50 +                            diags.fragment("cant.apply.diamond.1", diags.fragment("diamond", clazztype.tsym), details));
    1.51 +                }
    1.52 +            });
    1.53 +            owntype = checkMethod(site,
    1.54 +                    constructor,
    1.55 +                    diamondResult,
    1.56 +                    localEnv,
    1.57 +                    tree.args,
    1.58 +                    argtypes,
    1.59 +                    typeargtypes,
    1.60 +                    localEnv.info.varArgs).getReturnType();
    1.61          }
    1.62  
    1.63 -        return chk.checkClassType(tree.clazz.pos(), clazztype, true);
    1.64 +        return chk.checkClassType(tree.clazz.pos(), owntype, true);
    1.65      }
    1.66  
    1.67      /** Make an attributed null check tree.
    1.68 @@ -2687,32 +2686,6 @@
    1.69                              List<Type> argtypes,
    1.70                              List<Type> typeargtypes,
    1.71                              boolean useVarargs) {
    1.72 -        try {
    1.73 -            return rawCheckMethod(site, sym, resultInfo, env, argtrees, argtypes, typeargtypes, useVarargs);
    1.74 -        } catch (Resolve.InapplicableMethodException ex) {
    1.75 -            String key = ex.getDiagnostic() == null ?
    1.76 -                    "cant.apply.symbol" :
    1.77 -                    "cant.apply.symbol.1";
    1.78 -            log.error(env.tree.pos, key,
    1.79 -                      Kinds.kindName(sym),
    1.80 -                      sym.name == names.init ? sym.owner.name : sym.name,
    1.81 -                      rs.methodArguments(sym.type.getParameterTypes()),
    1.82 -                      rs.methodArguments(argtypes),
    1.83 -                      Kinds.kindName(sym.owner),
    1.84 -                      sym.owner.type,
    1.85 -                      ex.getDiagnostic());
    1.86 -            return types.createErrorType(site);
    1.87 -        }
    1.88 -    }
    1.89 -
    1.90 -    private Type rawCheckMethod(Type site,
    1.91 -                            Symbol sym,
    1.92 -                            ResultInfo resultInfo,
    1.93 -                            Env<AttrContext> env,
    1.94 -                            final List<JCExpression> argtrees,
    1.95 -                            List<Type> argtypes,
    1.96 -                            List<Type> typeargtypes,
    1.97 -                            boolean useVarargs) {
    1.98          // Test (5): if symbol is an instance method of a raw type, issue
    1.99          // an unchecked warning if its argument types change under erasure.
   1.100          if (allowGenerics &&
   1.101 @@ -2733,19 +2706,29 @@
   1.102          // Resolve.instantiate from the symbol's type as well as
   1.103          // any type arguments and value arguments.
   1.104          noteWarner.clear();
   1.105 -        Type owntype = rs.rawInstantiate(env,
   1.106 -                                          site,
   1.107 -                                          sym,
   1.108 -                                          resultInfo,
   1.109 -                                          argtypes,
   1.110 -                                          typeargtypes,
   1.111 -                                          true,
   1.112 -                                          useVarargs,
   1.113 -                                          noteWarner);
   1.114 -
   1.115 -        boolean unchecked = noteWarner.hasNonSilentLint(LintCategory.UNCHECKED);
   1.116 -
   1.117 -        return chk.checkMethod(owntype, sym, env, argtrees, argtypes, useVarargs, unchecked);
   1.118 +        try {
   1.119 +            Type owntype = rs.rawInstantiate(
   1.120 +                    env,
   1.121 +                    site,
   1.122 +                    sym,
   1.123 +                    resultInfo,
   1.124 +                    argtypes,
   1.125 +                    typeargtypes,
   1.126 +                    allowBoxing,
   1.127 +                    useVarargs,
   1.128 +                    noteWarner);
   1.129 +
   1.130 +            return chk.checkMethod(owntype, sym, env, argtrees, argtypes, useVarargs,
   1.131 +                    noteWarner.hasNonSilentLint(LintCategory.UNCHECKED));
   1.132 +        } catch (Infer.InferenceException ex) {
   1.133 +            //invalid target type - propagate exception outwards or report error
   1.134 +            //depending on the current check context
   1.135 +            resultInfo.checkContext.report(env.tree.pos(), ex.getDiagnostic());
   1.136 +            return types.createErrorType(site);
   1.137 +        } catch (Resolve.InapplicableMethodException ex) {
   1.138 +            Assert.error();
   1.139 +            return null;
   1.140 +        }
   1.141      }
   1.142  
   1.143      /**

mercurial