mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8367279: Test tools/javac/tree/TreePosTest.java timed out
Reviewed-by: asotona
This commit is contained in:
parent
5a2700f231
commit
3607e9986f
@ -38,16 +38,11 @@ import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.charset.Charset;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JComboBox;
|
||||
@ -71,7 +66,7 @@ import javax.tools.StandardJavaFileManager;
|
||||
|
||||
import com.sun.source.tree.CaseTree.CaseKind;
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
import com.sun.source.util.JavacTask;
|
||||
import com.sun.tools.javac.api.JavacTaskPool;
|
||||
import com.sun.tools.javac.api.JavacTool;
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.tree.EndPosTable;
|
||||
@ -80,7 +75,6 @@ import com.sun.tools.javac.tree.JCTree.JCAnnotatedType;
|
||||
import com.sun.tools.javac.tree.JCTree.JCCase;
|
||||
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
||||
import com.sun.tools.javac.tree.JCTree.JCImport;
|
||||
import com.sun.tools.javac.tree.JCTree.JCImportBase;
|
||||
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCNewClass;
|
||||
@ -90,7 +84,6 @@ import com.sun.tools.javac.tree.TreeScanner;
|
||||
|
||||
import static com.sun.tools.javac.tree.JCTree.Tag.*;
|
||||
import static com.sun.tools.javac.util.Position.NOPOS;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Utility and test program to check validity of tree positions for tree nodes.
|
||||
@ -275,6 +268,7 @@ public class TreePosTest {
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
Reporter r = new Reporter(pw);
|
||||
JavacTool tool = JavacTool.create();
|
||||
JavacTaskPool pool = new JavacTaskPool(1);
|
||||
StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null);
|
||||
|
||||
/**
|
||||
@ -285,21 +279,25 @@ public class TreePosTest {
|
||||
* @throws TreePosTest.ParseException if any errors occur while parsing the file
|
||||
*/
|
||||
JCCompilationUnit read(File file) throws IOException, ParseException {
|
||||
JavacTool tool = JavacTool.create();
|
||||
r.errors = 0;
|
||||
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
|
||||
JavacTask task = tool.getTask(pw, fm, r, List.of("-proc:none"), null, files);
|
||||
Iterable<? extends CompilationUnitTree> trees = task.parse();
|
||||
pw.flush();
|
||||
if (r.errors > 0)
|
||||
throw new ParseException(sw.toString());
|
||||
Iterator<? extends CompilationUnitTree> iter = trees.iterator();
|
||||
if (!iter.hasNext())
|
||||
throw new Error("no trees found");
|
||||
JCCompilationUnit t = (JCCompilationUnit) iter.next();
|
||||
if (iter.hasNext())
|
||||
throw new Error("too many trees found");
|
||||
return t;
|
||||
return pool.getTask(pw, fm, r, List.of("-proc:none"), null, files, task -> {
|
||||
try {
|
||||
Iterable<? extends CompilationUnitTree> trees = task.parse();
|
||||
pw.flush();
|
||||
if (r.errors > 0)
|
||||
throw new ParseException(sw.toString());
|
||||
Iterator<? extends CompilationUnitTree> iter = trees.iterator();
|
||||
if (!iter.hasNext())
|
||||
throw new Error("no trees found");
|
||||
JCCompilationUnit t = (JCCompilationUnit) iter.next();
|
||||
if (iter.hasNext())
|
||||
throw new Error("too many trees found");
|
||||
return t;
|
||||
} catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -546,7 +544,7 @@ public class TreePosTest {
|
||||
/**
|
||||
* Thrown when errors are found parsing a java file.
|
||||
*/
|
||||
private static class ParseException extends Exception {
|
||||
private static class ParseException extends RuntimeException {
|
||||
ParseException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user