author | jlahoda |
Thu, 09 Oct 2014 10:08:52 +0200 | |
changeset 26993 | 513b2cae81c3 |
parent 26103 | 3f96599b20da |
child 27552 | 8a4b2d3639c1 |
permissions | -rw-r--r-- |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
1 |
/* |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
4 |
* |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
8 |
* |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
13 |
* accompanied this code). |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
14 |
* |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
18 |
* |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
21 |
* questions. |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
22 |
*/ |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
23 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
24 |
/* |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
25 |
* @test |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
26 |
* @bug 8042251 |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
27 |
* @summary Test that outer_class_info_index of local and anonymous class is zero. |
26103 | 28 |
* @library /tools/lib /tools/javac/lib ../lib |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
29 |
* @build TestBase TestResult InMemoryFileManager ToolBox |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
30 |
* @run main InnerClassesIndexTest |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
31 |
*/ |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
32 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
33 |
import java.io.File; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
34 |
import java.io.FilenameFilter; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
35 |
import java.util.HashSet; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
36 |
import java.util.Set; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
37 |
import java.util.stream.Collectors; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
38 |
import java.util.stream.Stream; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
39 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
40 |
import com.sun.tools.classfile.Attribute; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
41 |
import com.sun.tools.classfile.ClassFile; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
42 |
import com.sun.tools.classfile.InnerClasses_attribute; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
43 |
import com.sun.tools.classfile.InnerClasses_attribute.Info; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
44 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
45 |
public class InnerClassesIndexTest extends TestResult { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
46 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
47 |
public static void main(String[] args) throws TestFailedException { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
48 |
new InnerClassesIndexTest().test(); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
49 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
50 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
51 |
private boolean isExcluded(String className) { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
52 |
return !className.startsWith(InnerClassesIndexTest.class.getName()) |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
53 |
|| "InnerClassesIndexTest$Inner".equals(className); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
54 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
55 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
56 |
private Set<String> getInnerClasses() { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
57 |
FilenameFilter filter = (dir, name) -> name.matches("InnerClassesIndexTest\\$.*\\.class"); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
58 |
return Stream.of(getClassDir().listFiles(filter)) |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
59 |
.map(File::getName) |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
60 |
.map(s -> s.replace(".class", "")) |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
61 |
.collect(Collectors.toSet()); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
62 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
63 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
64 |
public void test() throws TestFailedException { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
65 |
try { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
66 |
addTestCase("Source is InnerClassesIndexTest.java"); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
67 |
ClassFile classFile = readClassFile(InnerClassesIndexTest.class); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
68 |
InnerClasses_attribute attr = (InnerClasses_attribute) |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
69 |
classFile.getAttribute(Attribute.InnerClasses); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
70 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
71 |
Set<String> foundClasses = new HashSet<>(); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
72 |
for (Info info : attr.classes) { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
73 |
String innerName = classFile.constant_pool. |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
74 |
getClassInfo(info.inner_class_info_index).getBaseName(); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
75 |
echo("Testing class : " + innerName); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
76 |
if (isExcluded(innerName)) { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
77 |
echo("Ignored : " + innerName); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
78 |
continue; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
79 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
80 |
foundClasses.add(innerName); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
81 |
assertEquals(info.outer_class_info_index, 0, |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
82 |
"outer_class_info_index of " + innerName); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
83 |
if (innerName.matches("\\$\\d+")) { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
84 |
assertEquals(info.inner_name_index, 0, |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
85 |
"inner_name_index of anonymous class"); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
86 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
87 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
88 |
Set<String> expectedClasses = getInnerClasses(); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
89 |
expectedClasses.remove("InnerClassesIndexTest$Inner"); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
90 |
assertEquals(foundClasses, expectedClasses, "All classes are found"); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
91 |
} catch (Exception e) { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
92 |
addFailure(e); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
93 |
} finally { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
94 |
checkStatus(); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
95 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
96 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
97 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
98 |
static class Inner { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
99 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
100 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
101 |
Inner inner1 = new Inner() { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
102 |
}; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
103 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
104 |
static Inner inner2 = new Inner() { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
105 |
}; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
106 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
107 |
Runnable r = () -> { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
108 |
class Local { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
109 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
110 |
new Local() { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
111 |
}; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
112 |
}; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
113 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
114 |
public void local() { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
115 |
class Local { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
116 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
117 |
new Local() { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
118 |
}; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
119 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
120 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
121 |
public InnerClassesIndexTest() { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
122 |
class Local { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
123 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
124 |
new Local() { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
125 |
}; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
126 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
127 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
128 |
{ |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
129 |
class Local { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
130 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
131 |
new Local() { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
132 |
}; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
133 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
134 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
135 |
static { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
136 |
class Local { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
137 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
138 |
new Local() { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
139 |
}; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
140 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
diff
changeset
|
141 |
} |