author | alundblad |
Mon, 23 Sep 2013 10:42:38 +0200 | |
changeset 20249 | 93f8eae31092 |
parent 16809 | 5acfcb821d65 |
child 22690 | 86dd707d616a |
permissions | -rw-r--r-- |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
1 |
/* |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
16809
diff
changeset
|
2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
4 |
* |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
8 |
* |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
13 |
* accompanied this code). |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
14 |
* |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
18 |
* |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
21 |
* questions. |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
22 |
*/ |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
23 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
24 |
/* |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
25 |
* @test |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
26 |
* @bug 8002099 |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
27 |
* @summary Add support for intersection types in cast expression |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
28 |
*/ |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
29 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
30 |
import com.sun.source.util.JavacTask; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
31 |
import com.sun.tools.javac.util.ListBuffer; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
32 |
import java.net.URI; |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
33 |
import java.util.ArrayList; |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
34 |
import java.util.Arrays; |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
35 |
import java.util.List; |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
36 |
import javax.tools.Diagnostic; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
37 |
import javax.tools.JavaCompiler; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
38 |
import javax.tools.JavaFileObject; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
39 |
import javax.tools.SimpleJavaFileObject; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
40 |
import javax.tools.StandardJavaFileManager; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
41 |
import javax.tools.ToolProvider; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
42 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
43 |
public class IntersectionTargetTypeTest { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
44 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
45 |
static int checkCount = 0; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
46 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
47 |
enum BoundKind { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
48 |
INTF, |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
49 |
CLASS; |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
50 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
51 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
52 |
enum MethodKind { |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
53 |
NONE(false), |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
54 |
ABSTRACT_M(true), |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
55 |
DEFAULT_M(false), |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
56 |
ABSTRACT_G(true), |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
57 |
DEFAULT_G(false); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
58 |
|
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
59 |
boolean isAbstract; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
60 |
|
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
61 |
MethodKind(boolean isAbstract) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
62 |
this.isAbstract = isAbstract; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
63 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
64 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
65 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
66 |
enum TypeKind { |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
67 |
A("interface A { }\n", "A", BoundKind.INTF, MethodKind.NONE), |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
68 |
B("interface B { default void m() { } }\n", "B", BoundKind.INTF, MethodKind.DEFAULT_M), |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
69 |
C("interface C { void m(); }\n", "C", BoundKind.INTF, MethodKind.ABSTRACT_M), |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
70 |
D("interface D extends B { }\n", "D", BoundKind.INTF, MethodKind.DEFAULT_M), |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
71 |
E("interface E extends C { }\n", "E", BoundKind.INTF, MethodKind.ABSTRACT_M), |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
72 |
F("interface F extends C { void g(); }\n", "F", BoundKind.INTF, MethodKind.ABSTRACT_G, MethodKind.ABSTRACT_M), |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
73 |
G("interface G extends B { void g(); }\n", "G", BoundKind.INTF, MethodKind.ABSTRACT_G, MethodKind.DEFAULT_M), |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
74 |
H("interface H extends A { void g(); }\n", "H", BoundKind.INTF, MethodKind.ABSTRACT_G), |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
75 |
OBJECT("", "Object", BoundKind.CLASS), |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
76 |
STRING("", "String", BoundKind.CLASS); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
77 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
78 |
String declStr; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
79 |
String typeStr; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
80 |
BoundKind boundKind; |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
81 |
MethodKind[] methodKinds; |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
82 |
|
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
83 |
private TypeKind(String declStr, String typeStr, BoundKind boundKind, MethodKind... methodKinds) { |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
84 |
this.declStr = declStr; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
85 |
this.typeStr = typeStr; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
86 |
this.boundKind = boundKind; |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
87 |
this.methodKinds = methodKinds; |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
88 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
89 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
90 |
boolean compatibleSupertype(TypeKind tk) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
91 |
if (tk == this) return true; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
92 |
switch (tk) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
93 |
case B: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
94 |
return this != C && this != E && this != F; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
95 |
case C: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
96 |
return this != B && this != C && this != D && this != G; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
97 |
case D: return compatibleSupertype(B); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
98 |
case E: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
99 |
case F: return compatibleSupertype(C); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
100 |
case G: return compatibleSupertype(B); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
101 |
case H: return compatibleSupertype(A); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
102 |
default: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
103 |
return true; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
104 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
105 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
106 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
107 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
108 |
enum CastKind { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
109 |
ONE_ARY("(#B0)", 1), |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
110 |
TWO_ARY("(#B0 & #B1)", 2), |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
111 |
THREE_ARY("(#B0 & #B1 & #B2)", 3); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
112 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
113 |
String castTemplate; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
114 |
int nbounds; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
115 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
116 |
CastKind(String castTemplate, int nbounds) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
117 |
this.castTemplate = castTemplate; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
118 |
this.nbounds = nbounds; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
119 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
120 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
121 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
122 |
enum ExpressionKind { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
123 |
LAMBDA("()->{}", true), |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
124 |
MREF("this::m", true), |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
125 |
//COND_LAMBDA("(true ? ()->{} : ()->{})", true), re-enable if spec allows this |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
126 |
//COND_MREF("(true ? this::m : this::m)", true), |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
127 |
STANDALONE("null", false); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
128 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
129 |
String exprString; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
130 |
boolean isFunctional; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
131 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
132 |
private ExpressionKind(String exprString, boolean isFunctional) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
133 |
this.exprString = exprString; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
134 |
this.isFunctional = isFunctional; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
135 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
136 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
137 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
138 |
static class CastInfo { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
139 |
CastKind kind; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
140 |
TypeKind[] types; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
141 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
142 |
CastInfo(CastKind kind, TypeKind... types) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
143 |
this.kind = kind; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
144 |
this.types = types; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
145 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
146 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
147 |
String getCast() { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
148 |
String temp = kind.castTemplate; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
149 |
for (int i = 0; i < kind.nbounds ; i++) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
150 |
temp = temp.replace(String.format("#B%d", i), types[i].typeStr); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
151 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
152 |
return temp; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
153 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
154 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
155 |
boolean wellFormed() { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
156 |
//check for duplicate types |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
157 |
for (int i = 0 ; i < types.length ; i++) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
158 |
for (int j = 0 ; j < types.length ; j++) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
159 |
if (i != j && types[i] == types[j]) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
160 |
return false; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
161 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
162 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
163 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
164 |
//check that classes only appear as first bound |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
165 |
boolean classOk = true; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
166 |
for (int i = 0 ; i < types.length ; i++) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
167 |
if (types[i].boundKind == BoundKind.CLASS && |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
168 |
!classOk) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
169 |
return false; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
170 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
171 |
classOk = false; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
172 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
173 |
//check that supertypes are mutually compatible |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
174 |
for (int i = 0 ; i < types.length ; i++) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
175 |
for (int j = 0 ; j < types.length ; j++) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
176 |
if (!types[i].compatibleSupertype(types[j]) && i != j) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
177 |
return false; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
178 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
179 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
180 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
181 |
return true; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
182 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
183 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
184 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
185 |
public static void main(String... args) throws Exception { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
186 |
//create default shared JavaCompiler - reused across multiple compilations |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
187 |
JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
188 |
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
189 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
190 |
for (CastInfo cInfo : allCastInfo()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
191 |
for (ExpressionKind ek : ExpressionKind.values()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
192 |
new IntersectionTargetTypeTest(cInfo, ek).run(comp, fm); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
193 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
194 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
195 |
System.out.println("Total check executed: " + checkCount); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
196 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
197 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
198 |
static List<CastInfo> allCastInfo() { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
16809
diff
changeset
|
199 |
ListBuffer<CastInfo> buf = new ListBuffer<>(); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
200 |
for (CastKind kind : CastKind.values()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
201 |
for (TypeKind b1 : TypeKind.values()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
202 |
if (kind.nbounds == 1) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
203 |
buf.append(new CastInfo(kind, b1)); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
204 |
continue; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
205 |
} else { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
206 |
for (TypeKind b2 : TypeKind.values()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
207 |
if (kind.nbounds == 2) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
208 |
buf.append(new CastInfo(kind, b1, b2)); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
209 |
continue; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
210 |
} else { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
211 |
for (TypeKind b3 : TypeKind.values()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
212 |
buf.append(new CastInfo(kind, b1, b2, b3)); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
213 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
214 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
215 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
216 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
217 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
218 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
219 |
return buf.toList(); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
220 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
221 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
222 |
CastInfo cInfo; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
223 |
ExpressionKind ek; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
224 |
JavaSource source; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
225 |
DiagnosticChecker diagChecker; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
226 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
227 |
IntersectionTargetTypeTest(CastInfo cInfo, ExpressionKind ek) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
228 |
this.cInfo = cInfo; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
229 |
this.ek = ek; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
230 |
this.source = new JavaSource(); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
231 |
this.diagChecker = new DiagnosticChecker(); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
232 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
233 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
234 |
class JavaSource extends SimpleJavaFileObject { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
235 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
236 |
String bodyTemplate = "class Test {\n" + |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
237 |
" void m() { }\n" + |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
238 |
" void test() {\n" + |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
239 |
" Object o = #C#E;\n" + |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
240 |
" } }"; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
241 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
242 |
String source = ""; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
243 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
244 |
public JavaSource() { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
245 |
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
246 |
for (TypeKind tk : TypeKind.values()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
247 |
source += tk.declStr; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
248 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
249 |
source += bodyTemplate.replaceAll("#C", cInfo.getCast()).replaceAll("#E", ek.exprString); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
250 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
251 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
252 |
@Override |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
253 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
254 |
return source; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
255 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
256 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
257 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
258 |
void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
259 |
JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, |
15375
d2529dc91d77
8006566: Remove transient lambda-related guards from JavacParser
mcimadamore
parents:
14725
diff
changeset
|
260 |
null, null, Arrays.asList(source)); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
261 |
try { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
262 |
ct.analyze(); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
263 |
} catch (Throwable ex) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
264 |
throw new AssertionError("Error thrown when compiling the following code:\n" + source.getCharContent(true)); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
265 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
266 |
check(); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
267 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
268 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
269 |
void check() { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
270 |
checkCount++; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
271 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
272 |
boolean errorExpected = !cInfo.wellFormed(); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
273 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
274 |
if (ek.isFunctional) { |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
275 |
List<MethodKind> mks = new ArrayList<>(); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
276 |
for (TypeKind tk : cInfo.types) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
277 |
if (tk.boundKind == BoundKind.CLASS) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
278 |
errorExpected = true; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
279 |
break; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
280 |
} else { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
281 |
mks = mergeMethods(mks, Arrays.asList(tk.methodKinds)); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
282 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
283 |
} |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
284 |
int abstractCount = 0; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
285 |
for (MethodKind mk : mks) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
286 |
if (mk.isAbstract) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
287 |
abstractCount++; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
288 |
} |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
289 |
} |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
290 |
errorExpected |= abstractCount != 1; |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
291 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
292 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
293 |
if (errorExpected != diagChecker.errorFound) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
294 |
throw new Error("invalid diagnostics for source:\n" + |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
295 |
source.getCharContent(true) + |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
296 |
"\nFound error: " + diagChecker.errorFound + |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
297 |
"\nExpected error: " + errorExpected); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
298 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
299 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
300 |
|
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
301 |
List<MethodKind> mergeMethods(List<MethodKind> l1, List<MethodKind> l2) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
302 |
List<MethodKind> mergedMethods = new ArrayList<>(l1); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
303 |
for (MethodKind mk2 : l2) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
304 |
boolean add = !mergedMethods.contains(mk2); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
305 |
switch (mk2) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
306 |
case ABSTRACT_G: |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
307 |
add = add && !mergedMethods.contains(MethodKind.DEFAULT_G); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
308 |
break; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
309 |
case ABSTRACT_M: |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
310 |
add = add && !mergedMethods.contains(MethodKind.DEFAULT_M); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
311 |
break; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
312 |
case DEFAULT_G: |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
313 |
mergedMethods.remove(MethodKind.ABSTRACT_G); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
314 |
case DEFAULT_M: |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
315 |
mergedMethods.remove(MethodKind.ABSTRACT_M); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
316 |
case NONE: |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
317 |
add = false; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
318 |
break; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
319 |
} |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
320 |
if (add) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
321 |
mergedMethods.add(mk2); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
322 |
} |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
323 |
} |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
324 |
return mergedMethods; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
325 |
} |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
15375
diff
changeset
|
326 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
327 |
static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
328 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
329 |
boolean errorFound; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
330 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
331 |
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
332 |
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
333 |
errorFound = true; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
334 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
335 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
336 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
diff
changeset
|
337 |
} |