author | jlahoda |
Thu, 09 Oct 2014 10:08:52 +0200 | |
changeset 26993 | 513b2cae81c3 |
parent 26101 | d5dd2ecd2353 |
child 27552 | 8a4b2d3639c1 |
permissions | -rw-r--r-- |
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
1 |
/* |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
4 |
* |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
8 |
* |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
13 |
* accompanied this code). |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
14 |
* |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
18 |
* |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
21 |
* questions. |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
22 |
*/ |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
23 |
|
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
24 |
import java.io.File; |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
25 |
import java.io.FileInputStream; |
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
26 |
import java.io.IOException; |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
27 |
import java.io.InputStream; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
28 |
import java.util.Arrays; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
29 |
import java.util.Collections; |
25845
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
30 |
import java.util.List; |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
31 |
import java.util.Objects; |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
32 |
import java.util.function.Function; |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
33 |
import java.util.stream.Collectors; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
34 |
|
25845
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
35 |
import javax.tools.DiagnosticCollector; |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
36 |
import javax.tools.JavaCompiler; |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
37 |
import javax.tools.JavaFileObject; |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
38 |
import javax.tools.ToolProvider; |
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
39 |
|
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
40 |
import com.sun.tools.classfile.ClassFile; |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
41 |
import com.sun.tools.classfile.ConstantPoolException; |
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
42 |
|
25845
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
43 |
/** |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
44 |
* Base class for class file attribute tests. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
45 |
* Contains methods for compiling generated sources in memory, |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
46 |
* for reading files from disk and a lot of assert* methods. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
47 |
*/ |
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
48 |
public class TestBase { |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
49 |
|
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
50 |
public static final String LINE_SEPARATOR = System.lineSeparator(); |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
51 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
52 |
private <S> InMemoryFileManager compile( |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
53 |
List<String> options, |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
54 |
Function<S, ? extends JavaFileObject> src2JavaFileObject, |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
55 |
List<S> sources) |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
56 |
throws IOException, CompilationException { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
57 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
58 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
59 |
List<? extends JavaFileObject> src = sources.stream() |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
60 |
.map(src2JavaFileObject) |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
61 |
.collect(Collectors.toList()); |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
62 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
63 |
DiagnosticCollector<? super JavaFileObject> dc = new DiagnosticCollector<>(); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
64 |
try (InMemoryFileManager fileManager |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
65 |
= new InMemoryFileManager(compiler.getStandardFileManager(null, null, null))) { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
66 |
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, dc, options, null, src); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
67 |
boolean success = task.call(); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
68 |
if (!success) { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
69 |
String errorMessage = dc.getDiagnostics().stream() |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
70 |
.map(Object::toString) |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
71 |
.collect(Collectors.joining("\n")); |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
72 |
throw new CompilationException("Compilation Error\n\n" + errorMessage); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
73 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
74 |
return fileManager; |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
75 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
76 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
77 |
|
25845
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
78 |
/** |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
79 |
* Compiles sources in memory. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
80 |
* |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
81 |
* @param sources to compile. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
82 |
* @return memory file manager which contains class files and class loader. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
83 |
*/ |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
84 |
public InMemoryFileManager compile(String... sources) |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
85 |
throws IOException, CompilationException { |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
86 |
return compile(Collections.emptyList(), sources); |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
87 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
88 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
89 |
/** |
25845
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
90 |
* Compiles sources in memory. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
91 |
* |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
92 |
* @param options compiler options. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
93 |
* @param sources sources to compile. |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
94 |
* @return map where key is className, value is corresponding ClassFile. |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
95 |
*/ |
25845
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
96 |
public InMemoryFileManager compile(List<String> options, String... sources) |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
97 |
throws IOException, CompilationException { |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
98 |
return compile(options, ToolBox.JavaSource::new, Arrays.asList(sources)); |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
99 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
100 |
|
25845
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
101 |
/** |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
102 |
* Compiles sources in memory. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
103 |
* |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
104 |
* @param sources sources[i][0] - name of file, sources[i][1] - sources. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
105 |
* @return map where key is className, value is corresponding ClassFile. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
106 |
*/ |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
107 |
public InMemoryFileManager compile(String[]... sources) throws IOException, |
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
108 |
CompilationException { |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
109 |
return compile(Collections.emptyList(), sources); |
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
110 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
111 |
|
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
112 |
/** |
25845
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
113 |
* Compiles sources in memory. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
114 |
* |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
115 |
* @param options compiler options |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
116 |
* @param sources sources[i][0] - name of file, sources[i][1] - sources. |
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
117 |
* @return map where key is className, value is corresponding ClassFile. |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
118 |
*/ |
25845
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
119 |
public InMemoryFileManager compile(List<String> options, String[]... sources) |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
120 |
throws IOException, CompilationException { |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
121 |
return compile(options, src -> new ToolBox.JavaSource(src[0], src[1]), Arrays.asList(sources)); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
122 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
123 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
124 |
/** |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
125 |
* Returns class file that is read from {@code is}. |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
126 |
* |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
127 |
* @param is an input stream |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
128 |
* @return class file that is read from {@code is} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
129 |
* @throws IOException if I/O error occurs |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
130 |
* @throws ConstantPoolException if constant pool error occurs |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
131 |
*/ |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
132 |
public ClassFile readClassFile(InputStream is) throws IOException, ConstantPoolException { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
133 |
return ClassFile.read(is); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
134 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
135 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
136 |
/** |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
137 |
* Returns class file that is read from {@code fileObject}. |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
138 |
* |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
139 |
* @param fileObject a file object |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
140 |
* @return class file that is read from {@code fileObject} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
141 |
* @throws IOException if I/O error occurs |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
142 |
* @throws ConstantPoolException if constant pool error occurs |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
143 |
*/ |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
144 |
public ClassFile readClassFile(JavaFileObject fileObject) throws IOException, ConstantPoolException { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
145 |
return readClassFile(fileObject.openInputStream()); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
146 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
147 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
148 |
/** |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
149 |
* Returns class file that corresponds to {@code clazz}. |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
150 |
* |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
151 |
* @param clazz a class |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
152 |
* @return class file that is read from {@code clazz} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
153 |
* @throws IOException if I/O error occurs |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
154 |
* @throws ConstantPoolException if constant pool error occurs |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
155 |
*/ |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
156 |
public ClassFile readClassFile(Class<?> clazz) throws IOException, ConstantPoolException { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
157 |
return readClassFile(getClassFile(clazz)); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
158 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
159 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
160 |
/** |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
161 |
* Returns class file that corresponds to {@code className}. |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
162 |
* |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
163 |
* @param className a class name |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
164 |
* @return class file that is read from {@code className} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
165 |
* @throws IOException if I/O error occurs |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
166 |
* @throws ConstantPoolException if constant pool error occurs |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
167 |
*/ |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
168 |
public ClassFile readClassFile(String className) throws IOException, ConstantPoolException { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
169 |
return readClassFile(getClassFile(className + ".class")); |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
170 |
} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
171 |
|
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
172 |
/** |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
173 |
* Returns class file that is read from {@code file}. |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
174 |
* |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
175 |
* @param file a file |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
176 |
* @return class file that is read from {@code file} |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
177 |
* @throws IOException if I/O error occurs |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
178 |
* @throws ConstantPoolException if constant pool error occurs |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
179 |
*/ |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
180 |
public ClassFile readClassFile(File file) throws IOException, ConstantPoolException { |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
181 |
return readClassFile(new FileInputStream(file)); |
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
182 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
183 |
|
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
184 |
public void assertEquals(Object actual, Object expected, String message) { |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
185 |
if (!Objects.equals(actual, expected)) |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
186 |
throw new AssertionFailedException(String.format("%s%nGot: %s, Expected: %s", |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
187 |
message, actual, expected)); |
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
188 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
189 |
|
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
190 |
public void assertNull(Object actual, String message) { |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
191 |
assertEquals(actual, null, message); |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
192 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
193 |
|
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
194 |
public void assertNotNull(Object actual, String message) { |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
195 |
if (Objects.isNull(actual)) { |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
196 |
throw new AssertionFailedException(message + " : Expected not null value"); |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
197 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
198 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
199 |
|
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
200 |
public void assertTrue(boolean actual, String message) { |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
201 |
assertEquals(actual, true, message); |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
202 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
203 |
|
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
204 |
public void assertFalse(boolean actual, String message) { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
205 |
assertEquals(actual, false, message); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
206 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
207 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
208 |
public File getSourceDir() { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
209 |
return new File(System.getProperty("test.src", ".")); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
210 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
211 |
|
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
212 |
public File getClassDir() { |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
213 |
return new File(System.getProperty("test.classes", TestBase.class.getResource(".").getPath())); |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
214 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
215 |
|
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
216 |
public File getSourceFile(String fileName) { |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
217 |
return new File(getSourceDir(), fileName); |
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
218 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
219 |
|
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
220 |
public File getClassFile(String fileName) { |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
221 |
return new File(getClassDir(), fileName); |
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
222 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
223 |
|
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
224 |
public File getClassFile(Class clazz) { |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
225 |
return getClassFile(clazz.getName().replace(".", "/") + ".class"); |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
226 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
227 |
|
25845
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
228 |
/** |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
229 |
* Prints message to standard error. New lines are converted to system dependent NL. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
230 |
* |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
231 |
* @param message string to print. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
232 |
*/ |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
233 |
public void echo(String message) { |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
234 |
printf(message + "\n"); |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
235 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
236 |
|
25845
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
237 |
/** |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
238 |
* Substitutes args in template and prints result to standard error. |
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
239 |
* New lines are converted to system dependent NL. |
25845
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
240 |
* |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
241 |
* @param template template in standard String.format(...) format. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
242 |
* @param args arguments to substitute in template. |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
243 |
*/ |
14935053bb07
8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents:
25434
diff
changeset
|
244 |
public void printf(String template, Object... args) { |
26101
d5dd2ecd2353
8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents:
25845
diff
changeset
|
245 |
System.err.printf(String.format(template, args).replace("\n", LINE_SEPARATOR)); |
25434
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
246 |
} |
823512a72660
8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
24223
diff
changeset
|
247 |
|
24223
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
248 |
public static class CompilationException extends Exception { |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
249 |
|
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
250 |
public CompilationException(String message) { |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
251 |
super(message); |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
252 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
253 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
254 |
|
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
255 |
public static class AssertionFailedException extends RuntimeException { |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
256 |
public AssertionFailedException(String message) { |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
257 |
super(message); |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
258 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
259 |
} |
90b07e33a49d
8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff
changeset
|
260 |
} |