author | duke |
Wed, 05 Jul 2017 18:59:39 +0200 | |
changeset 18044 | f1a01fb5f958 |
parent 9744 | 3e48977e539d |
child 27319 | 030080f03e4f |
permissions | -rw-r--r-- |
8221
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
1 |
/* |
9744
3e48977e539d
7044486: open jdk repos have files with incorrect copyright headers, which can end up in src bundles
katleman
parents:
8221
diff
changeset
|
2 |
* Copyright (c) 2011, 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(); |
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
45 |
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); |
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
46 |
JavacTask task = (JavacTask) compiler.getTask(null, fileManager, null, null, null, |
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
47 |
fileManager.getJavaFileObjects(thisSrc)); |
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
48 |
CompilationUnitTree tree = task.parse().iterator().next(); |
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
49 |
int count = 0; |
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
50 |
for (ImportTree importTree : tree.getImports()) { |
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
51 |
System.out.println(importTree); |
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
52 |
count++; |
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
53 |
} |
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
54 |
int expected = 7; |
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
55 |
if (count != expected) |
1f0ae42b572e
6963934: JCCompilationUnit.getImports does not report all imports
jjg
parents:
diff
changeset
|
56 |
throw new Exception("unexpected number of imports found: " + count + ", expected: " + expected); |
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 |
} |