author | alanb |
Thu, 17 Mar 2016 19:04:28 +0000 | |
changeset 36526 | 3b41f1c69604 |
parent 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
16300 | 1 |
/* |
36526 | 2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
16300 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 8005653 |
|
27 |
* @summary A lambda containing an inner class referencing an external type var |
|
28 |
* @author Robert Field |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
16300
diff
changeset
|
29 |
* @modules jdk.compiler |
36526 | 30 |
* jdk.jdeps/com.sun.tools.javap |
16300 | 31 |
* @run main LambdaInnerTypeVarReflect |
32 |
*/ |
|
33 |
||
34 |
import java.io.StringWriter; |
|
35 |
import java.io.PrintWriter; |
|
36 |
import java.io.IOException; |
|
37 |
||
38 |
public class LambdaInnerTypeVarReflect { |
|
39 |
||
40 |
static int assertionCount = 0; |
|
41 |
||
42 |
static void assertTrue(boolean cond) { |
|
43 |
assertionCount++; |
|
44 |
if (!cond) |
|
45 |
throw new AssertionError(); |
|
46 |
} |
|
47 |
||
48 |
interface I { |
|
49 |
C doit(); |
|
50 |
} |
|
51 |
||
52 |
abstract class C { |
|
53 |
abstract Object it(); |
|
54 |
} |
|
55 |
||
56 |
class TV { |
|
57 |
C go() { |
|
58 |
return foo("Frump").doit(); |
|
59 |
} |
|
60 |
||
61 |
<RRRRR> I foo(RRRRR r) { |
|
62 |
return () -> new C() { |
|
63 |
public RRRRR xxxxx = r; |
|
64 |
@Override |
|
65 |
Object it() { return xxxxx; }; |
|
66 |
}; |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
void test1() throws IOException { |
|
71 |
char[] buffer = new char[1024]; |
|
72 |
String innerName = new TV().go().getClass().getName(); |
|
73 |
StringWriter sw = new StringWriter(); |
|
74 |
PrintWriter pw = new PrintWriter(sw); |
|
75 |
int exitCode = com.sun.tools.javap.Main.run(new String[] {innerName}, pw); |
|
76 |
assertTrue(exitCode == 0); |
|
77 |
||
78 |
String javapOut = sw.toString(); |
|
79 |
assertTrue(javapOut.contains(innerName)); |
|
80 |
assertTrue(!javapOut.contains("RRRRR")); |
|
81 |
} |
|
82 |
||
83 |
public static void main(String[] args) throws IOException { |
|
84 |
LambdaInnerTypeVarReflect t = new LambdaInnerTypeVarReflect(); |
|
85 |
t.test1(); |
|
86 |
assertTrue(assertionCount == 3); |
|
87 |
} |
|
88 |
} |