author | chegar |
Tue, 14 Jan 2014 15:15:45 +0000 | |
changeset 22275 | de7efc0bb1a5 |
parent 17811 | afcf17402cdb |
child 24070 | 3852ce6db3f4 |
permissions | -rw-r--r-- |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
1 |
/* |
17576 | 2 |
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
4 |
* |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
10 |
* |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
16 |
* |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
20 |
* |
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
24 |
*/ |
4703
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
25 |
|
12085
ce2780cb121f
7150579: Moved ant code into a separate package, anttasks.
ohrstrom
parents:
9087
diff
changeset
|
26 |
package genstubs; |
ce2780cb121f
7150579: Moved ant code into a separate package, anttasks.
ohrstrom
parents:
9087
diff
changeset
|
27 |
|
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
28 |
import java.io.*; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
29 |
import java.util.*; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
30 |
import javax.tools.JavaFileObject; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
31 |
import javax.tools.StandardJavaFileManager; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
32 |
import javax.tools.StandardLocation; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
33 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
34 |
import com.sun.source.tree.CompilationUnitTree; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
35 |
import com.sun.source.util.JavacTask; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
36 |
import com.sun.tools.javac.api.JavacTool; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
37 |
import com.sun.tools.javac.code.Flags; |
14364 | 38 |
import com.sun.tools.javac.code.TypeTag; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
39 |
import com.sun.tools.javac.tree.JCTree; |
17576 | 40 |
import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
41 |
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; |
4703
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
42 |
import com.sun.tools.javac.tree.JCTree.JCFieldAccess; |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
43 |
import com.sun.tools.javac.tree.JCTree.JCIdent; |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
44 |
import com.sun.tools.javac.tree.JCTree.JCImport; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
45 |
import com.sun.tools.javac.tree.JCTree.JCLiteral; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
46 |
import com.sun.tools.javac.tree.JCTree.JCMethodDecl; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
47 |
import com.sun.tools.javac.tree.JCTree.JCModifiers; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
48 |
import com.sun.tools.javac.tree.JCTree.JCVariableDecl; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
49 |
import com.sun.tools.javac.tree.Pretty; |
4703
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
50 |
import com.sun.tools.javac.tree.TreeMaker; |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
51 |
import com.sun.tools.javac.tree.TreeScanner; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
52 |
import com.sun.tools.javac.tree.TreeTranslator; |
4703
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
53 |
import com.sun.tools.javac.util.Context; |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
54 |
import com.sun.tools.javac.util.ListBuffer; |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
55 |
import com.sun.tools.javac.util.Name; |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
56 |
import javax.tools.JavaFileManager; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
57 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
58 |
/** |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
59 |
* Generate stub source files by removing implementation details from input files. |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
60 |
* |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
61 |
* This is a special purpose stub generator, specific to the needs of generating |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
62 |
* stub files for JDK 7 API that are needed to compile langtools files that depend |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
63 |
* on that API. The stub generator works by removing as much of the API source code |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
64 |
* as possible without affecting the public signature, in order to reduce the |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
65 |
* transitive closure of the API being referenced. The resulting stubs can be |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
66 |
* put on the langtools sourcepath with -implicit:none to compile the langtools |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
67 |
* files that depend on the JDK 7 API. |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
68 |
* |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
69 |
* Usage: |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
70 |
* genstubs -s <outdir> -sourcepath <path> <classnames> |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
71 |
* |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
72 |
* The specified class names are looked up on the sourcepath, and corresponding |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
73 |
* stubs are written to the source output directory. |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
74 |
* |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
75 |
* Classes are parsed into javac ASTs, then processed with a javac TreeTranslator |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
76 |
* to remove implementation details, and written out in the source output directory. |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
77 |
* Documentation comments and annotations are removed. Method bodies are removed |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
78 |
* and methods are marked native. Private and package-private field definitions |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
79 |
* have their initializers replace with 0, 0.0, false, null as appropriate. |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
80 |
*/ |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
81 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
82 |
public class GenStubs { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
83 |
static class Fault extends Exception { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
84 |
private static final long serialVersionUID = 0; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
85 |
Fault(String message) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
86 |
super(message); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
87 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
88 |
Fault(String message, Throwable cause) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
89 |
super(message); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
90 |
initCause(cause); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
91 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
92 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
93 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
94 |
public static void main(String[] args) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
95 |
boolean ok = new GenStubs().run(args); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
96 |
if (!ok) |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
97 |
System.exit(1); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
98 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
99 |
|
12085
ce2780cb121f
7150579: Moved ant code into a separate package, anttasks.
ohrstrom
parents:
9087
diff
changeset
|
100 |
public boolean run(String... args) { |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
101 |
File outdir = null; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
102 |
String sourcepath = null; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
103 |
List<String> classes = new ArrayList<String>(); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
104 |
for (ListIterator<String> iter = Arrays.asList(args).listIterator(); iter.hasNext(); ) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
105 |
String arg = iter.next(); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
106 |
if (arg.equals("-s") && iter.hasNext()) |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
107 |
outdir = new File(iter.next()); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
108 |
else if (arg.equals("-sourcepath") && iter.hasNext()) |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
109 |
sourcepath = iter.next(); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
110 |
else if (arg.startsWith("-")) |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
111 |
throw new IllegalArgumentException(arg); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
112 |
else { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
113 |
classes.add(arg); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
114 |
while (iter.hasNext()) |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
115 |
classes.add(iter.next()); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
116 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
117 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
118 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
119 |
return run(sourcepath, outdir, classes); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
120 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
121 |
|
12085
ce2780cb121f
7150579: Moved ant code into a separate package, anttasks.
ohrstrom
parents:
9087
diff
changeset
|
122 |
public boolean run(String sourcepath, File outdir, List<String> classes) { |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
123 |
//System.err.println("run: sourcepath:" + sourcepath + " outdir:" + outdir + " classes:" + classes); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
124 |
if (sourcepath == null) |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
125 |
throw new IllegalArgumentException("sourcepath not set"); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
126 |
if (outdir == null) |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
127 |
throw new IllegalArgumentException("source output dir not set"); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
128 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
129 |
JavacTool tool = JavacTool.create(); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
130 |
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
131 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
132 |
try { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
133 |
fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir)); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
134 |
fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath)); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
135 |
List<JavaFileObject> files = new ArrayList<JavaFileObject>(); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
136 |
for (String c: classes) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
137 |
JavaFileObject fo = fm.getJavaFileForInput( |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
138 |
StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
139 |
if (fo == null) |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
140 |
error("class not found: " + c); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
141 |
else |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
142 |
files.add(fo); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
143 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
144 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
145 |
JavacTask t = tool.getTask(null, fm, null, null, null, files); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
146 |
Iterable<? extends CompilationUnitTree> trees = t.parse(); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
147 |
for (CompilationUnitTree tree: trees) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
148 |
makeStub(fm, tree); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
149 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
150 |
} catch (IOException e) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
151 |
error("IO error " + e, e); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
152 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
153 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
154 |
return (errors == 0); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
155 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
156 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
157 |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
158 |
CompilationUnitTree tree2 = new StubMaker().translate(tree); |
4703
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
159 |
CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
160 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
161 |
String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
162 |
JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
163 |
className, JavaFileObject.Kind.SOURCE, null); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
164 |
// System.err.println("Writing " + className + " to " + fo.getName()); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
165 |
Writer out = fo.openWriter(); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
166 |
try { |
4703
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
167 |
new Pretty(out, true).printExpr((JCTree) tree3); |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
168 |
} finally { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
169 |
out.close(); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
170 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
171 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
172 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
173 |
List<File> splitPath(String path) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
174 |
List<File> list = new ArrayList<File>(); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
175 |
for (String p: path.split(File.pathSeparator)) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
176 |
if (p.length() > 0) |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
177 |
list.add(new File(p)); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
178 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
179 |
return list; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
180 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
181 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
182 |
void error(String message) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
183 |
System.err.println(message); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
184 |
errors++; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
185 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
186 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
187 |
void error(String message, Throwable cause) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
188 |
error(message); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
189 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
190 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
191 |
int errors; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
192 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
193 |
class StubMaker extends TreeTranslator { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
194 |
CompilationUnitTree translate(CompilationUnitTree tree) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
195 |
return super.translate((JCCompilationUnit) tree); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
196 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
197 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
198 |
/** |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
199 |
* compilation units: remove javadoc comments |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
200 |
* -- required, in order to remove @deprecated tags, since we |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
201 |
* (separately) remove all annotations, including @Deprecated |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
202 |
*/ |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
203 |
public void visitTopLevel(JCCompilationUnit tree) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
204 |
super.visitTopLevel(tree); |
13184
8bc3123a920e
7180594: Fix GenStubs in langtools for build-infra builds
erikj
parents:
12085
diff
changeset
|
205 |
tree.docComments = null; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
206 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
207 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
208 |
/** |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
209 |
* methods: remove method bodies, make methods native |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
210 |
*/ |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
211 |
@Override |
17576 | 212 |
public void visitClassDef(JCClassDecl tree) { |
213 |
long prevClassMods = currClassMods; |
|
214 |
currClassMods = tree.mods.flags; |
|
215 |
try { |
|
216 |
super.visitClassDef(tree);; |
|
217 |
} finally { |
|
218 |
currClassMods = prevClassMods; |
|
219 |
} |
|
220 |
} |
|
221 |
private long currClassMods = 0; |
|
222 |
||
223 |
/** |
|
224 |
* methods: remove method bodies, make methods native |
|
225 |
*/ |
|
226 |
@Override |
|
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
227 |
public void visitMethodDef(JCMethodDecl tree) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
228 |
tree.mods = translate(tree.mods); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
229 |
tree.restype = translate(tree.restype); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
230 |
tree.typarams = translateTypeParams(tree.typarams); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
231 |
tree.params = translateVarDefs(tree.params); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
232 |
tree.thrown = translate(tree.thrown); |
17811
afcf17402cdb
8015641: genstubs needs to cope with static interface methods
jjg
parents:
17576
diff
changeset
|
233 |
if (tree.body != null) { |
17576 | 234 |
if ((currClassMods & Flags.INTERFACE) != 0) { |
17811
afcf17402cdb
8015641: genstubs needs to cope with static interface methods
jjg
parents:
17576
diff
changeset
|
235 |
tree.mods.flags &= ~(Flags.DEFAULT | Flags.STATIC); |
17576 | 236 |
} else { |
237 |
tree.mods.flags |= Flags.NATIVE; |
|
238 |
} |
|
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
239 |
tree.body = null; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
240 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
241 |
result = tree; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
242 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
243 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
244 |
/** |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
245 |
* modifiers: remove annotations |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
246 |
*/ |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
247 |
@Override |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
248 |
public void visitModifiers(JCModifiers tree) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
249 |
tree.annotations = com.sun.tools.javac.util.List.nil(); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
250 |
result = tree; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
251 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
252 |
|
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
253 |
/** |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
254 |
* field definitions: replace initializers with 0, 0.0, false etc |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
255 |
* when possible -- i.e. leave public, protected initializers alone |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
256 |
*/ |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
257 |
@Override |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
258 |
public void visitVarDef(JCVariableDecl tree) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
259 |
tree.mods = translate(tree.mods); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
260 |
tree.vartype = translate(tree.vartype); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
261 |
if (tree.init != null) { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
262 |
if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0) |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
263 |
tree.init = translate(tree.init); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
264 |
else { |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
265 |
String t = tree.vartype.toString(); |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
266 |
if (t.equals("boolean")) |
14364 | 267 |
tree.init = new JCLiteral(TypeTag.BOOLEAN, 0) { }; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
268 |
else if (t.equals("byte")) |
14364 | 269 |
tree.init = new JCLiteral(TypeTag.BYTE, 0) { }; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
270 |
else if (t.equals("char")) |
14364 | 271 |
tree.init = new JCLiteral(TypeTag.CHAR, 0) { }; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
272 |
else if (t.equals("double")) |
14364 | 273 |
tree.init = new JCLiteral(TypeTag.DOUBLE, 0.d) { }; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
274 |
else if (t.equals("float")) |
14364 | 275 |
tree.init = new JCLiteral(TypeTag.FLOAT, 0.f) { }; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
276 |
else if (t.equals("int")) |
14364 | 277 |
tree.init = new JCLiteral(TypeTag.INT, 0) { }; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
278 |
else if (t.equals("long")) |
14364 | 279 |
tree.init = new JCLiteral(TypeTag.LONG, 0) { }; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
280 |
else if (t.equals("short")) |
14364 | 281 |
tree.init = new JCLiteral(TypeTag.SHORT, 0) { }; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
282 |
else |
14364 | 283 |
tree.init = new JCLiteral(TypeTag.BOT, null) { }; |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
284 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
285 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
286 |
result = tree; |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
287 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
288 |
} |
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
289 |
|
4703
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
290 |
class ImportCleaner extends TreeScanner { |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
291 |
private Set<Name> names = new HashSet<Name>(); |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
292 |
private TreeMaker m; |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
293 |
|
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
294 |
ImportCleaner(JavaFileManager fm) { |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
295 |
// ImportCleaner itself doesn't require a filemanager, but instantiating |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
296 |
// a TreeMaker does, indirectly (via ClassReader, sigh) |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
297 |
Context c = new Context(); |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
298 |
c.put(JavaFileManager.class, fm); |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
299 |
m = TreeMaker.instance(c); |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
300 |
} |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
301 |
|
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
302 |
CompilationUnitTree removeRedundantImports(CompilationUnitTree t) { |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
303 |
JCCompilationUnit tree = (JCCompilationUnit) t; |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
304 |
tree.accept(this); |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
305 |
ListBuffer<JCTree> defs = new ListBuffer<JCTree>(); |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
306 |
for (JCTree def: tree.defs) { |
12085
ce2780cb121f
7150579: Moved ant code into a separate package, anttasks.
ohrstrom
parents:
9087
diff
changeset
|
307 |
if (def.getTag() == JCTree.Tag.IMPORT) { |
4703
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
308 |
JCImport imp = (JCImport) def; |
12085
ce2780cb121f
7150579: Moved ant code into a separate package, anttasks.
ohrstrom
parents:
9087
diff
changeset
|
309 |
if (imp.qualid.getTag() == JCTree.Tag.SELECT) { |
4703
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
310 |
JCFieldAccess qualid = (JCFieldAccess) imp.qualid; |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
311 |
if (!qualid.name.toString().equals("*") |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
312 |
&& !names.contains(qualid.name)) { |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
313 |
continue; |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
314 |
} |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
315 |
} |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
316 |
} |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
317 |
defs.add(def); |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
318 |
} |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
319 |
return m.TopLevel(tree.packageAnnotations, tree.pid, defs.toList()); |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
320 |
} |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
321 |
|
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
322 |
@Override |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
323 |
public void visitImport(JCImport tree) { } // ignore names found in imports |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
324 |
|
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
325 |
@Override |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
326 |
public void visitIdent(JCIdent tree) { |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
327 |
names.add(tree.name); |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
328 |
} |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
329 |
|
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
330 |
@Override |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
331 |
public void visitSelect(JCFieldAccess tree) { |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
332 |
super.visitSelect(tree); |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
333 |
names.add(tree.name); |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
334 |
} |
800e1750ff18
6909470: langtools stub generator should prune unnecessary imports
jjg
parents:
4415
diff
changeset
|
335 |
} |
4415
7d4f73717fba
6902337: fix langtools build to allow forward refs into jdk/ repo
jjg
parents:
diff
changeset
|
336 |
} |