Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javac/6440583/T6440583.java
38813 views
/*1* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 644058326* @summary better error recovery27*/2829import java.io.*;30import java.util.*;31import javax.tools.*;32import com.sun.source.tree.*;33import com.sun.source.util.*;34import com.sun.tools.javac.api.*;35import com.sun.tools.javac.tree.JCTree.*;3637public class T6440583 {38public static void main(String... args) throws Exception {39String testSrc = System.getProperty("test.src", ".");40String testClasses = System.getProperty("test.classes", ".");41JavacTool tool = JavacTool.create();42StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);43Iterable<? extends JavaFileObject> files =44fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java")));45JavacTask task = tool.getTask(null, fm, null, null, null, files);4647Iterable<? extends Tree> trees = task.parse();4849TreeScanner<Boolean,Void> checker = new TreeScanner<Boolean,Void>() {50public Boolean visitErroneous(ErroneousTree tree, Void ignore) {51JCErroneous etree = (JCErroneous) tree;52List<? extends Tree> errs = etree.getErrorTrees();53System.err.println("errs: " + errs);54if (errs == null || errs.size() == 0)55throw new AssertionError("no error trees found");56found = true;57return true;58}59};6061for (Tree tree: trees)62checker.scan(tree, null);6364if (!found)65throw new AssertionError("no ErroneousTree nodes found");66}6768private static boolean found;69}707172