author | mcimadamore |
Sat, 17 Nov 2012 19:01:03 +0000 | |
changeset 14547 | 86d8d242b0c4 |
parent 14443 | 91c05eb19277 |
child 15040 | 99fd9483d3f0 |
permissions | -rw-r--r-- |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
1 |
/* |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
4 |
* |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
8 |
* |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
13 |
* accompanied this code). |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
14 |
* |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
18 |
* |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
21 |
* questions. |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
22 |
*/ |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
23 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
24 |
/* |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
25 |
* @test |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
26 |
* @summary Automatic test for checking correctness of default super/this resolution |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
27 |
*/ |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
28 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
29 |
import com.sun.source.util.JavacTask; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
30 |
import java.net.URI; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
31 |
import java.util.Arrays; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
32 |
import java.util.ArrayList; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
33 |
import java.util.List; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
34 |
import java.util.Locale; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
35 |
import java.util.Map; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
36 |
import javax.tools.Diagnostic; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
37 |
import javax.tools.JavaCompiler; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
38 |
import javax.tools.JavaFileObject; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
39 |
import javax.tools.SimpleJavaFileObject; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
40 |
import javax.tools.StandardJavaFileManager; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
41 |
import javax.tools.ToolProvider; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
42 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
43 |
public class TestDefaultSuperCall { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
44 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
45 |
static int checkCount = 0; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
46 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
47 |
enum InterfaceKind { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
48 |
DEFAULT("interface A extends B { default void m() { } }"), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
49 |
ABSTRACT("interface A extends B { void m(); }"), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
50 |
NONE("interface A extends B { }"); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
51 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
52 |
String interfaceStr; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
53 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
54 |
InterfaceKind(String interfaceStr) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
55 |
this.interfaceStr = interfaceStr; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
56 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
57 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
58 |
boolean methodDefined() { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
59 |
return this == DEFAULT; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
60 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
61 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
62 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
63 |
enum PruneKind { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
64 |
NO_PRUNE("interface C { }"), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
65 |
PRUNE("interface C extends A { }"); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
66 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
67 |
boolean methodDefined(InterfaceKind ik) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
68 |
return this == PRUNE && |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
69 |
ik.methodDefined(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
70 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
71 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
72 |
String interfaceStr; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
73 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
74 |
PruneKind(String interfaceStr) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
75 |
this.interfaceStr = interfaceStr; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
76 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
77 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
78 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
79 |
enum QualifierKind { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
80 |
DIRECT_1("C"), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
81 |
DIRECT_2("A"), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
82 |
INDIRECT("B"), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
83 |
UNRELATED("E"), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
84 |
ENCLOSING_1(null), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
85 |
ENCLOSING_2(null); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
86 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
87 |
String qualifierStr; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
88 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
89 |
QualifierKind(String qualifierStr) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
90 |
this.qualifierStr = qualifierStr; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
91 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
92 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
93 |
String getQualifier(Shape sh) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
94 |
switch (this) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
95 |
case ENCLOSING_1: return sh.enclosingAt(0); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
96 |
case ENCLOSING_2: return sh.enclosingAt(1); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
97 |
default: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
98 |
return qualifierStr; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
99 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
100 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
101 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
102 |
boolean isEnclosing() { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
103 |
return this == ENCLOSING_1 || |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
104 |
this == ENCLOSING_2; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
105 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
106 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
107 |
boolean allowSuperCall(InterfaceKind ik, PruneKind pk) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
108 |
switch (this) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
109 |
case DIRECT_1: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
110 |
return pk.methodDefined(ik); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
111 |
case DIRECT_2: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
112 |
return ik.methodDefined() && pk == PruneKind.NO_PRUNE; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
113 |
default: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
114 |
return false; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
115 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
116 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
117 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
118 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
119 |
enum ExprKind { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
120 |
THIS("this"), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
121 |
SUPER("super"); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
122 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
123 |
String exprStr; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
124 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
125 |
ExprKind(String exprStr) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
126 |
this.exprStr = exprStr; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
127 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
128 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
129 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
130 |
enum ElementKind { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
131 |
INTERFACE("interface #N { #B }", true), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
132 |
INTERFACE_EXTENDS("interface #N extends A, C { #B }", true), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
133 |
CLASS("class #N { #B }", false), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
134 |
CLASS_EXTENDS("abstract class #N implements A, C { #B }", false), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
135 |
STATIC_CLASS("static class #N { #B }", true), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
136 |
STATIC_CLASS_EXTENDS("abstract static class #N implements A, C { #B }", true), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
137 |
ANON_CLASS("new Object() { #B };", false), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
138 |
METHOD("void test() { #B }", false), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
139 |
STATIC_METHOD("static void test() { #B }", true), |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
140 |
DEFAULT_METHOD("default void test() { #B }", false); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
141 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
142 |
String templateDecl; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
143 |
boolean isStatic; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
144 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
145 |
ElementKind(String templateDecl, boolean isStatic) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
146 |
this.templateDecl = templateDecl; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
147 |
this.isStatic = isStatic; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
148 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
149 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
150 |
boolean isClassDecl() { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
151 |
switch(this) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
152 |
case METHOD: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
153 |
case STATIC_METHOD: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
154 |
case DEFAULT_METHOD: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
155 |
return false; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
156 |
default: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
157 |
return true; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
158 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
159 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
160 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
161 |
boolean isAllowedEnclosing(ElementKind ek, boolean isTop) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
162 |
switch (this) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
163 |
case CLASS: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
164 |
case CLASS_EXTENDS: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
165 |
//class is implicitly static inside interface, so skip this combo |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
166 |
return ek.isClassDecl() && |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
167 |
ek != INTERFACE && ek != INTERFACE_EXTENDS; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
168 |
case ANON_CLASS: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
169 |
return !ek.isClassDecl(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
170 |
case METHOD: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
171 |
return ek == CLASS || ek == CLASS_EXTENDS || |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
172 |
ek == STATIC_CLASS || ek == STATIC_CLASS_EXTENDS || |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
173 |
ek == ANON_CLASS; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
174 |
case INTERFACE: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
175 |
case INTERFACE_EXTENDS: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
176 |
case STATIC_CLASS: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
177 |
case STATIC_CLASS_EXTENDS: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
178 |
case STATIC_METHOD: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
179 |
return (isTop && (ek == CLASS || ek == CLASS_EXTENDS)) || |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
180 |
ek == STATIC_CLASS || ek == STATIC_CLASS_EXTENDS; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
181 |
case DEFAULT_METHOD: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
182 |
return ek == INTERFACE || ek == INTERFACE_EXTENDS; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
183 |
default: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
184 |
throw new AssertionError("Bad enclosing element kind" + this); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
185 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
186 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
187 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
188 |
boolean isAllowedTop() { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
189 |
switch (this) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
190 |
case CLASS: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
191 |
case CLASS_EXTENDS: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
192 |
case INTERFACE: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
193 |
case INTERFACE_EXTENDS: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
194 |
return true; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
195 |
default: |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
196 |
return false; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
197 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
198 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
199 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
200 |
boolean hasSuper() { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
201 |
return this == INTERFACE_EXTENDS || |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
202 |
this == STATIC_CLASS_EXTENDS || |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
203 |
this == CLASS_EXTENDS; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
204 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
205 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
206 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
207 |
static class Shape { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
208 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
209 |
String shapeStr; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
210 |
List<ElementKind> enclosingElements; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
211 |
List<String> enclosingNames; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
212 |
List<String> elementsWithMethod; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
213 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
214 |
Shape(ElementKind... elements) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
215 |
System.err.println("elements = " + Arrays.toString(elements)); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
216 |
enclosingElements = new ArrayList<>(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
217 |
enclosingNames = new ArrayList<>(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
218 |
elementsWithMethod = new ArrayList<>(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
219 |
int count = 0; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
220 |
String prevName = null; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
221 |
for (ElementKind ek : elements) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
222 |
String name = "name"+count++; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
223 |
if (ek.isStatic) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
224 |
enclosingElements = new ArrayList<>(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
225 |
enclosingNames = new ArrayList<>(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
226 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
227 |
if (ek.isClassDecl()) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
228 |
enclosingElements.add(ek); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
229 |
enclosingNames.add(name); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
230 |
} else { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
231 |
elementsWithMethod.add(prevName); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
232 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
233 |
String element = ek.templateDecl.replaceAll("#N", name); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
234 |
shapeStr = shapeStr == null ? element : shapeStr.replaceAll("#B", element); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
235 |
prevName = name; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
236 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
237 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
238 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
239 |
String getShape(QualifierKind qk, ExprKind ek) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
240 |
String methName = ek == ExprKind.THIS ? "test" : "m"; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
241 |
String call = qk.getQualifier(this) + "." + ek.exprStr + "." + methName + "();"; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
242 |
return shapeStr.replaceAll("#B", call); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
243 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
244 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
245 |
String enclosingAt(int index) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
246 |
return index < enclosingNames.size() ? enclosingNames.get(index) : "BAD"; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
247 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
248 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
249 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
250 |
public static void main(String... args) throws Exception { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
251 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
252 |
//create default shared JavaCompiler - reused across multiple compilations |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
253 |
JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
254 |
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
255 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
256 |
for (InterfaceKind ik : InterfaceKind.values()) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
257 |
for (PruneKind pk : PruneKind.values()) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
258 |
for (ElementKind ek1 : ElementKind.values()) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
259 |
if (!ek1.isAllowedTop()) continue; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
260 |
for (ElementKind ek2 : ElementKind.values()) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
261 |
if (!ek2.isAllowedEnclosing(ek1, true)) continue; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
262 |
for (ElementKind ek3 : ElementKind.values()) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
263 |
if (!ek3.isAllowedEnclosing(ek2, false)) continue; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
264 |
for (ElementKind ek4 : ElementKind.values()) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
265 |
if (!ek4.isAllowedEnclosing(ek3, false)) continue; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
266 |
for (ElementKind ek5 : ElementKind.values()) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
267 |
if (!ek5.isAllowedEnclosing(ek4, false) || ek5.isClassDecl()) continue; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
268 |
for (QualifierKind qk : QualifierKind.values()) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
269 |
for (ExprKind ek : ExprKind.values()) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
270 |
new TestDefaultSuperCall(ik, pk, new Shape(ek1, ek2, ek3, ek4, ek5), qk, ek).run(comp, fm); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
271 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
272 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
273 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
274 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
275 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
276 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
277 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
278 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
279 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
280 |
System.out.println("Total check executed: " + checkCount); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
281 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
282 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
283 |
InterfaceKind ik; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
284 |
PruneKind pk; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
285 |
Shape sh; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
286 |
QualifierKind qk; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
287 |
ExprKind ek; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
288 |
JavaSource source; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
289 |
DiagnosticChecker diagChecker; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
290 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
291 |
TestDefaultSuperCall(InterfaceKind ik, PruneKind pk, Shape sh, QualifierKind qk, ExprKind ek) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
292 |
this.ik = ik; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
293 |
this.pk = pk; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
294 |
this.sh = sh; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
295 |
this.qk = qk; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
296 |
this.ek = ek; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
297 |
this.source = new JavaSource(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
298 |
this.diagChecker = new DiagnosticChecker(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
299 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
300 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
301 |
class JavaSource extends SimpleJavaFileObject { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
302 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
303 |
String template = "interface E {}\n" + |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
304 |
"interface B { }\n" + |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
305 |
"#I\n" + |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
306 |
"#P\n" + |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
307 |
"#C"; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
308 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
309 |
String source; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
310 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
311 |
public JavaSource() { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
312 |
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
313 |
source = template.replaceAll("#I", ik.interfaceStr) |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
314 |
.replaceAll("#P", pk.interfaceStr) |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
315 |
.replaceAll("#C", sh.getShape(qk, ek)); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
316 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
317 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
318 |
@Override |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
319 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
320 |
return source; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
321 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
322 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
323 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
324 |
void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
325 |
JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, |
14547 | 326 |
null, null, Arrays.asList(source)); |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
327 |
try { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
328 |
ct.analyze(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
329 |
} catch (Throwable ex) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
330 |
throw new AssertionError("Error thrown when analyzing the following source:\n" + source.getCharContent(true)); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
331 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
332 |
check(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
333 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
334 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
335 |
void check() { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
336 |
boolean errorExpected = false; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
337 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
338 |
boolean badEnclosing = false; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
339 |
boolean badThis = false; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
340 |
boolean badSuper = false; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
341 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
342 |
if (qk == QualifierKind.ENCLOSING_1 && |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
343 |
sh.enclosingNames.size() < 1) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
344 |
errorExpected |= true; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
345 |
badEnclosing = true; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
346 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
347 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
348 |
if (qk == QualifierKind.ENCLOSING_2 && |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
349 |
sh.enclosingNames.size() < 2) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
350 |
errorExpected |= true; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
351 |
badEnclosing = true; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
352 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
353 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
354 |
if (ek == ExprKind.THIS) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
355 |
boolean found = false; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
356 |
for (int i = 0; i < sh.enclosingElements.size(); i++) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
357 |
if (sh.enclosingElements.get(i) == ElementKind.ANON_CLASS) continue; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
358 |
if (sh.enclosingNames.get(i).equals(qk.getQualifier(sh))) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
359 |
found = sh.elementsWithMethod.contains(sh.enclosingNames.get(i)); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
360 |
break; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
361 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
362 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
363 |
errorExpected |= !found; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
364 |
if (!found) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
365 |
badThis = true; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
366 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
367 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
368 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
369 |
if (ek == ExprKind.SUPER) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
370 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
371 |
int lastIdx = sh.enclosingElements.size() - 1; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
372 |
boolean found = lastIdx == -1 ? false : |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
373 |
sh.enclosingElements.get(lastIdx).hasSuper() && qk.allowSuperCall(ik, pk); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
374 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
375 |
errorExpected |= !found; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
376 |
if (!found) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
377 |
badSuper = true; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
378 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
379 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
380 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
381 |
checkCount++; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
382 |
if (diagChecker.errorFound != errorExpected) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
383 |
throw new AssertionError("Problem when compiling source:\n" + source.getCharContent(true) + |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
384 |
"\nenclosingElems: " + sh.enclosingElements + |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
385 |
"\nenclosingNames: " + sh.enclosingNames + |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
386 |
"\nelementsWithMethod: " + sh.elementsWithMethod + |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
387 |
"\nbad encl: " + badEnclosing + |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
388 |
"\nbad this: " + badThis + |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
389 |
"\nbad super: " + badSuper + |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
390 |
"\nqual kind: " + qk + |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
391 |
"\nfound error: " + diagChecker.errorFound); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
392 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
393 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
394 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
395 |
static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
396 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
397 |
boolean errorFound; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
398 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
399 |
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
400 |
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
401 |
System.err.println(diagnostic.getMessage(Locale.getDefault())); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
402 |
errorFound = true; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
403 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
404 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
405 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
diff
changeset
|
406 |
} |