Debian Codegraph @

framework/tests/all-systems/java8/memberref/MemberReferences.java

raw
1 // If conservativeUninferredTypeArguments option is used, then the lines marked
2 // "TODO: Issue 802", will issue a methodref.inference.unimplemented warning.
3
4 interface Supplier<R> {
5 R supply();
6 }
7
8 interface FunctionMR<T, R> {
9 R apply(T t);
10 }
11
12 interface Consumer<T> {
13 void consume(T t);
14 }
15
16 interface BiFunctionMR<T, U, R> {
17 R apply(T t, U u);
18 }
19
20 /** super # instMethod */
21 // SUPER(ReferenceMode.INVOKE, false),
22 class Super {
23
24 Object func1(Object o) {
25 return o;
26 }
27
28 <T> T func2(T o) {
29 return o;
30 }
31
32 class Sub extends Super {
33 void context() {
34 FunctionMR<Object, Object> f1 = super::func1;
35 // TODO: Issue 802: type argument inference
36 FunctionMR f2 = super::func2;
37 // Top level wildcards are ignored when type checking
38 FunctionMR<? extends String, ? extends String> f3 = super::<String>func2;
39 }
40 }
41 }
42
43 class SuperWithArg<U> {
44
45 void func1(U o) {}
46
47 class Sub extends SuperWithArg<Number> {
48 void context() {
49 Consumer<Integer> f1 = super::func1;
50 }
51 }
52 }
53
54 /** Type # instMethod. */
55 // UNBOUNDED(ReferenceMode.INVOKE, true),
56 class Unbound {
57 <T> T func1(T o) {
58 return o;
59 }
60
61 void context() {
62 FunctionMR<String, String> f1 = String::toString;
63 // TODO: Issue 802: type argument inference
64 BiFunctionMR<Unbound, String, String> f2 = Unbound::func1;
65 @SuppressWarnings("nullness:type.argument.type.incompatible")
66 BiFunctionMR<? extends Unbound, ? super Integer, ? extends Integer> f3 =
67 Unbound::<Integer>func1;
68 }
69 }
70
71 abstract class UnboundWithArg<U> {
72 abstract U func1();
73
74 void context() {
75 // TODO: Issue 802: type argument inference
76 FunctionMR<UnboundWithArg<String>, String> f1 = UnboundWithArg::func1;
77 FunctionMR<UnboundWithArg<String>, String> f2 = UnboundWithArg<String>::func1;
78 // TODO: Issue 802: type argument inference
79 FunctionMR<? extends UnboundWithArg<String>, String> f3 = UnboundWithArg::func1;
80 FunctionMR<? extends UnboundWithArg<String>, String> f4 = UnboundWithArg<String>::func1;
81 }
82 }
83
84 /** Type # staticMethod. */
85 // STATIC(ReferenceMode.INVOKE, false),
86 class Static {
87 static <T> T func1(T o) {
88 return o;
89 }
90
91 void context() {
92 // TODO: Issue 802: type argument inference
93 FunctionMR<String, String> f1 = Static::func1;
94 FunctionMR<String, String> f2 = Static::<String>func1;
95 }
96 }
97
98 /** Expr # instMethod. */
99 // BOUND(ReferenceMode.INVOKE, false),
100 class Bound {
101 <T> T func1(T o) {
102 return o;
103 }
104
105 void context(Bound bound) {
106 // TODO: Issue 802: type argument inference
107 FunctionMR<String, String> f1 = bound::func1;
108 // TODO: Issue 802: type argument inference
109 FunctionMR<String, String> f2 = this::func1;
110 FunctionMR<String, String> f3 = this::<String>func1;
111 FunctionMR<? extends String, ? extends String> f4 = this::<String>func1;
112 }
113 }
114
115 class BoundWithArg<U> {
116 void func1(U param) {}
117
118 void context(BoundWithArg<Number> bound) {
119 Consumer<Number> f1 = bound::func1;
120 Consumer<Integer> f2 = bound::func1;
121 }
122 }
123
124 /** Inner # new. */
125 // IMPLICIT_INNER(ReferenceMode.NEW, false),
126 class Outer {
127 void context(Outer other) {
128 Supplier<Inner> f1 = Inner::new;
129 }
130
131 class Inner extends Outer {}
132 }
133
134 class OuterWithArg {
135 void context() {
136 // TODO: Issue 802: type argument inference
137 Supplier<Inner<String>> f1 = Inner::new;
138 Supplier<? extends Inner<Number>> f2 = Inner<Number>::new;
139 Supplier<? extends Inner<? extends Number>> f3 = Inner<Integer>::new;
140 }
141
142 class Inner<T> extends OuterWithArg {}
143 }
144
145 /** Toplevel # new. */
146 // TOPLEVEL(ReferenceMode.NEW, false),
147 class TopLevel {
148 TopLevel() {}
149
150 <T> TopLevel(T s) {}
151
152 void context() {
153 Supplier<TopLevel> f1 = TopLevel::new;
154 // TODO: Issue 802: type argument inference
155 FunctionMR<String, TopLevel> f2 = TopLevel::new;
156 FunctionMR<String, TopLevel> f3 = TopLevel::<String>new;
157 }
158 }
159
160 class TopLevelWithArg<T> {
161 TopLevelWithArg() {}
162
163 <U> TopLevelWithArg(U s) {}
164
165 void context() {
166 // TODO: Issue 802: type argument inference
167 Supplier<TopLevelWithArg<String>> f1 = TopLevelWithArg::new;
168 Supplier<TopLevelWithArg<String>> f2 = TopLevelWithArg<String>::new;
169 FunctionMR<String, TopLevelWithArg<String>> f3 = TopLevelWithArg<String>::<String>new;
170 }
171 }
172
173 /** ArrayType # new. */
174 // ARRAY_CTOR(ReferenceMode.NEW, false);
175
176 class ArrayType {
177 void context() {
178 // TODO: Signedness Checker does not default boxed primitives correctly.
179 // See Issue #797: https://github.com/typetools/checker-framework/issues/797
180 @SuppressWarnings({"signedness"})
181 FunctionMR<Integer, String[]> string = String[]::new;
182 FunctionMR<String[], String[]> clone = String[]::clone;
183 FunctionMR<String[], String> toString = String[]::toString;
184 }
185 }