author | mcimadamore |
Mon, 01 Jul 2013 14:57:03 +0100 | |
changeset 18668 | 1f99c1b43ab2 |
parent 17804 | 6bed8a263318 |
child 22448 | a85fbad9d687 |
permissions | -rw-r--r-- |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
1 |
/* |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
4 |
* |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
8 |
* |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
13 |
* accompanied this code). |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
14 |
* |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
18 |
* |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
21 |
* questions. |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
22 |
*/ |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
23 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
24 |
/* |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
25 |
* @test |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
26 |
* @bug 7098660 |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
27 |
* @summary Write better overload resolution/inference tests |
14963
974d4423c999
8005282: Use @library tag with non-relative path for javac tests
darcy
parents:
10816
diff
changeset
|
28 |
* @library /tools/javac/lib |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
29 |
* @build JavacTestingAbstractProcessor ResolveHarness |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
30 |
* @run main ResolveHarness |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
31 |
*/ |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
32 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
33 |
import com.sun.source.util.JavacTask; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
34 |
import com.sun.tools.javac.api.ClientCodeWrapper.DiagnosticSourceUnwrapper; |
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
35 |
import com.sun.tools.javac.code.Flags; |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
36 |
import com.sun.tools.javac.code.Symbol; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
37 |
import com.sun.tools.javac.code.Type.MethodType; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
38 |
import com.sun.tools.javac.util.JCDiagnostic; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
39 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
40 |
import java.io.File; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
41 |
import java.util.Set; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
42 |
import java.util.Arrays; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
43 |
import java.util.ArrayList; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
44 |
import java.util.Collections; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
45 |
import java.util.HashMap; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
46 |
import java.util.HashSet; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
47 |
import java.util.List; |
17804
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
48 |
import java.util.Locale; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
49 |
import java.util.Map; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
50 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
51 |
import javax.annotation.processing.AbstractProcessor; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
52 |
import javax.annotation.processing.RoundEnvironment; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
53 |
import javax.annotation.processing.SupportedAnnotationTypes; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
54 |
import javax.lang.model.element.Element; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
55 |
import javax.lang.model.element.TypeElement; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
56 |
import javax.tools.Diagnostic; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
57 |
import javax.tools.Diagnostic.Kind; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
58 |
import javax.tools.DiagnosticListener; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
59 |
import javax.tools.JavaCompiler; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
60 |
import javax.tools.JavaFileObject; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
61 |
import javax.tools.StandardJavaFileManager; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
62 |
import javax.tools.ToolProvider; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
63 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
64 |
import static javax.tools.StandardLocation.*; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
65 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
66 |
public class ResolveHarness implements javax.tools.DiagnosticListener<JavaFileObject> { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
67 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
68 |
static int nerrors = 0; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
69 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
70 |
static final JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
71 |
static final StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
72 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
73 |
public static void main(String[] args) throws Exception { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
74 |
fm.setLocation(SOURCE_PATH, |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
75 |
Arrays.asList(new File(System.getProperty("test.src"), "tests"))); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
76 |
for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
77 |
new ResolveHarness(jfo).check(); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
78 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
79 |
if (nerrors > 0) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
80 |
throw new AssertionError("Errors were found"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
81 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
82 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
83 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
84 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
85 |
JavaFileObject jfo; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
86 |
DiagnosticProcessor[] diagProcessors; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
87 |
Map<ElementKey, Candidate> candidatesMap = new HashMap<ElementKey, Candidate>(); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
88 |
Set<String> declaredKeys = new HashSet<>(); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
89 |
List<Diagnostic<? extends JavaFileObject>> diags = new ArrayList<>(); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
90 |
List<ElementKey> seenCandidates = new ArrayList<>(); |
17804
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
91 |
Map<String, String> predefTranslationMap = new HashMap<>(); |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
92 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
93 |
protected ResolveHarness(JavaFileObject jfo) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
94 |
this.jfo = jfo; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
95 |
this.diagProcessors = new DiagnosticProcessor[] { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
96 |
new VerboseResolutionNoteProcessor(), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
97 |
new VerboseDeferredInferenceNoteProcessor(), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
98 |
new ErrorProcessor() |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
99 |
}; |
17804
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
100 |
predefTranslationMap.put("+", "_plus"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
101 |
predefTranslationMap.put("-", "_minus"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
102 |
predefTranslationMap.put("~", "_not"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
103 |
predefTranslationMap.put("++", "_plusplus"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
104 |
predefTranslationMap.put("--", "_minusminus"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
105 |
predefTranslationMap.put("!", "_bang"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
106 |
predefTranslationMap.put("*", "_mul"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
107 |
predefTranslationMap.put("/", "_div"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
108 |
predefTranslationMap.put("%", "_mod"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
109 |
predefTranslationMap.put("&", "_and"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
110 |
predefTranslationMap.put("|", "_or"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
111 |
predefTranslationMap.put("^", "_xor"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
112 |
predefTranslationMap.put("<<", "_lshift"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
113 |
predefTranslationMap.put(">>", "_rshift"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
114 |
predefTranslationMap.put("<<<", "_lshiftshift"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
115 |
predefTranslationMap.put(">>>", "_rshiftshift"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
116 |
predefTranslationMap.put("<", "_lt"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
117 |
predefTranslationMap.put(">", "_gt"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
118 |
predefTranslationMap.put("<=", "_lteq"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
119 |
predefTranslationMap.put(">=", "_gteq"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
120 |
predefTranslationMap.put("==", "_eq"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
121 |
predefTranslationMap.put("!=", "_neq"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
122 |
predefTranslationMap.put("&&", "_andand"); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
123 |
predefTranslationMap.put("||", "_oror"); |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
124 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
125 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
126 |
protected void check() throws Exception { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
127 |
String[] options = { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
128 |
"-XDshouldStopPolicy=ATTR", |
17804
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
129 |
"-XDverboseResolution=success,failure,applicable,inapplicable,deferred-inference,predef" |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
130 |
}; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
131 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
132 |
AbstractProcessor[] processors = { new ResolveCandidateFinder(), null }; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
133 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
134 |
@SuppressWarnings("unchecked") |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
135 |
DiagnosticListener<? super JavaFileObject>[] diagListeners = |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
136 |
new DiagnosticListener[] { new DiagnosticHandler(false), new DiagnosticHandler(true) }; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
137 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
138 |
for (int i = 0 ; i < options.length ; i ++) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
139 |
JavacTask ct = (JavacTask)comp.getTask(null, fm, diagListeners[i], |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
140 |
Arrays.asList(options[i]), null, Arrays.asList(jfo)); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
141 |
if (processors[i] != null) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
142 |
ct.setProcessors(Collections.singleton(processors[i])); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
143 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
144 |
ct.analyze(); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
145 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
146 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
147 |
//check diags |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
148 |
for (Diagnostic<? extends JavaFileObject> diag : diags) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
149 |
for (DiagnosticProcessor proc : diagProcessors) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
150 |
if (proc.matches(diag)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
151 |
proc.process(diag); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
152 |
break; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
153 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
154 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
155 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
156 |
//check all candidates have been used up |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
157 |
for (Map.Entry<ElementKey, Candidate> entry : candidatesMap.entrySet()) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
158 |
if (!seenCandidates.contains(entry.getKey())) { |
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
159 |
error("Redundant @Candidate annotation on method " + entry.getKey().elem + " sig = " + entry.getKey().elem.asType()); |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
160 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
161 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
162 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
163 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
164 |
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
165 |
diags.add(diagnostic); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
166 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
167 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
168 |
Candidate getCandidateAtPos(Element methodSym, long line, long col) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
169 |
Candidate c = candidatesMap.get(new ElementKey(methodSym)); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
170 |
if (c != null) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
171 |
Pos pos = c.pos(); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
172 |
if (!pos.userDefined() || |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
173 |
(pos.line() == line && pos.col() == col)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
174 |
seenCandidates.add(new ElementKey(methodSym)); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
175 |
return c; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
176 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
177 |
} else { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
178 |
error("Missing @Candidate annotation on method " + methodSym); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
179 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
180 |
return null; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
181 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
182 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
183 |
void checkSig(Candidate c, Element methodSym, MethodType mtype) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
184 |
if (c.sig().length() > 0 && !c.sig().equals(mtype.toString())) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
185 |
error("Inferred type mismatch for method: " + methodSym); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
186 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
187 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
188 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
189 |
protected void error(String msg) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
190 |
nerrors++; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
191 |
System.err.printf("Error occurred while checking file: %s\nreason: %s\n", jfo.getName(), msg); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
192 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
193 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
194 |
/** |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
195 |
* Base class for diagnostic processor. It provides methods for matching and |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
196 |
* processing a given diagnostic object (overridden by subclasses). |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
197 |
*/ |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
198 |
abstract class DiagnosticProcessor { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
199 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
200 |
List<String> codes; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
201 |
Diagnostic.Kind kind; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
202 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
203 |
public DiagnosticProcessor(Kind kind, String... codes) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
204 |
this.codes = Arrays.asList(codes); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
205 |
this.kind = kind; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
206 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
207 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
208 |
abstract void process(Diagnostic<? extends JavaFileObject> diagnostic); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
209 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
210 |
boolean matches(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
211 |
return (codes.isEmpty() || codes.contains(diagnostic.getCode())) && |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
212 |
diagnostic.getKind() == kind; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
213 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
214 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
215 |
JCDiagnostic asJCDiagnostic(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
216 |
if (diagnostic instanceof JCDiagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
217 |
return (JCDiagnostic)diagnostic; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
218 |
} else if (diagnostic instanceof DiagnosticSourceUnwrapper) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
219 |
return ((DiagnosticSourceUnwrapper)diagnostic).d; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
220 |
} else { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
221 |
throw new AssertionError("Cannot convert diagnostic to JCDiagnostic: " + diagnostic.getClass().getName()); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
222 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
223 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
224 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
225 |
List<JCDiagnostic> subDiagnostics(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
226 |
JCDiagnostic diag = asJCDiagnostic(diagnostic); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
227 |
if (diag instanceof JCDiagnostic.MultilineDiagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
228 |
return ((JCDiagnostic.MultilineDiagnostic)diag).getSubdiagnostics(); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
229 |
} else { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
230 |
throw new AssertionError("Cannot extract subdiagnostics: " + diag.getClass().getName()); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
231 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
232 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
233 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
234 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
235 |
/** |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
236 |
* Processor for verbose resolution notes generated by javac. The processor |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
237 |
* checks that the diagnostic is associated with a method declared by |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
238 |
* a class annotated with the special @TraceResolve marker annotation. If |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
239 |
* that's the case, all subdiagnostics (one for each resolution candidate) |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
240 |
* are checked against the corresponding @Candidate annotations, using |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
241 |
* a VerboseCandidateSubdiagProcessor. |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
242 |
*/ |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
243 |
class VerboseResolutionNoteProcessor extends DiagnosticProcessor { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
244 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
245 |
VerboseResolutionNoteProcessor() { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
246 |
super(Kind.NOTE, |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
247 |
"compiler.note.verbose.resolve.multi", |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
248 |
"compiler.note.verbose.resolve.multi.1"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
249 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
250 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
251 |
@Override |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
252 |
void process(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
253 |
Element siteSym = getSiteSym(diagnostic); |
17804
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
254 |
if (siteSym.getSimpleName().length() != 0 && |
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
255 |
((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) { |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
256 |
return; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
257 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
258 |
int candidateIdx = 0; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
259 |
for (JCDiagnostic d : subDiagnostics(diagnostic)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
260 |
boolean isMostSpecific = candidateIdx++ == mostSpecific(diagnostic); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
261 |
VerboseCandidateSubdiagProcessor subProc = |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
262 |
new VerboseCandidateSubdiagProcessor(isMostSpecific, phase(diagnostic), success(diagnostic)); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
263 |
if (subProc.matches(d)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
264 |
subProc.process(d); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
265 |
} else { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
266 |
throw new AssertionError("Bad subdiagnostic: " + d.getCode()); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
267 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
268 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
269 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
270 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
271 |
Element getSiteSym(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
272 |
return (Element)asJCDiagnostic(diagnostic).getArgs()[1]; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
273 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
274 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
275 |
int mostSpecific(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
276 |
return success(diagnostic) ? |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
277 |
(Integer)asJCDiagnostic(diagnostic).getArgs()[2] : -1; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
278 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
279 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
280 |
boolean success(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
281 |
return diagnostic.getCode().equals("compiler.note.verbose.resolve.multi"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
282 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
283 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
284 |
Phase phase(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
285 |
return Phase.fromString(asJCDiagnostic(diagnostic).getArgs()[3].toString()); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
286 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
287 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
288 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
289 |
/** |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
290 |
* Processor for verbose resolution subdiagnostic notes generated by javac. |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
291 |
* The processor checks that the details of the overload candidate |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
292 |
* match against the info contained in the corresponding @Candidate |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
293 |
* annotation (if any). |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
294 |
*/ |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
295 |
class VerboseCandidateSubdiagProcessor extends DiagnosticProcessor { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
296 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
297 |
boolean mostSpecific; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
298 |
Phase phase; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
299 |
boolean success; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
300 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
301 |
public VerboseCandidateSubdiagProcessor(boolean mostSpecific, Phase phase, boolean success) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
302 |
super(Kind.OTHER, |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
303 |
"compiler.misc.applicable.method.found", |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
304 |
"compiler.misc.applicable.method.found.1", |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
305 |
"compiler.misc.not.applicable.method.found"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
306 |
this.mostSpecific = mostSpecific; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
307 |
this.phase = phase; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
308 |
this.success = success; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
309 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
310 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
311 |
@Override |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
312 |
void process(Diagnostic<? extends JavaFileObject> diagnostic) { |
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
313 |
Symbol methodSym = (Symbol)methodSym(diagnostic); |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
314 |
if ((methodSym.flags() & Flags.GENERATEDCONSTR) != 0) { |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
315 |
//skip resolution of default constructor (put there by javac) |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
316 |
return; |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
317 |
} |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
318 |
Candidate c = getCandidateAtPos(methodSym, |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
319 |
asJCDiagnostic(diagnostic).getLineNumber(), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
320 |
asJCDiagnostic(diagnostic).getColumnNumber()); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
321 |
if (c == null) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
322 |
return; //nothing to check |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
323 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
324 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
325 |
if (c.applicable().length == 0 && c.mostSpecific()) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
326 |
error("Inapplicable method cannot be most specific " + methodSym); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
327 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
328 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
329 |
if (isApplicable(diagnostic) != Arrays.asList(c.applicable()).contains(phase)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
330 |
error("Invalid candidate's applicability " + methodSym); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
331 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
332 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
333 |
if (success) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
334 |
for (Phase p : c.applicable()) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
335 |
if (phase.ordinal() < p.ordinal()) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
336 |
error("Invalid phase " + p + " on method " + methodSym); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
337 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
338 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
339 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
340 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
341 |
if (Arrays.asList(c.applicable()).contains(phase)) { //applicable |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
342 |
if (c.mostSpecific() != mostSpecific) { |
17804
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
14963
diff
changeset
|
343 |
error("Invalid most specific value for method " + methodSym + " " + new ElementKey(methodSym).key); |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
344 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
345 |
MethodType mtype = getSig(diagnostic); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
346 |
if (mtype != null) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
347 |
checkSig(c, methodSym, mtype); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
348 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
349 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
350 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
351 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
352 |
boolean isApplicable(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
353 |
return !diagnostic.getCode().equals("compiler.misc.not.applicable.method.found"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
354 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
355 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
356 |
Element methodSym(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
357 |
return (Element)asJCDiagnostic(diagnostic).getArgs()[1]; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
358 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
359 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
360 |
MethodType getSig(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
361 |
JCDiagnostic details = (JCDiagnostic)asJCDiagnostic(diagnostic).getArgs()[2]; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
362 |
if (details == null) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
363 |
return null; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
364 |
} else if (details instanceof JCDiagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
365 |
return details.getCode().equals("compiler.misc.full.inst.sig") ? |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
366 |
(MethodType)details.getArgs()[0] : null; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
367 |
} else { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
368 |
throw new AssertionError("Bad diagnostic arg: " + details); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
369 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
370 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
371 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
372 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
373 |
/** |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
374 |
* Processor for verbose deferred inference notes generated by javac. The |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
375 |
* processor checks that the inferred signature for a given generic method |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
376 |
* call corresponds to the one (if any) declared in the @Candidate annotation. |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
377 |
*/ |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
378 |
class VerboseDeferredInferenceNoteProcessor extends DiagnosticProcessor { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
379 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
380 |
public VerboseDeferredInferenceNoteProcessor() { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
381 |
super(Kind.NOTE, "compiler.note.deferred.method.inst"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
382 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
383 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
384 |
@Override |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
385 |
void process(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
386 |
Element methodSym = methodSym(diagnostic); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
387 |
Candidate c = getCandidateAtPos(methodSym, |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
388 |
asJCDiagnostic(diagnostic).getLineNumber(), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
389 |
asJCDiagnostic(diagnostic).getColumnNumber()); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
390 |
MethodType sig = sig(diagnostic); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
391 |
if (c != null && sig != null) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
392 |
checkSig(c, methodSym, sig); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
393 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
394 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
395 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
396 |
Element methodSym(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
397 |
return (Element)asJCDiagnostic(diagnostic).getArgs()[0]; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
398 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
399 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
400 |
MethodType sig(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
401 |
return (MethodType)asJCDiagnostic(diagnostic).getArgs()[1]; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
402 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
403 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
404 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
405 |
/** |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
406 |
* Processor for all error diagnostics; if the error key is not declared in |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
407 |
* the test file header, the processor reports an error. |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
408 |
*/ |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
409 |
class ErrorProcessor extends DiagnosticProcessor { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
410 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
411 |
public ErrorProcessor() { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
412 |
super(Diagnostic.Kind.ERROR); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
413 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
414 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
415 |
@Override |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
416 |
void process(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
417 |
if (!declaredKeys.contains(diagnostic.getCode())) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
418 |
error("Unexpected compilation error key '" + diagnostic.getCode() + "'"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
419 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
420 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
421 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
422 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
423 |
@SupportedAnnotationTypes({"Candidate","TraceResolve"}) |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
424 |
class ResolveCandidateFinder extends JavacTestingAbstractProcessor { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
425 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
426 |
@Override |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
427 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
428 |
if (roundEnv.processingOver()) |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
429 |
return true; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
430 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
431 |
TypeElement traceResolveAnno = elements.getTypeElement("TraceResolve"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
432 |
TypeElement candidateAnno = elements.getTypeElement("Candidate"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
433 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
434 |
if (!annotations.contains(traceResolveAnno)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
435 |
error("no @TraceResolve annotation found in test class"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
436 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
437 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
438 |
if (!annotations.contains(candidateAnno)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
439 |
error("no @candidate annotation found in test class"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
440 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
441 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
442 |
for (Element elem: roundEnv.getElementsAnnotatedWith(traceResolveAnno)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
443 |
TraceResolve traceResolve = elem.getAnnotation(TraceResolve.class); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
444 |
declaredKeys.addAll(Arrays.asList(traceResolve.keys())); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
445 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
446 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
447 |
for (Element elem: roundEnv.getElementsAnnotatedWith(candidateAnno)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
448 |
candidatesMap.put(new ElementKey(elem), elem.getAnnotation(Candidate.class)); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
449 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
450 |
return true; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
451 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
452 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
453 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
454 |
class ElementKey { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
455 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
456 |
String key; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
457 |
Element elem; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
458 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
459 |
public ElementKey(Element elem) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
460 |
this.elem = elem; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
461 |
this.key = computeKey(elem); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
462 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
463 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
464 |
@Override |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
465 |
public boolean equals(Object obj) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
466 |
if (obj instanceof ElementKey) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
467 |
ElementKey other = (ElementKey)obj; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
468 |
return other.key.equals(key); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
469 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
470 |
return false; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
471 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
472 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
473 |
@Override |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
474 |
public int hashCode() { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
475 |
return key.hashCode(); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
476 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
477 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
478 |
String computeKey(Element e) { |
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
479 |
String simpleName = e.getSimpleName().toString(); |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
480 |
String opName = predefTranslationMap.get(simpleName); |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
481 |
String name = opName != null ? opName : simpleName; |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
17804
diff
changeset
|
482 |
return name + e.asType(); |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
483 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
484 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
485 |
@Override |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
486 |
public String toString() { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
487 |
return "Key{"+key+"}"; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
488 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
489 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
490 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
491 |
class DiagnosticHandler implements DiagnosticListener<JavaFileObject> { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
492 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
493 |
boolean shouldRecordDiags; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
494 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
495 |
DiagnosticHandler(boolean shouldRecordDiags) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
496 |
this.shouldRecordDiags = shouldRecordDiags; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
497 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
498 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
499 |
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
500 |
if (shouldRecordDiags) |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
501 |
diags.add(diagnostic); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
502 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
503 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
504 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
diff
changeset
|
505 |
} |