Wed, 15 May 2013 14:00:31 +0100
8012003: Method diagnostics resolution need to be simplified in some cases
Summary: Unfold method resolution diagnostics when they mention errors in poly expressions
Reviewed-by: jjg, vromero
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed May 15 00:00:39 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed May 15 14:00:31 2013 +0100 1.3 @@ -2391,7 +2391,8 @@ 1.4 for (JCDiagnostic deferredDiag : lambdaDeferredHandler.getDiagnostics()) { 1.5 if (deferredDiag.getKind() == JCDiagnostic.Kind.ERROR) { 1.6 resultInfo.checkContext 1.7 - .report(that, diags.fragment("bad.arg.types.in.lambda", TreeInfo.types(that.params))); 1.8 + .report(that, diags.fragment("bad.arg.types.in.lambda", TreeInfo.types(that.params), 1.9 + deferredDiag)); //hidden diag parameter 1.10 //we mark the lambda as erroneous - this is crucial in the recovery step 1.11 //as parameter-dependent type error won't be reported in that stage, 1.12 //meaning that a lambda will be deemed erroeneous only if there is
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed May 15 00:00:39 2013 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed May 15 14:00:31 2013 +0100 2.3 @@ -37,7 +37,10 @@ 2.4 import com.sun.tools.javac.comp.Infer.InferenceContext; 2.5 import com.sun.tools.javac.comp.Infer.FreeTypeListener; 2.6 import com.sun.tools.javac.comp.Resolve.MethodResolutionContext.Candidate; 2.7 +import com.sun.tools.javac.comp.Resolve.MethodResolutionDiagHelper.DiagnosticRewriter; 2.8 +import com.sun.tools.javac.comp.Resolve.MethodResolutionDiagHelper.Template; 2.9 import com.sun.tools.javac.jvm.*; 2.10 +import com.sun.tools.javac.main.Option; 2.11 import com.sun.tools.javac.tree.*; 2.12 import com.sun.tools.javac.tree.JCTree.*; 2.13 import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind; 2.14 @@ -94,6 +97,7 @@ 2.15 public final boolean allowDefaultMethods; 2.16 public final boolean allowStructuralMostSpecific; 2.17 private final boolean debugResolve; 2.18 + private final boolean compactMethodDiags; 2.19 final EnumSet<VerboseResolutionMode> verboseResolutionMode; 2.20 2.21 Scope polymorphicSignatureScope; 2.22 @@ -124,6 +128,8 @@ 2.23 varargsEnabled = source.allowVarargs(); 2.24 Options options = Options.instance(context); 2.25 debugResolve = options.isSet("debugresolve"); 2.26 + compactMethodDiags = options.isSet(Option.XDIAGS, "compact") || 2.27 + options.isUnset(Option.XDIAGS) && options.isUnset("rawDiagnostics"); 2.28 verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options); 2.29 Target target = Target.instance(context); 2.30 allowMethodHandles = target.hasMethodHandles(); 2.31 @@ -661,6 +667,10 @@ 2.32 this.basicKey = basicKey; 2.33 this.inferKey = inferKey; 2.34 } 2.35 + 2.36 + String regex() { 2.37 + return String.format("([a-z]*\\.)*(%s|%s)", basicKey, inferKey); 2.38 + } 2.39 } 2.40 2.41 /** 2.42 @@ -691,6 +701,7 @@ 2.43 Warner warn) { 2.44 //should we expand formals? 2.45 boolean useVarargs = deferredAttrContext.phase.isVarargsRequired(); 2.46 + List<JCExpression> trees = TreeInfo.args(env.tree); 2.47 2.48 //inference context used during this method check 2.49 InferenceContext inferenceContext = deferredAttrContext.inferenceContext; 2.50 @@ -699,17 +710,19 @@ 2.51 2.52 if (varargsFormal == null && 2.53 argtypes.size() != formals.size()) { 2.54 - reportMC(MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 2.55 + reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 2.56 } 2.57 2.58 while (argtypes.nonEmpty() && formals.head != varargsFormal) { 2.59 - checkArg(false, argtypes.head, formals.head, deferredAttrContext, warn); 2.60 + DiagnosticPosition pos = trees != null ? trees.head : null; 2.61 + checkArg(pos, false, argtypes.head, formals.head, deferredAttrContext, warn); 2.62 argtypes = argtypes.tail; 2.63 formals = formals.tail; 2.64 + trees = trees != null ? trees.tail : trees; 2.65 } 2.66 2.67 if (formals.head != varargsFormal) { 2.68 - reportMC(MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 2.69 + reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 2.70 } 2.71 2.72 if (useVarargs) { 2.73 @@ -717,8 +730,10 @@ 2.74 //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) 2.75 final Type elt = types.elemtype(varargsFormal); 2.76 while (argtypes.nonEmpty()) { 2.77 - checkArg(true, argtypes.head, elt, deferredAttrContext, warn); 2.78 + DiagnosticPosition pos = trees != null ? trees.head : null; 2.79 + checkArg(pos, true, argtypes.head, elt, deferredAttrContext, warn); 2.80 argtypes = argtypes.tail; 2.81 + trees = trees != null ? trees.tail : trees; 2.82 } 2.83 } 2.84 } 2.85 @@ -726,9 +741,9 @@ 2.86 /** 2.87 * Does the actual argument conforms to the corresponding formal? 2.88 */ 2.89 - abstract void checkArg(boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn); 2.90 - 2.91 - protected void reportMC(MethodCheckDiag diag, InferenceContext inferenceContext, Object... args) { 2.92 + abstract void checkArg(DiagnosticPosition pos, boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn); 2.93 + 2.94 + protected void reportMC(DiagnosticPosition pos, MethodCheckDiag diag, InferenceContext inferenceContext, Object... args) { 2.95 boolean inferDiag = inferenceContext != infer.emptyContext; 2.96 InapplicableMethodException ex = inferDiag ? 2.97 infer.inferenceException : inapplicableMethodException; 2.98 @@ -738,7 +753,8 @@ 2.99 args2[0] = inferenceContext.inferenceVars(); 2.100 args = args2; 2.101 } 2.102 - throw ex.setMessage(inferDiag ? diag.inferKey : diag.basicKey, args); 2.103 + String key = inferDiag ? diag.inferKey : diag.basicKey; 2.104 + throw ex.setMessage(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args)); 2.105 } 2.106 2.107 public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { 2.108 @@ -752,7 +768,7 @@ 2.109 */ 2.110 MethodCheck arityMethodCheck = new AbstractMethodCheck() { 2.111 @Override 2.112 - void checkArg(boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { 2.113 + void checkArg(DiagnosticPosition pos, boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { 2.114 //do nothing - actual always compatible to formals 2.115 } 2.116 }; 2.117 @@ -778,9 +794,9 @@ 2.118 MethodCheck resolveMethodCheck = new AbstractMethodCheck() { 2.119 2.120 @Override 2.121 - void checkArg(boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { 2.122 + void checkArg(DiagnosticPosition pos, boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { 2.123 ResultInfo mresult = methodCheckResult(varargs, formal, deferredAttrContext, warn); 2.124 - mresult.check(null, actual); 2.125 + mresult.check(pos, actual); 2.126 } 2.127 2.128 @Override 2.129 @@ -809,7 +825,7 @@ 2.130 } else { 2.131 if (!isAccessible(env, t)) { 2.132 Symbol location = env.enclClass.sym; 2.133 - reportMC(MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location); 2.134 + reportMC(env.tree, MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location); 2.135 } 2.136 } 2.137 } 2.138 @@ -822,7 +838,7 @@ 2.139 2.140 @Override 2.141 public void report(DiagnosticPosition pos, JCDiagnostic details) { 2.142 - reportMC(methodDiag, deferredAttrContext.inferenceContext, details); 2.143 + reportMC(pos, methodDiag, deferredAttrContext.inferenceContext, details); 2.144 } 2.145 }; 2.146 return new MethodResultInfo(to, checkContext); 2.147 @@ -3327,6 +3343,18 @@ 2.148 } 2.149 else { 2.150 Candidate c = errCandidate(); 2.151 + if (compactMethodDiags) { 2.152 + for (Map.Entry<Template, DiagnosticRewriter> _entry : 2.153 + MethodResolutionDiagHelper.rewriters.entrySet()) { 2.154 + if (_entry.getKey().matches(c.details)) { 2.155 + JCDiagnostic simpleDiag = 2.156 + _entry.getValue().rewriteDiagnostic(diags, pos, 2.157 + log.currentSource(), dkind, c.details); 2.158 + simpleDiag.setFlag(DiagnosticFlag.COMPRESSED); 2.159 + return simpleDiag; 2.160 + } 2.161 + } 2.162 + } 2.163 Symbol ws = c.sym.asMemberOf(site, types); 2.164 return diags.create(dkind, log.currentSource(), pos, 2.165 "cant.apply.symbol", 2.166 @@ -3375,35 +3403,75 @@ 2.167 Name name, 2.168 List<Type> argtypes, 2.169 List<Type> typeargtypes) { 2.170 - if (!resolveContext.candidates.isEmpty()) { 2.171 + Map<Symbol, JCDiagnostic> candidatesMap = mapCandidates(); 2.172 + Map<Symbol, JCDiagnostic> filteredCandidates = filterCandidates(candidatesMap); 2.173 + if (filteredCandidates.isEmpty()) { 2.174 + filteredCandidates = candidatesMap; 2.175 + } 2.176 + boolean truncatedDiag = candidatesMap.size() != filteredCandidates.size(); 2.177 + if (filteredCandidates.size() > 1) { 2.178 JCDiagnostic err = diags.create(dkind, 2.179 + null, 2.180 + truncatedDiag ? 2.181 + EnumSet.of(DiagnosticFlag.COMPRESSED) : 2.182 + EnumSet.noneOf(DiagnosticFlag.class), 2.183 log.currentSource(), 2.184 pos, 2.185 "cant.apply.symbols", 2.186 name == names.init ? KindName.CONSTRUCTOR : absentKind(kind), 2.187 name == names.init ? site.tsym.name : name, 2.188 methodArguments(argtypes)); 2.189 - return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site)); 2.190 + return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(filteredCandidates, site)); 2.191 + } else if (filteredCandidates.size() == 1) { 2.192 + JCDiagnostic d = new InapplicableSymbolError(resolveContext).getDiagnostic(dkind, pos, 2.193 + location, site, name, argtypes, typeargtypes); 2.194 + if (truncatedDiag) { 2.195 + d.setFlag(DiagnosticFlag.COMPRESSED); 2.196 + } 2.197 + return d; 2.198 } else { 2.199 return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, pos, 2.200 location, site, name, argtypes, typeargtypes); 2.201 } 2.202 } 2.203 - 2.204 //where 2.205 - List<JCDiagnostic> candidateDetails(Type site) { 2.206 - Map<Symbol, JCDiagnostic> details = new LinkedHashMap<Symbol, JCDiagnostic>(); 2.207 - for (Candidate c : resolveContext.candidates) { 2.208 - if (c.isApplicable()) continue; 2.209 - JCDiagnostic detailDiag = diags.fragment("inapplicable.method", 2.210 - Kinds.kindName(c.sym), 2.211 - c.sym.location(site, types), 2.212 - c.sym.asMemberOf(site, types), 2.213 - c.details); 2.214 - details.put(c.sym, detailDiag); 2.215 + private Map<Symbol, JCDiagnostic> mapCandidates() { 2.216 + Map<Symbol, JCDiagnostic> candidates = new LinkedHashMap<Symbol, JCDiagnostic>(); 2.217 + for (Candidate c : resolveContext.candidates) { 2.218 + if (c.isApplicable()) continue; 2.219 + candidates.put(c.sym, c.details); 2.220 + } 2.221 + return candidates; 2.222 } 2.223 - return List.from(details.values()); 2.224 - } 2.225 + 2.226 + Map<Symbol, JCDiagnostic> filterCandidates(Map<Symbol, JCDiagnostic> candidatesMap) { 2.227 + Map<Symbol, JCDiagnostic> candidates = new LinkedHashMap<Symbol, JCDiagnostic>(); 2.228 + for (Map.Entry<Symbol, JCDiagnostic> _entry : candidatesMap.entrySet()) { 2.229 + JCDiagnostic d = _entry.getValue(); 2.230 + if (!compactMethodDiags || 2.231 + !new Template(MethodCheckDiag.ARITY_MISMATCH.regex()).matches(d)) { 2.232 + candidates.put(_entry.getKey(), d); 2.233 + } 2.234 + } 2.235 + return candidates; 2.236 + } 2.237 + 2.238 + private List<JCDiagnostic> candidateDetails(Map<Symbol, JCDiagnostic> candidatesMap, Type site) { 2.239 + List<JCDiagnostic> details = List.nil(); 2.240 + for (Map.Entry<Symbol, JCDiagnostic> _entry : candidatesMap.entrySet()) { 2.241 + Symbol sym = _entry.getKey(); 2.242 + JCDiagnostic detailDiag = diags.fragment("inapplicable.method", 2.243 + Kinds.kindName(sym), 2.244 + sym.location(site, types), 2.245 + sym.asMemberOf(site, types), 2.246 + _entry.getValue()); 2.247 + details = details.prepend(detailDiag); 2.248 + } 2.249 + //typically members are visited in reverse order (see Scope) 2.250 + //so we need to reverse the candidate list so that candidates 2.251 + //conform to source order 2.252 + return details; 2.253 + } 2.254 } 2.255 2.256 /** 2.257 @@ -3624,6 +3692,105 @@ 2.258 } 2.259 } 2.260 2.261 + /** 2.262 + * Helper class for method resolution diagnostic simplification. 2.263 + * Certain resolution diagnostic are rewritten as simpler diagnostic 2.264 + * where the enclosing resolution diagnostic (i.e. 'inapplicable method') 2.265 + * is stripped away, as it doesn't carry additional info. The logic 2.266 + * for matching a given diagnostic is given in terms of a template 2.267 + * hierarchy: a diagnostic template can be specified programmatically, 2.268 + * so that only certain diagnostics are matched. Each templete is then 2.269 + * associated with a rewriter object that carries out the task of rewtiting 2.270 + * the diagnostic to a simpler one. 2.271 + */ 2.272 + static class MethodResolutionDiagHelper { 2.273 + 2.274 + /** 2.275 + * A diagnostic rewriter transforms a method resolution diagnostic 2.276 + * into a simpler one 2.277 + */ 2.278 + interface DiagnosticRewriter { 2.279 + JCDiagnostic rewriteDiagnostic(JCDiagnostic.Factory diags, 2.280 + DiagnosticPosition preferedPos, DiagnosticSource preferredSource, 2.281 + DiagnosticType preferredKind, JCDiagnostic d); 2.282 + } 2.283 + 2.284 + /** 2.285 + * A diagnostic template is made up of two ingredients: (i) a regular 2.286 + * expression for matching a diagnostic key and (ii) a list of sub-templates 2.287 + * for matching diagnostic arguments. 2.288 + */ 2.289 + static class Template { 2.290 + 2.291 + /** regex used to match diag key */ 2.292 + String regex; 2.293 + 2.294 + /** templates used to match diagnostic args */ 2.295 + Template[] subTemplates; 2.296 + 2.297 + Template(String key, Template... subTemplates) { 2.298 + this.regex = key; 2.299 + this.subTemplates = subTemplates; 2.300 + } 2.301 + 2.302 + /** 2.303 + * Returns true if the regex matches the diagnostic key and if 2.304 + * all diagnostic arguments are matches by corresponding sub-templates. 2.305 + */ 2.306 + boolean matches(Object o) { 2.307 + JCDiagnostic d = (JCDiagnostic)o; 2.308 + Object[] args = d.getArgs(); 2.309 + if (!d.getCode().matches(regex) || 2.310 + subTemplates.length != d.getArgs().length) { 2.311 + return false; 2.312 + } 2.313 + for (int i = 0; i < args.length ; i++) { 2.314 + if (!subTemplates[i].matches(args[i])) { 2.315 + return false; 2.316 + } 2.317 + } 2.318 + return true; 2.319 + } 2.320 + } 2.321 + 2.322 + /** a dummy template that match any diagnostic argument */ 2.323 + static final Template skip = new Template("") { 2.324 + @Override 2.325 + boolean matches(Object d) { 2.326 + return true; 2.327 + } 2.328 + }; 2.329 + 2.330 + /** rewriter map used for method resolution simplification */ 2.331 + static final Map<Template, DiagnosticRewriter> rewriters = 2.332 + new LinkedHashMap<Template, DiagnosticRewriter>(); 2.333 + 2.334 + static { 2.335 + String argMismatchRegex = MethodCheckDiag.ARG_MISMATCH.regex(); 2.336 + rewriters.put(new Template(argMismatchRegex, new Template("(.*)(bad.arg.types.in.lambda)", skip, skip)), 2.337 + new DiagnosticRewriter() { 2.338 + @Override 2.339 + public JCDiagnostic rewriteDiagnostic(JCDiagnostic.Factory diags, 2.340 + DiagnosticPosition preferedPos, DiagnosticSource preferredSource, 2.341 + DiagnosticType preferredKind, JCDiagnostic d) { 2.342 + return (JCDiagnostic)((JCDiagnostic)d.getArgs()[0]).getArgs()[1]; 2.343 + } 2.344 + }); 2.345 + 2.346 + rewriters.put(new Template(argMismatchRegex, skip), 2.347 + new DiagnosticRewriter() { 2.348 + @Override 2.349 + public JCDiagnostic rewriteDiagnostic(JCDiagnostic.Factory diags, 2.350 + DiagnosticPosition preferedPos, DiagnosticSource preferredSource, 2.351 + DiagnosticType preferredKind, JCDiagnostic d) { 2.352 + JCDiagnostic cause = (JCDiagnostic)d.getArgs()[0]; 2.353 + return diags.create(preferredKind, preferredSource, d.getDiagnosticPosition(), 2.354 + "prob.found.req", cause); 2.355 + } 2.356 + }); 2.357 + } 2.358 + } 2.359 + 2.360 enum MethodResolutionPhase { 2.361 BASIC(false, false), 2.362 BOX(true, false),
3.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Wed May 15 00:00:39 2013 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Wed May 15 14:00:31 2013 +0100 3.3 @@ -1614,6 +1614,9 @@ 3.4 log.warning("proc.use.proc.or.implicit"); 3.5 } 3.6 chk.reportDeferredDiagnostics(); 3.7 + if (log.compressedOutput) { 3.8 + log.mandatoryNote(null, "compressed.diags"); 3.9 + } 3.10 } 3.11 3.12 /** Close the compiler, flushing the logs
4.1 --- a/src/share/classes/com/sun/tools/javac/main/Option.java Wed May 15 00:00:39 2013 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/main/Option.java Wed May 15 14:00:31 2013 +0100 4.3 @@ -407,6 +407,8 @@ 4.4 } 4.5 }, 4.6 4.7 + XDIAGS("-Xdiags:", "opt.diags", EXTENDED, BASIC, ONEOF, "compact", "verbose"), 4.8 + 4.9 /* This is a back door to the compiler's option table. 4.10 * -XDx=y sets the option x to the value y. 4.11 * -XDx sets the option x to the value x.
5.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Wed May 15 00:00:39 2013 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Wed May 15 14:00:31 2013 +0100 5.3 @@ -227,11 +227,13 @@ 5.4 5.5 # 0: symbol kind, 1: message segment 5.6 compiler.err.invalid.mref=\ 5.7 - invalid {0} reference; {1} 5.8 + invalid {0} reference\n\ 5.9 + {1} 5.10 5.11 # 0: symbol kind, 1: message segment 5.12 compiler.misc.invalid.mref=\ 5.13 - invalid {0} reference; {1} 5.14 + invalid {0} reference\n\ 5.15 + {1} 5.16 5.17 compiler.misc.static.mref.with.targs=\ 5.18 parameterized qualifier on static method reference 5.19 @@ -714,7 +716,8 @@ 5.20 5.21 # 0: message segment 5.22 compiler.misc.incompatible.type.in.conditional=\ 5.23 - bad type in conditional expression; {0} 5.24 + bad type in conditional expression\n\ 5.25 + {0} 5.26 5.27 compiler.misc.conditional.target.cant.be.void=\ 5.28 target-type for conditional expression cannot be void 5.29 @@ -743,7 +746,7 @@ 5.30 compiler.misc.incompatible.arg.types.in.mref=\ 5.31 incompatible parameter types in method reference 5.32 5.33 -# 0: list of type 5.34 +# 0: list of type, 1: message segment 5.35 compiler.misc.bad.arg.types.in.lambda=\ 5.36 cannot type-check lambda expression with inferred parameter types\n\ 5.37 inferred types: {0} 5.38 @@ -1154,6 +1157,9 @@ 5.39 ## The following string will appear before all messages keyed as: 5.40 ## "compiler.note". 5.41 5.42 +compiler.note.compressed.diags=\ 5.43 + Some messages have been simplified; recompile with -Xdiags:verbose to get full output 5.44 + 5.45 compiler.note.potential.lambda.found=\ 5.46 This anonymous inner class creation can be turned into a lambda expression. 5.47 5.48 @@ -1742,6 +1748,10 @@ 5.49 compiler.err.prob.found.req=\ 5.50 incompatible types: {0} 5.51 5.52 +# 0: message segment 5.53 +compiler.misc.prob.found.req=\ 5.54 + incompatible types: {0} 5.55 + 5.56 # 0: message segment, 1: type, 2: type 5.57 compiler.warn.prob.found.req=\ 5.58 {0}\n\
6.1 --- a/src/share/classes/com/sun/tools/javac/resources/javac.properties Wed May 15 00:00:39 2013 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/resources/javac.properties Wed May 15 14:00:31 2013 +0100 6.3 @@ -168,6 +168,8 @@ 6.4 Specify which file to read when both a source file and class file are found for an implicitly compiled class 6.5 javac.opt.AT=\ 6.6 Read options and filenames from file 6.7 +javac.opt.diags=\ 6.8 + Select a diagnostic mode 6.9 6.10 ## errors 6.11
7.1 --- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Wed May 15 00:00:39 2013 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Wed May 15 14:00:31 2013 +0100 7.3 @@ -349,6 +349,7 @@ 7.4 SYNTAX, 7.5 RECOVERABLE, 7.6 NON_DEFERRABLE, 7.7 + COMPRESSED 7.8 } 7.9 7.10 private final DiagnosticType type;
8.1 --- a/src/share/classes/com/sun/tools/javac/util/List.java Wed May 15 00:00:39 2013 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/util/List.java Wed May 15 14:00:31 2013 +0100 8.3 @@ -154,11 +154,11 @@ 8.4 } 8.5 8.6 public static <A> List<A> from(Iterable<? extends A> coll) { 8.7 - List<A> xs = nil(); 8.8 + ListBuffer<A> xs = ListBuffer.lb(); 8.9 for (A a : coll) { 8.10 - xs = new List<A>(a, xs); 8.11 + xs.append(a); 8.12 } 8.13 - return xs; 8.14 + return xs.toList(); 8.15 } 8.16 8.17 /** Construct a list consisting of a given number of identical elements.
9.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java Wed May 15 00:00:39 2013 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java Wed May 15 14:00:31 2013 +0100 9.3 @@ -214,6 +214,11 @@ 9.4 public Set<String> expectDiagKeys; 9.5 9.6 /** 9.7 + * Set to true if a compressed diagnostic is reported 9.8 + */ 9.9 + public boolean compressedOutput; 9.10 + 9.11 + /** 9.12 * JavacMessages object used for localization. 9.13 */ 9.14 private JavacMessages messages; 9.15 @@ -597,6 +602,9 @@ 9.16 } 9.17 break; 9.18 } 9.19 + if (diagnostic.isFlagSet(JCDiagnostic.DiagnosticFlag.COMPRESSED)) { 9.20 + compressedOutput = true; 9.21 + } 9.22 } 9.23 } 9.24
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/tools/javac/Diagnostics/compressed/T8012003a.java Wed May 15 14:00:31 2013 +0100 10.3 @@ -0,0 +1,24 @@ 10.4 +/** 10.5 + * @test /nodynamiccopyright/ 10.6 + * @bug 8012003 10.7 + * @summary Method diagnostics resolution need to be simplified in some cases 10.8 + * test general overload resolution simplifications 10.9 + * @compile/fail/ref=T8012003a.out -XDrawDiagnostics -Xdiags:compact T8012003a.java 10.10 + */ 10.11 + 10.12 +class T8012003a { 10.13 + void m1(Integer i) { } 10.14 + 10.15 + void m2(Integer i) { } 10.16 + void m2(Integer i, Object o) { } 10.17 + 10.18 + void m3(Integer i) { } 10.19 + void m3(String s) { } 10.20 + 10.21 + void test() { 10.22 + m1(""); 10.23 + m1(false ? "" : ""); 10.24 + m2(""); 10.25 + m3('x'); 10.26 + } 10.27 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/tools/javac/Diagnostics/compressed/T8012003a.out Wed May 15 14:00:31 2013 +0100 11.3 @@ -0,0 +1,6 @@ 11.4 +T8012003a.java:19:12: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer) 11.5 +T8012003a.java:20:20: compiler.err.prob.found.req: (compiler.misc.incompatible.type.in.conditional: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)) 11.6 +T8012003a.java:21:12: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer) 11.7 +T8012003a.java:22:9: compiler.err.cant.apply.symbols: kindname.method, m3, char,{(compiler.misc.inapplicable.method: kindname.method, T8012003a, m3(java.lang.Integer), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: char, java.lang.Integer))),(compiler.misc.inapplicable.method: kindname.method, T8012003a, m3(java.lang.String), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: char, java.lang.String)))} 11.8 +- compiler.note.compressed.diags 11.9 +4 errors
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javac/Diagnostics/compressed/T8012003b.java Wed May 15 14:00:31 2013 +0100 12.3 @@ -0,0 +1,37 @@ 12.4 +/** 12.5 + * @test /nodynamiccopyright/ 12.6 + * @bug 8012003 12.7 + * @summary Method diagnostics resolution need to be simplified in some cases 12.8 + * test lambda-related overload resolution simplifications 12.9 + * @compile/fail/ref=T8012003b.out -XDrawDiagnostics -Xdiags:compact T8012003b.java 12.10 + */ 12.11 + 12.12 +class T8012003b { 12.13 + 12.14 + interface Consumer_V<X> { 12.15 + void m(X x); 12.16 + } 12.17 + 12.18 + interface Consumer_NV<X> { 12.19 + Integer m(X x); 12.20 + } 12.21 + 12.22 + void m1(Runnable r) { } 12.23 + void m1(Runnable r, String s) { } 12.24 + 12.25 + void m2(Consumer_V<Integer> ci) { } 12.26 + 12.27 + void m3(Consumer_NV<String> ci) { } 12.28 + 12.29 + void g(String arg) { } 12.30 + String g2(String arg) { return arg; } 12.31 + 12.32 + void test() { 12.33 + m1(this::g); 12.34 + m1(()->1); 12.35 + m1(()->false ? "" : ""); 12.36 + m2(this::g); 12.37 + m3(this::g2); 12.38 + m3(this::k); 12.39 + } 12.40 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javac/Diagnostics/compressed/T8012003b.out Wed May 15 14:00:31 2013 +0100 13.3 @@ -0,0 +1,8 @@ 13.4 +T8012003b.java:30:12: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, g, java.lang.String, compiler.misc.no.args, kindname.class, T8012003b, (compiler.misc.arg.length.mismatch))) 13.5 +T8012003b.java:31:16: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: int, void)) 13.6 +T8012003b.java:32:22: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.conditional.target.cant.be.void)) 13.7 +T8012003b.java:33:12: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Integer, java.lang.String))) 13.8 +T8012003b.java:34:12: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.mref: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)) 13.9 +T8012003b.java:35:12: compiler.err.invalid.mref: kindname.method, (compiler.misc.cant.resolve.location.args: kindname.method, k, , , (compiler.misc.location: kindname.class, T8012003b, null)) 13.10 +- compiler.note.compressed.diags 13.11 +6 errors
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/Diagnostics/compressed/T8012003c.java Wed May 15 14:00:31 2013 +0100 14.3 @@ -0,0 +1,24 @@ 14.4 +/** 14.5 + * @test /nodynamiccopyright/ 14.6 + * @bug 8012003 14.7 + * @summary Method diagnostics resolution need to be simplified in some cases 14.8 + * test simplification of lambda type-checking error leading to resolution failure 14.9 + * @compile/fail/ref=T8012003c.out -XDrawDiagnostics -Xdiags:compact T8012003c.java 14.10 + */ 14.11 + 14.12 +class T8012003c { 14.13 + 14.14 + interface I { 14.15 + void m(P p); 14.16 + } 14.17 + 14.18 + void m(I i) { } 14.19 + 14.20 + void test() { 14.21 + m(p->p.m()); 14.22 + } 14.23 +} 14.24 + 14.25 +class P { 14.26 + private void m() { } 14.27 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javac/Diagnostics/compressed/T8012003c.out Wed May 15 14:00:31 2013 +0100 15.3 @@ -0,0 +1,3 @@ 15.4 +T8012003c.java:18:15: compiler.err.report.access: m(), private, P 15.5 +- compiler.note.compressed.diags 15.6 +1 error
16.1 --- a/test/tools/javac/diags/examples/BadArgTypesInLambda.java Wed May 15 00:00:39 2013 -0700 16.2 +++ b/test/tools/javac/diags/examples/BadArgTypesInLambda.java Wed May 15 14:00:31 2013 +0100 16.3 @@ -24,6 +24,9 @@ 16.4 // key: compiler.err.cant.apply.symbol 16.5 // key: compiler.misc.no.conforming.assignment.exists 16.6 // key: compiler.misc.bad.arg.types.in.lambda 16.7 +// key: compiler.err.prob.found.req 16.8 +// key: compiler.misc.inconvertible.types 16.9 +// options: -Xdiags:verbose 16.10 16.11 class BadArgTypesInLambda { 16.12 interface SAM {
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javac/diags/examples/CompressedDiags.java Wed May 15 14:00:31 2013 +0100 17.3 @@ -0,0 +1,39 @@ 17.4 +/* 17.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.7 + * 17.8 + * This code is free software; you can redistribute it and/or modify it 17.9 + * under the terms of the GNU General Public License version 2 only, as 17.10 + * published by the Free Software Foundation. 17.11 + * 17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17.15 + * version 2 for more details (a copy is included in the LICENSE file that 17.16 + * accompanied this code). 17.17 + * 17.18 + * You should have received a copy of the GNU General Public License version 17.19 + * 2 along with this work; if not, write to the Free Software Foundation, 17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17.21 + * 17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 17.23 + * or visit www.oracle.com if you need additional information or have any 17.24 + * questions. 17.25 + */ 17.26 + 17.27 +// key: compiler.err.prob.found.req 17.28 +// key: compiler.misc.inconvertible.types 17.29 +// key: compiler.note.compressed.diags 17.30 +// key: compiler.note.note 17.31 +// key: compiler.misc.count.error 17.32 +// key: compiler.err.error 17.33 +// run: backdoor 17.34 + 17.35 +class CompressedDiags { 17.36 + 17.37 + void m(String s) { } 17.38 + 17.39 + void test() { 17.40 + m(1); 17.41 + } 17.42 +}
18.1 --- a/test/tools/javac/diags/examples/KindnameConstructor.java Wed May 15 00:00:39 2013 -0700 18.2 +++ b/test/tools/javac/diags/examples/KindnameConstructor.java Wed May 15 14:00:31 2013 +0100 18.3 @@ -28,6 +28,7 @@ 18.4 // key: compiler.misc.inconvertible.types 18.5 // key: compiler.misc.count.error 18.6 // key: compiler.err.error 18.7 +// options: -Xdiags:verbose 18.8 // run: backdoor 18.9 18.10 class KindnameConstructor {
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/tools/javac/diags/examples/ProbFoundReqFragment.java Wed May 15 14:00:31 2013 +0100 19.3 @@ -0,0 +1,44 @@ 19.4 +/* 19.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, as 19.10 + * published by the Free Software Foundation. 19.11 + * 19.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.15 + * version 2 for more details (a copy is included in the LICENSE file that 19.16 + * accompanied this code). 19.17 + * 19.18 + * You should have received a copy of the GNU General Public License version 19.19 + * 2 along with this work; if not, write to the Free Software Foundation, 19.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.21 + * 19.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19.23 + * or visit www.oracle.com if you need additional information or have any 19.24 + * questions. 19.25 + */ 19.26 + 19.27 +// key: compiler.err.prob.found.req 19.28 +// key: compiler.misc.prob.found.req 19.29 +// key: compiler.misc.inconvertible.types 19.30 +// key: compiler.misc.invalid.mref 19.31 +// key: compiler.misc.kindname.method 19.32 +// key: compiler.misc.count.error 19.33 +// key: compiler.err.error 19.34 +// run: backdoor 19.35 + 19.36 +class ProbFoundReqFragment { 19.37 + 19.38 + interface I { 19.39 + void g(int i); 19.40 + } 19.41 + 19.42 + void m(String s) { } 19.43 + 19.44 + void test() { 19.45 + I i = this::m; 19.46 + } 19.47 +}
20.1 --- a/test/tools/javac/lambda/TargetType66.out Wed May 15 00:00:39 2013 -0700 20.2 +++ b/test/tools/javac/lambda/TargetType66.out Wed May 15 14:00:31 2013 +0100 20.3 @@ -1,4 +1,4 @@ 20.4 TargetType66.java:22:9: compiler.err.ref.ambiguous: g, kindname.method, g(TargetType66.SAM1), TargetType66, kindname.method, g(TargetType66.SAM2), TargetType66 20.5 -TargetType66.java:23:9: compiler.err.cant.apply.symbols: kindname.method, g, @578,{(compiler.misc.inapplicable.method: kindname.method, TargetType66, g(TargetType66.SAM1), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.bad.arg.types.in.lambda: java.lang.String))),(compiler.misc.inapplicable.method: kindname.method, TargetType66, g(TargetType66.SAM2), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.bad.arg.types.in.lambda: java.lang.Integer)))} 20.6 +TargetType66.java:23:9: compiler.err.cant.apply.symbols: kindname.method, g, @578,{(compiler.misc.inapplicable.method: kindname.method, TargetType66, g(TargetType66.SAM1), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.bad.arg.types.in.lambda: java.lang.String, (compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Character))))),(compiler.misc.inapplicable.method: kindname.method, TargetType66, g(TargetType66.SAM2), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.bad.arg.types.in.lambda: java.lang.Integer, (compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Integer, java.lang.Character)))))} 20.7 TargetType66.java:24:30: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Character) 20.8 3 errors