163 return "Test";
164 }
165 }
166
167 private ClassFile compileAndReturn(String fullFile, String testClass, String... extraParams) throws Exception {
168 File source = writeTestFile(fullFile);
169 File clazzFile = compileTestFile(source, testClass);
170 return ClassFile.read(clazzFile);
171 }
172
173 protected File writeTestFile(String fullFile) throws IOException {
174 File f = new File("Test.java");
175 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
176 out.println(fullFile);
177 out.close();
178 return f;
179 }
180
181 protected File compileTestFile(File f, String testClass, String... extraParams) {
182 List<String> options = new ArrayList<>();
183 options.addAll(Arrays.asList("-source", "1.8"));
184 options.addAll(Arrays.asList(extraParams));
185 options.add(f.getPath());
186 int rc = com.sun.tools.javac.Main.compile(options.toArray(new String[options.size()]));
187 if (rc != 0)
188 throw new Error("compilation failed. rc=" + rc);
189 String path;
190 if (f.getParent() != null) {
191 path = f.getParent();
192 } else {
193 path = "";
194 }
195
196 return new File(path + testClass + ".class");
197 }
198
199 private String wrap(String compact) {
200 StringBuilder sb = new StringBuilder();
201
202 // Automatically import java.util
203 sb.append("\nimport java.util.*;");
|
163 return "Test";
164 }
165 }
166
167 private ClassFile compileAndReturn(String fullFile, String testClass, String... extraParams) throws Exception {
168 File source = writeTestFile(fullFile);
169 File clazzFile = compileTestFile(source, testClass);
170 return ClassFile.read(clazzFile);
171 }
172
173 protected File writeTestFile(String fullFile) throws IOException {
174 File f = new File("Test.java");
175 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
176 out.println(fullFile);
177 out.close();
178 return f;
179 }
180
181 protected File compileTestFile(File f, String testClass, String... extraParams) {
182 List<String> options = new ArrayList<>();
183 options.addAll(Arrays.asList(extraParams));
184 options.add(f.getPath());
185 int rc = com.sun.tools.javac.Main.compile(options.toArray(new String[options.size()]));
186 if (rc != 0)
187 throw new Error("compilation failed. rc=" + rc);
188 String path;
189 if (f.getParent() != null) {
190 path = f.getParent();
191 } else {
192 path = "";
193 }
194
195 return new File(path + testClass + ".class");
196 }
197
198 private String wrap(String compact) {
199 StringBuilder sb = new StringBuilder();
200
201 // Automatically import java.util
202 sb.append("\nimport java.util.*;");
|