langtools/test/tools/javac/tree/T6963934.java
author jjg
Wed, 29 Oct 2014 17:25:23 -0700
changeset 27319 030080f03e4f
parent 9744 3e48977e539d
child 30730 d3ce7619db2c
permissions -rw-r--r--
8062348: langtools tests should close file manager (group 1) Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8221
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
     1
/*
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
     2
 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
8221
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
     4
 *
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
     8
 *
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    13
 * accompanied this code).
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    14
 *
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    18
 *
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    21
 * questions.
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    22
 */
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    23
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    24
/*
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    25
 * @test
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    26
 * @bug     6963934
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    27
 * @summary JCCompilationUnit.getImports does not report all imports
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    28
 */
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    29
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    30
import java.io.File;
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    31
import javax.tools.JavaCompiler;
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    32
import javax.tools.StandardJavaFileManager;
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    33
import javax.tools.ToolProvider;; // NOTE: extra semicolon for test
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    34
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    35
import com.sun.source.tree.CompilationUnitTree;
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    36
import com.sun.source.tree.ImportTree;
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    37
import com.sun.source.util.JavacTask;
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    38
; // NOTE: extra semicolon for test
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    39
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    40
public class T6963934 {
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    42
        File testSrc = new File(System.getProperty("test.src"));
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    43
        File thisSrc = new File(testSrc, T6963934.class.getSimpleName() + ".java");
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    44
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
    45
        try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
    46
            JavacTask task = (JavacTask) compiler.getTask(null, fileManager, null, null, null,
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
    47
                    fileManager.getJavaFileObjects(thisSrc));
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
    48
            CompilationUnitTree tree = task.parse().iterator().next();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
    49
            int count = 0;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
    50
            for (ImportTree importTree : tree.getImports()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
    51
                System.out.println(importTree);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
    52
                count++;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
    53
            }
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
    54
            int expected = 7;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
    55
            if (count != expected)
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9744
diff changeset
    56
                throw new Exception("unexpected number of imports found: " + count + ", expected: " + expected);
8221
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    57
        }
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    58
    }
1f0ae42b572e 6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff changeset
    59
}