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

changeset 3005
0353cf89ea96
parent 2814
380f6c17ea01
child 3075
745c9feb99f2
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Jan 04 12:08:55 2016 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Jan 07 08:45:19 2016 +0000
     1.3 @@ -717,7 +717,8 @@
     1.4                                      Warner warn) {
     1.5              //should we expand formals?
     1.6              boolean useVarargs = deferredAttrContext.phase.isVarargsRequired();
     1.7 -            List<JCExpression> trees = TreeInfo.args(env.tree);
     1.8 +            JCTree callTree = treeForDiagnostics(env);
     1.9 +            List<JCExpression> trees = TreeInfo.args(callTree);
    1.10  
    1.11              //inference context used during this method check
    1.12              InferenceContext inferenceContext = deferredAttrContext.inferenceContext;
    1.13 @@ -726,7 +727,7 @@
    1.14  
    1.15              if (varargsFormal == null &&
    1.16                      argtypes.size() != formals.size()) {
    1.17 -                reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args
    1.18 +                reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args
    1.19              }
    1.20  
    1.21              while (argtypes.nonEmpty() && formals.head != varargsFormal) {
    1.22 @@ -738,7 +739,7 @@
    1.23              }
    1.24  
    1.25              if (formals.head != varargsFormal) {
    1.26 -                reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args
    1.27 +                reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args
    1.28              }
    1.29  
    1.30              if (useVarargs) {
    1.31 @@ -754,6 +755,11 @@
    1.32              }
    1.33          }
    1.34  
    1.35 +            // where
    1.36 +            private JCTree treeForDiagnostics(Env<AttrContext> env) {
    1.37 +                return env.info.preferredTreeForDiagnostics != null ? env.info.preferredTreeForDiagnostics : env.tree;
    1.38 +            }
    1.39 +
    1.40          /**
    1.41           * Does the actual argument conforms to the corresponding formal?
    1.42           */
    1.43 @@ -1828,17 +1834,23 @@
    1.44          boolean staticOnly = false;
    1.45          while (env1.outer != null) {
    1.46              if (isStatic(env1)) staticOnly = true;
    1.47 -            sym = findMethod(
    1.48 -                env1, env1.enclClass.sym.type, name, argtypes, typeargtypes,
    1.49 -                allowBoxing, useVarargs, false);
    1.50 -            if (sym.exists()) {
    1.51 -                if (staticOnly &&
    1.52 -                    sym.kind == MTH &&
    1.53 -                    sym.owner.kind == TYP &&
    1.54 -                    (sym.flags() & STATIC) == 0) return new StaticError(sym);
    1.55 -                else return sym;
    1.56 -            } else if (sym.kind < bestSoFar.kind) {
    1.57 -                bestSoFar = sym;
    1.58 +            Assert.check(env1.info.preferredTreeForDiagnostics == null);
    1.59 +            env1.info.preferredTreeForDiagnostics = env.tree;
    1.60 +            try {
    1.61 +                sym = findMethod(
    1.62 +                    env1, env1.enclClass.sym.type, name, argtypes, typeargtypes,
    1.63 +                    allowBoxing, useVarargs, false);
    1.64 +                if (sym.exists()) {
    1.65 +                    if (staticOnly &&
    1.66 +                        sym.kind == MTH &&
    1.67 +                        sym.owner.kind == TYP &&
    1.68 +                        (sym.flags() & STATIC) == 0) return new StaticError(sym);
    1.69 +                    else return sym;
    1.70 +                } else if (sym.kind < bestSoFar.kind) {
    1.71 +                    bestSoFar = sym;
    1.72 +                }
    1.73 +            } finally {
    1.74 +                env1.info.preferredTreeForDiagnostics = null;
    1.75              }
    1.76              if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
    1.77              env1 = env1.outer;
    1.78 @@ -4214,7 +4226,11 @@
    1.79                          DiagnosticPosition preferedPos, DiagnosticSource preferredSource,
    1.80                          DiagnosticType preferredKind, JCDiagnostic d) {
    1.81                      JCDiagnostic cause = (JCDiagnostic)d.getArgs()[0];
    1.82 -                    return diags.create(preferredKind, preferredSource, d.getDiagnosticPosition(),
    1.83 +                    DiagnosticPosition pos = d.getDiagnosticPosition();
    1.84 +                    if (pos == null) {
    1.85 +                        pos = preferedPos;
    1.86 +                    }
    1.87 +                    return diags.create(preferredKind, preferredSource, pos,
    1.88                              "prob.found.req", cause);
    1.89                  }
    1.90              });

mercurial