Path: blob/master/test/langtools/tools/javac/6440583/T6440583.java
41149 views
/*1* Copyright (c) 2006, 2015, 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* @modules jdk.compiler/com.sun.tools.javac.api28* jdk.compiler/com.sun.tools.javac.file29* jdk.compiler/com.sun.tools.javac.tree30* jdk.compiler/com.sun.tools.javac.util31*/3233import java.io.*;34import java.util.*;35import javax.tools.*;36import com.sun.source.tree.*;37import com.sun.source.util.*;38import com.sun.tools.javac.api.*;39import com.sun.tools.javac.tree.JCTree.*;4041public class T6440583 {42public static void main(String... args) throws Exception {43String testSrc = System.getProperty("test.src", ".");44String testClasses = System.getProperty("test.classes", ".");45JavacTool tool = JavacTool.create();46try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {47Iterable<? extends JavaFileObject> files =48fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java")));49JavacTask task = tool.getTask(null, fm, null, null, null, files);5051Iterable<? extends Tree> trees = task.parse();5253TreeScanner<Boolean,Void> checker = new TreeScanner<Boolean,Void>() {54public Boolean visitErroneous(ErroneousTree tree, Void ignore) {55JCErroneous etree = (JCErroneous) tree;56List<? extends Tree> errs = etree.getErrorTrees();57System.err.println("errs: " + errs);58if (errs == null || errs.size() == 0)59throw new AssertionError("no error trees found");60found = true;61return true;62}63};6465for (Tree tree: trees)66checker.scan(tree, null);6768if (!found)69throw new AssertionError("no ErroneousTree nodes found");70}71}7273private static boolean found;74}757677