jjg@837: /* jjg@837: * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved. jjg@837: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@837: * jjg@837: * This code is free software; you can redistribute it and/or modify it jjg@837: * under the terms of the GNU General Public License version 2 only, as jjg@837: * published by the Free Software Foundation. jjg@837: * jjg@837: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@837: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@837: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@837: * version 2 for more details (a copy is included in the LICENSE file that jjg@837: * accompanied this code). jjg@837: * jjg@837: * You should have received a copy of the GNU General Public License version jjg@837: * 2 along with this work; if not, write to the Free Software Foundation, jjg@837: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@837: * jjg@837: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jjg@837: * or visit www.oracle.com if you need additional information or have any jjg@837: * questions. jjg@837: */ jjg@837: jjg@837: /* jjg@837: * @test jjg@837: * @bug 6963934 jjg@837: * @summary JCCompilationUnit.getImports does not report all imports jjg@837: */ jjg@837: jjg@837: import java.io.File; jjg@837: import javax.tools.JavaCompiler; jjg@837: import javax.tools.StandardJavaFileManager; jjg@837: import javax.tools.ToolProvider;; // NOTE: extra semicolon for test jjg@837: jjg@837: import com.sun.source.tree.CompilationUnitTree; jjg@837: import com.sun.source.tree.ImportTree; jjg@837: import com.sun.source.util.JavacTask; jjg@837: ; // NOTE: extra semicolon for test jjg@837: jjg@837: public class T6963934 { jjg@837: public static void main(String[] args) throws Exception { jjg@837: File testSrc = new File(System.getProperty("test.src")); jjg@837: File thisSrc = new File(testSrc, T6963934.class.getSimpleName() + ".java"); jjg@837: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); jjg@837: StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); jjg@837: JavacTask task = (JavacTask) compiler.getTask(null, fileManager, null, null, null, jjg@837: fileManager.getJavaFileObjects(thisSrc)); jjg@837: CompilationUnitTree tree = task.parse().iterator().next(); jjg@837: int count = 0; jjg@837: for (ImportTree importTree : tree.getImports()) { jjg@837: System.out.println(importTree); jjg@837: count++; jjg@837: } jjg@837: int expected = 7; jjg@837: if (count != expected) jjg@837: throw new Exception("unexpected number of imports found: " + count + ", expected: " + expected); jjg@837: } jjg@837: }