author | jlahoda |
Thu, 13 Jul 2017 13:37:44 +0200 | |
changeset 45910 | c7092e4591b2 |
parent 45504 | ea7475564d07 |
permissions | -rw-r--r-- |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
1 |
/* |
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
2 |
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
4 |
* |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
10 |
* |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
16 |
* |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
20 |
* |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
23 |
* questions. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
24 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
25 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.code; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
27 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27858
diff
changeset
|
28 |
import java.io.IOException; |
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
29 |
import java.nio.file.Path; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
30 |
import java.util.EnumSet; |
27579 | 31 |
import java.util.HashMap; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
32 |
import java.util.Iterator; |
27579 | 33 |
import java.util.Map; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
34 |
import java.util.NoSuchElementException; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
35 |
import java.util.Set; |
27579 | 36 |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
37 |
import javax.lang.model.SourceVersion; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
38 |
import javax.tools.JavaFileManager; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
39 |
import javax.tools.JavaFileManager.Location; |
27579 | 40 |
import javax.tools.JavaFileObject; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
41 |
import javax.tools.JavaFileObject.Kind; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
42 |
import javax.tools.StandardJavaFileManager; |
36526 | 43 |
import javax.tools.StandardLocation; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
44 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24604
diff
changeset
|
45 |
import com.sun.tools.javac.code.Scope.WriteableScope; |
27579 | 46 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
47 |
import com.sun.tools.javac.code.Symbol.Completer; |
|
48 |
import com.sun.tools.javac.code.Symbol.CompletionFailure; |
|
36526 | 49 |
import com.sun.tools.javac.code.Symbol.ModuleSymbol; |
27579 | 50 |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
51 |
import com.sun.tools.javac.code.Symbol.TypeSymbol; |
|
52 |
import com.sun.tools.javac.comp.Annotate; |
|
53 |
import com.sun.tools.javac.file.JRTIndex; |
|
54 |
import com.sun.tools.javac.file.JavacFileManager; |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
55 |
import com.sun.tools.javac.jvm.ClassReader; |
27579 | 56 |
import com.sun.tools.javac.jvm.Profile; |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37001
diff
changeset
|
57 |
import com.sun.tools.javac.main.Option; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
58 |
import com.sun.tools.javac.platform.PlatformDescription; |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43772
diff
changeset
|
59 |
import com.sun.tools.javac.resources.CompilerProperties.Fragments; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
60 |
import com.sun.tools.javac.util.*; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
61 |
|
27579 | 62 |
import static javax.tools.StandardLocation.*; |
63 |
||
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
64 |
import static com.sun.tools.javac.code.Flags.*; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
65 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
66 |
|
27857 | 67 |
import com.sun.tools.javac.util.Dependencies.CompletionCause; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
68 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
69 |
/** |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
70 |
* This class provides operations to locate class definitions |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
71 |
* from the source and class files on the paths provided to javac. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
72 |
* |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
73 |
* <p><b>This is NOT part of any supported API. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
74 |
* If you write code that depends on this, you do so at your own risk. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
75 |
* This code and its internal interfaces are subject to change or |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
76 |
* deletion without notice.</b> |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
77 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
78 |
public class ClassFinder { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
79 |
/** The context key for the class finder. */ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
80 |
protected static final Context.Key<ClassFinder> classFinderKey = new Context.Key<>(); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
81 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
82 |
ClassReader reader; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
83 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27858
diff
changeset
|
84 |
private final Annotate annotate; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
85 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
86 |
/** Switch: verbose output. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
87 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
88 |
boolean verbose; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
89 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
90 |
/** |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
91 |
* Switch: cache completion failures unless -XDdev is used |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
92 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
93 |
private boolean cacheCompletionFailure; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
94 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
95 |
/** |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
96 |
* Switch: prefer source files instead of newer when both source |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
97 |
* and class are available |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
98 |
**/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
99 |
protected boolean preferSource; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
100 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
101 |
/** |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
102 |
* Switch: Search classpath and sourcepath for classes before the |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
103 |
* bootclasspath |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
104 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
105 |
protected boolean userPathsFirst; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
106 |
|
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
107 |
/** |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
108 |
* Switch: should read OTHER classfiles (.sig files) from PLATFORM_CLASS_PATH. |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
109 |
*/ |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
110 |
private boolean allowSigFiles; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
111 |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
112 |
/** The log to use for verbose output |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
113 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
114 |
final Log log; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
115 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
116 |
/** The symbol table. */ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
117 |
Symtab syms; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
118 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
119 |
/** The name table. */ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
120 |
final Names names; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
121 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
122 |
/** Force a completion failure on this name |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
123 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
124 |
final Name completionFailureName; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
125 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
126 |
/** Access to files |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
127 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
128 |
private final JavaFileManager fileManager; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
129 |
|
25844
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25443
diff
changeset
|
130 |
/** Dependency tracker |
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25443
diff
changeset
|
131 |
*/ |
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25443
diff
changeset
|
132 |
private final Dependencies dependencies; |
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25443
diff
changeset
|
133 |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
134 |
/** Factory for diagnostics |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
135 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
136 |
JCDiagnostic.Factory diagFactory; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
137 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
138 |
/** Can be reassigned from outside: |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
139 |
* the completer to be used for ".java" files. If this remains unassigned |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
140 |
* ".java" files will not be loaded. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
141 |
*/ |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
142 |
public Completer sourceCompleter = Completer.NULL_COMPLETER; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
143 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
144 |
/** The path name of the class file currently being read. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
145 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
146 |
protected JavaFileObject currentClassFile = null; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
147 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
148 |
/** The class or method currently being read. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
149 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
150 |
protected Symbol currentOwner = null; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
151 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
152 |
/** |
27579 | 153 |
* The currently selected profile. |
154 |
*/ |
|
155 |
private final Profile profile; |
|
156 |
||
157 |
/** |
|
158 |
* Use direct access to the JRTIndex to access the temporary |
|
159 |
* replacement for the info that used to be in ct.sym. |
|
160 |
* In time, this will go away and be replaced by the module system. |
|
161 |
*/ |
|
162 |
private final JRTIndex jrtIndex; |
|
163 |
||
164 |
/** |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
165 |
* Completer that delegates to the complete-method of this class. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
166 |
*/ |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42407
diff
changeset
|
167 |
private final Completer thisCompleter = this::complete; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
168 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
169 |
public Completer getCompleter() { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
170 |
return thisCompleter; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
171 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
172 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
173 |
/** Get the ClassFinder instance for this invocation. */ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
174 |
public static ClassFinder instance(Context context) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
175 |
ClassFinder instance = context.get(classFinderKey); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
176 |
if (instance == null) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
177 |
instance = new ClassFinder(context); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
178 |
return instance; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
179 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
180 |
|
36526 | 181 |
/** Construct a new class finder. */ |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
182 |
protected ClassFinder(Context context) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
183 |
context.put(classFinderKey, this); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
184 |
reader = ClassReader.instance(context); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
185 |
names = Names.instance(context); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
186 |
syms = Symtab.instance(context); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
187 |
fileManager = context.get(JavaFileManager.class); |
25844
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25443
diff
changeset
|
188 |
dependencies = Dependencies.instance(context); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
189 |
if (fileManager == null) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
190 |
throw new AssertionError("FileManager initialization error"); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
191 |
diagFactory = JCDiagnostic.Factory.instance(context); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
192 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
193 |
log = Log.instance(context); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
194 |
annotate = Annotate.instance(context); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
195 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
196 |
Options options = Options.instance(context); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37001
diff
changeset
|
197 |
verbose = options.isSet(Option.VERBOSE); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
198 |
cacheCompletionFailure = options.isUnset("dev"); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
199 |
preferSource = "source".equals(options.get("-Xprefer")); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37001
diff
changeset
|
200 |
userPathsFirst = options.isSet(Option.XXUSERPATHSFIRST); |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
201 |
allowSigFiles = context.get(PlatformDescription.class) != null; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
202 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
203 |
completionFailureName = |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
204 |
options.isSet("failcomplete") |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
205 |
? names.fromString(options.get("failcomplete")) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
206 |
: null; |
27579 | 207 |
|
208 |
// Temporary, until more info is available from the module system. |
|
209 |
boolean useCtProps; |
|
210 |
JavaFileManager fm = context.get(JavaFileManager.class); |
|
211 |
if (fm instanceof JavacFileManager) { |
|
212 |
JavacFileManager jfm = (JavacFileManager) fm; |
|
213 |
useCtProps = jfm.isDefaultBootClassPath() && jfm.isSymbolFileEnabled(); |
|
214 |
} else if (fm.getClass().getName().equals("com.sun.tools.sjavac.comp.SmartFileManager")) { |
|
215 |
useCtProps = !options.isSet("ignore.symbol.file"); |
|
216 |
} else { |
|
217 |
useCtProps = false; |
|
218 |
} |
|
219 |
jrtIndex = useCtProps && JRTIndex.isAvailable() ? JRTIndex.getSharedInstance() : null; |
|
220 |
||
221 |
profile = Profile.instance(context); |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
222 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
223 |
|
27579 | 224 |
|
225 |
/************************************************************************ |
|
226 |
* Temporary ct.sym replacement |
|
227 |
* |
|
228 |
* The following code is a temporary substitute for the ct.sym mechanism |
|
229 |
* used in JDK 6 thru JDK 8. |
|
230 |
* This mechanism will eventually be superseded by the Jigsaw module system. |
|
231 |
***********************************************************************/ |
|
232 |
||
233 |
/** |
|
234 |
* Returns any extra flags for a class symbol. |
|
235 |
* This information used to be provided using private annotations |
|
236 |
* in the class file in ct.sym; in time, this information will be |
|
237 |
* available from the module system. |
|
238 |
*/ |
|
239 |
long getSupplementaryFlags(ClassSymbol c) { |
|
36526 | 240 |
if (jrtIndex == null || !jrtIndex.isInJRT(c.classfile) || c.name == names.module_info) { |
27579 | 241 |
return 0; |
242 |
} |
|
243 |
||
244 |
if (supplementaryFlags == null) { |
|
245 |
supplementaryFlags = new HashMap<>(); |
|
246 |
} |
|
247 |
||
248 |
Long flags = supplementaryFlags.get(c.packge()); |
|
249 |
if (flags == null) { |
|
250 |
long newFlags = 0; |
|
251 |
try { |
|
252 |
JRTIndex.CtSym ctSym = jrtIndex.getCtSym(c.packge().flatName()); |
|
253 |
Profile minProfile = Profile.DEFAULT; |
|
254 |
if (ctSym.proprietary) |
|
255 |
newFlags |= PROPRIETARY; |
|
256 |
if (ctSym.minProfile != null) |
|
257 |
minProfile = Profile.lookup(ctSym.minProfile); |
|
258 |
if (profile != Profile.DEFAULT && minProfile.value > profile.value) { |
|
259 |
newFlags |= NOT_IN_PROFILE; |
|
260 |
} |
|
261 |
} catch (IOException ignore) { |
|
262 |
} |
|
263 |
supplementaryFlags.put(c.packge(), flags = newFlags); |
|
264 |
} |
|
265 |
return flags; |
|
266 |
} |
|
267 |
||
268 |
private Map<PackageSymbol, Long> supplementaryFlags; |
|
269 |
||
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
270 |
/************************************************************************ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
271 |
* Loading Classes |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
272 |
***********************************************************************/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
273 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
274 |
/** Completion for classes to be loaded. Before a class is loaded |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
275 |
* we make sure its enclosing class (if any) is loaded. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
276 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
277 |
private void complete(Symbol sym) throws CompletionFailure { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
278 |
if (sym.kind == TYP) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
279 |
try { |
25844
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25443
diff
changeset
|
280 |
ClassSymbol c = (ClassSymbol) sym; |
27857 | 281 |
dependencies.push(c, CompletionCause.CLASS_READER); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27858
diff
changeset
|
282 |
annotate.blockAnnotations(); |
25844
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25443
diff
changeset
|
283 |
c.members_field = new Scope.ErrorScope(c); // make sure it's always defined |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27858
diff
changeset
|
284 |
completeOwners(c.owner); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27858
diff
changeset
|
285 |
completeEnclosing(c); |
25844
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25443
diff
changeset
|
286 |
fillIn(c); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
287 |
} finally { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
27858
diff
changeset
|
288 |
annotate.unblockAnnotationsNoFlush(); |
25844
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25443
diff
changeset
|
289 |
dependencies.pop(); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
290 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
291 |
} else if (sym.kind == PCK) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
292 |
PackageSymbol p = (PackageSymbol)sym; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
293 |
try { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
294 |
fillIn(p); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
295 |
} catch (IOException ex) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43772
diff
changeset
|
296 |
JCDiagnostic msg = |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43772
diff
changeset
|
297 |
diagFactory.fragment(Fragments.ExceptionMessage(ex.getLocalizedMessage())); |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43772
diff
changeset
|
298 |
throw new CompletionFailure(sym, msg).initCause(ex); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
299 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
300 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
301 |
if (!reader.filling) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
302 |
annotate.flush(); // finish attaching annotations |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
303 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
304 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
305 |
/** complete up through the enclosing package. */ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
306 |
private void completeOwners(Symbol o) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
307 |
if (o.kind != PCK) completeOwners(o.owner); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
308 |
o.complete(); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
309 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
310 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
311 |
/** |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
312 |
* Tries to complete lexically enclosing classes if c looks like a |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
313 |
* nested class. This is similar to completeOwners but handles |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
314 |
* the situation when a nested class is accessed directly as it is |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
315 |
* possible with the Tree API or javax.lang.model.*. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
316 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
317 |
private void completeEnclosing(ClassSymbol c) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
318 |
if (c.owner.kind == PCK) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
319 |
Symbol owner = c.owner; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
320 |
for (Name name : Convert.enclosingCandidates(Convert.shortName(c.name))) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24604
diff
changeset
|
321 |
Symbol encl = owner.members().findFirst(name); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
322 |
if (encl == null) |
36526 | 323 |
encl = syms.getClass(c.packge().modle, TypeSymbol.formFlatName(name, owner)); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
324 |
if (encl != null) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
325 |
encl.complete(); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
326 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
327 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
328 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
329 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
330 |
/** Fill in definition of class `c' from corresponding class or |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
331 |
* source file. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
332 |
*/ |
36526 | 333 |
void fillIn(ClassSymbol c) { |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
334 |
if (completionFailureName == c.fullname) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43772
diff
changeset
|
335 |
JCDiagnostic msg = |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43772
diff
changeset
|
336 |
diagFactory.fragment(Fragments.UserSelectedCompletionFailure); |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43772
diff
changeset
|
337 |
throw new CompletionFailure(c, msg); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
338 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
339 |
currentOwner = c; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
340 |
JavaFileObject classfile = c.classfile; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
341 |
if (classfile != null) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
342 |
JavaFileObject previousClassFile = currentClassFile; |
45910
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
343 |
Symbol prevOwner = c.owner; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
344 |
Name prevName = c.fullname; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
345 |
try { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
346 |
if (reader.filling) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
347 |
Assert.error("Filling " + classfile.toUri() + " during " + previousClassFile); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
348 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
349 |
currentClassFile = classfile; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
350 |
if (verbose) { |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
31506
diff
changeset
|
351 |
log.printVerbose("loading", currentClassFile.getName()); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
352 |
} |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
353 |
if (classfile.getKind() == JavaFileObject.Kind.CLASS || |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
354 |
classfile.getKind() == JavaFileObject.Kind.OTHER) { |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
355 |
reader.readClassFile(c); |
27579 | 356 |
c.flags_field |= getSupplementaryFlags(c); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
357 |
} else { |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
358 |
if (!sourceCompleter.isTerminal()) { |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
359 |
sourceCompleter.complete(c); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
360 |
} else { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
361 |
throw new IllegalStateException("Source completer required to read " |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
362 |
+ classfile.toUri()); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
363 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
364 |
} |
45910
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
365 |
} catch (BadClassFile cf) { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
366 |
//the symbol may be partially initialized, purge it: |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
367 |
c.owner = prevOwner; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
368 |
c.members_field.getSymbols(sym -> sym.kind == TYP).forEach(sym -> { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
369 |
ClassSymbol csym = (ClassSymbol) sym; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
370 |
csym.owner = sym.packge(); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
371 |
csym.owner.members().enter(sym); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
372 |
csym.fullname = sym.flatName(); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
373 |
csym.name = Convert.shortName(sym.flatName()); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
374 |
csym.reset(); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
375 |
}); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
376 |
c.fullname = prevName; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
377 |
c.name = Convert.shortName(prevName); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
378 |
c.reset(); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45504
diff
changeset
|
379 |
throw cf; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
380 |
} finally { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
381 |
currentClassFile = previousClassFile; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
382 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
383 |
} else { |
27579 | 384 |
throw classFileNotFound(c); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
385 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
386 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
387 |
// where |
27579 | 388 |
private CompletionFailure classFileNotFound(ClassSymbol c) { |
389 |
JCDiagnostic diag = |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
43772
diff
changeset
|
390 |
diagFactory.fragment(Fragments.ClassFileNotFound(c.flatname)); |
27579 | 391 |
return newCompletionFailure(c, diag); |
392 |
} |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
393 |
/** Static factory for CompletionFailure objects. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
394 |
* In practice, only one can be used at a time, so we share one |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
395 |
* to reduce the expense of allocating new exception objects. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
396 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
397 |
private CompletionFailure newCompletionFailure(TypeSymbol c, |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
398 |
JCDiagnostic diag) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
399 |
if (!cacheCompletionFailure) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
400 |
// log.warning("proc.messager", |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
401 |
// Log.getLocalizedString("class.file.not.found", c.flatname)); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
402 |
// c.debug.printStackTrace(); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
403 |
return new CompletionFailure(c, diag); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
404 |
} else { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
405 |
CompletionFailure result = cachedCompletionFailure; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
406 |
result.sym = c; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
407 |
result.diag = diag; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
408 |
return result; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
409 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
410 |
} |
27579 | 411 |
private final CompletionFailure cachedCompletionFailure = |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
412 |
new CompletionFailure(null, (JCDiagnostic) null); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
413 |
{ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
414 |
cachedCompletionFailure.setStackTrace(new StackTraceElement[0]); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
415 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
416 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
417 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
418 |
/** Load a toplevel class with given fully qualified name |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
419 |
* The class is entered into `classes' only if load was successful. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
420 |
*/ |
36526 | 421 |
public ClassSymbol loadClass(ModuleSymbol msym, Name flatname) throws CompletionFailure { |
422 |
Assert.checkNonNull(msym); |
|
423 |
Name packageName = Convert.packagePart(flatname); |
|
424 |
PackageSymbol ps = syms.lookupPackage(msym, packageName); |
|
425 |
||
426 |
Assert.checkNonNull(ps.modle, () -> "msym=" + msym + "; flatName=" + flatname); |
|
427 |
||
428 |
boolean absent = syms.getClass(ps.modle, flatname) == null; |
|
429 |
ClassSymbol c = syms.enterClass(ps.modle, flatname); |
|
430 |
||
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
431 |
if (c.members_field == null) { |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
432 |
try { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
433 |
c.complete(); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
434 |
} catch (CompletionFailure ex) { |
36526 | 435 |
if (absent) syms.removeClass(ps.modle, flatname); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
436 |
throw ex; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
437 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
438 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
439 |
return c; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
440 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
441 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
442 |
/************************************************************************ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
443 |
* Loading Packages |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
444 |
***********************************************************************/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
445 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
446 |
/** Include class corresponding to given class file in package, |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
447 |
* unless (1) we already have one the same kind (.class or .java), or |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
448 |
* (2) we have one of the other kind, and the given class file |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
449 |
* is older. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
450 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
451 |
protected void includeClassFile(PackageSymbol p, JavaFileObject file) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
452 |
if ((p.flags_field & EXISTS) == 0) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
453 |
for (Symbol q = p; q != null && q.kind == PCK; q = q.owner) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
454 |
q.flags_field |= EXISTS; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
455 |
JavaFileObject.Kind kind = file.getKind(); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
456 |
int seen; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
457 |
if (kind == JavaFileObject.Kind.CLASS || kind == JavaFileObject.Kind.OTHER) |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
458 |
seen = CLASS_SEEN; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
459 |
else |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
460 |
seen = SOURCE_SEEN; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
461 |
String binaryName = fileManager.inferBinaryName(currentLoc, file); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
462 |
int lastDot = binaryName.lastIndexOf("."); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
463 |
Name classname = names.fromString(binaryName.substring(lastDot + 1)); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
464 |
boolean isPkgInfo = classname == names.package_info; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
465 |
ClassSymbol c = isPkgInfo |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
466 |
? p.package_info |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24604
diff
changeset
|
467 |
: (ClassSymbol) p.members_field.findFirst(classname); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
468 |
if (c == null) { |
36526 | 469 |
c = syms.enterClass(p.modle, classname, p); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
470 |
if (c.classfile == null) // only update the file if's it's newly created |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
471 |
c.classfile = file; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
472 |
if (isPkgInfo) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
473 |
p.package_info = c; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
474 |
} else { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
475 |
if (c.owner == p) // it might be an inner class |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
476 |
p.members_field.enter(c); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
477 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
478 |
} else if (!preferCurrent && c.classfile != null && (c.flags_field & seen) == 0) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
479 |
// if c.classfile == null, we are currently compiling this class |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
480 |
// and no further action is necessary. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
481 |
// if (c.flags_field & seen) != 0, we have already encountered |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
482 |
// a file of the same kind; again no further action is necessary. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
483 |
if ((c.flags_field & (CLASS_SEEN | SOURCE_SEEN)) != 0) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
484 |
c.classfile = preferredFileObject(file, c.classfile); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
485 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
486 |
c.flags_field |= seen; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
487 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
488 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
489 |
/** Implement policy to choose to derive information from a source |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
490 |
* file or a class file when both are present. May be overridden |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
491 |
* by subclasses. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
492 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
493 |
protected JavaFileObject preferredFileObject(JavaFileObject a, |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
494 |
JavaFileObject b) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
495 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
496 |
if (preferSource) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
497 |
return (a.getKind() == JavaFileObject.Kind.SOURCE) ? a : b; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
498 |
else { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
499 |
long adate = a.getLastModified(); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
500 |
long bdate = b.getLastModified(); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
501 |
// 6449326: policy for bad lastModifiedTime in ClassReader |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
502 |
//assert adate >= 0 && bdate >= 0; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
503 |
return (adate > bdate) ? a : b; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
504 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
505 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
506 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
507 |
/** |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
508 |
* specifies types of files to be read when filling in a package symbol |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
509 |
*/ |
36526 | 510 |
// Note: overridden by JavadocClassFinder |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
511 |
protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
512 |
return EnumSet.of(JavaFileObject.Kind.CLASS, JavaFileObject.Kind.SOURCE); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
513 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
514 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
515 |
/** |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
516 |
* this is used to support javadoc |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
517 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
518 |
protected void extraFileActions(PackageSymbol pack, JavaFileObject fe) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
519 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
520 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
521 |
protected Location currentLoc; // FIXME |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
522 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
523 |
private boolean verbosePath = true; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
524 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
525 |
// Set to true when the currently selected file should be kept |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
526 |
private boolean preferCurrent; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
527 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
528 |
/** Load directory of package into members scope. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
529 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
530 |
private void fillIn(PackageSymbol p) throws IOException { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
531 |
if (p.members_field == null) |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24604
diff
changeset
|
532 |
p.members_field = WriteableScope.create(p); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
533 |
|
36526 | 534 |
ModuleSymbol msym = p.modle; |
535 |
||
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42407
diff
changeset
|
536 |
Assert.checkNonNull(msym, p::toString); |
36526 | 537 |
|
538 |
msym.complete(); |
|
539 |
||
540 |
if (msym == syms.noModule) { |
|
541 |
preferCurrent = false; |
|
542 |
if (userPathsFirst) { |
|
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
543 |
scanUserPaths(p, true); |
36526 | 544 |
preferCurrent = true; |
545 |
scanPlatformPath(p); |
|
546 |
} else { |
|
547 |
scanPlatformPath(p); |
|
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
548 |
scanUserPaths(p, true); |
36526 | 549 |
} |
550 |
} else if (msym.classLocation == StandardLocation.CLASS_PATH) { |
|
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
551 |
scanUserPaths(p, msym.sourceLocation == StandardLocation.SOURCE_PATH); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
552 |
} else { |
36526 | 553 |
scanModulePaths(p, msym); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
554 |
} |
36526 | 555 |
} |
556 |
||
557 |
// TODO: for now, this is a much simplified form of scanUserPaths |
|
558 |
// and (deliberately) does not default sourcepath to classpath. |
|
559 |
// But, we need to think about retaining existing behavior for |
|
560 |
// -classpath and -sourcepath for single module mode. |
|
561 |
// One plausible solution is to detect if the module's sourceLocation |
|
562 |
// is the same as the module's classLocation. |
|
563 |
private void scanModulePaths(PackageSymbol p, ModuleSymbol msym) throws IOException { |
|
564 |
Set<JavaFileObject.Kind> kinds = getPackageFileKinds(); |
|
565 |
||
566 |
Set<JavaFileObject.Kind> classKinds = EnumSet.copyOf(kinds); |
|
567 |
classKinds.remove(JavaFileObject.Kind.SOURCE); |
|
568 |
boolean wantClassFiles = !classKinds.isEmpty(); |
|
569 |
||
570 |
Set<JavaFileObject.Kind> sourceKinds = EnumSet.copyOf(kinds); |
|
571 |
sourceKinds.remove(JavaFileObject.Kind.CLASS); |
|
572 |
boolean wantSourceFiles = !sourceKinds.isEmpty(); |
|
573 |
||
574 |
String packageName = p.fullname.toString(); |
|
575 |
||
576 |
Location classLocn = msym.classLocation; |
|
577 |
Location sourceLocn = msym.sourceLocation; |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
578 |
Location patchLocn = msym.patchLocation; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
579 |
Location patchOutLocn = msym.patchOutputLocation; |
36526 | 580 |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
581 |
boolean prevPreferCurrent = preferCurrent; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
582 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
583 |
try { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
584 |
preferCurrent = false; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
585 |
if (wantClassFiles && (patchOutLocn != null)) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
586 |
fillIn(p, patchOutLocn, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
587 |
list(patchOutLocn, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
588 |
p, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
589 |
packageName, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
590 |
classKinds)); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
591 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
592 |
if ((wantClassFiles || wantSourceFiles) && (patchLocn != null)) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
593 |
Set<JavaFileObject.Kind> combined = EnumSet.noneOf(JavaFileObject.Kind.class); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
594 |
combined.addAll(classKinds); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
595 |
combined.addAll(sourceKinds); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
596 |
fillIn(p, patchLocn, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
597 |
list(patchLocn, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
598 |
p, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
599 |
packageName, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
600 |
combined)); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
601 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
602 |
preferCurrent = true; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
603 |
if (wantClassFiles && (classLocn != null)) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
604 |
fillIn(p, classLocn, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
605 |
list(classLocn, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
606 |
p, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
607 |
packageName, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
608 |
classKinds)); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
609 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
610 |
if (wantSourceFiles && (sourceLocn != null)) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
611 |
fillIn(p, sourceLocn, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
612 |
list(sourceLocn, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
613 |
p, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
614 |
packageName, |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
615 |
sourceKinds)); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
616 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
617 |
} finally { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
42827
diff
changeset
|
618 |
preferCurrent = prevPreferCurrent; |
36526 | 619 |
} |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
620 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
621 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
622 |
/** |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
623 |
* Scans class path and source path for files in given package. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
624 |
*/ |
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
625 |
private void scanUserPaths(PackageSymbol p, boolean includeSourcePath) throws IOException { |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
626 |
Set<JavaFileObject.Kind> kinds = getPackageFileKinds(); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
627 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
628 |
Set<JavaFileObject.Kind> classKinds = EnumSet.copyOf(kinds); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
629 |
classKinds.remove(JavaFileObject.Kind.SOURCE); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
630 |
boolean wantClassFiles = !classKinds.isEmpty(); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
631 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
632 |
Set<JavaFileObject.Kind> sourceKinds = EnumSet.copyOf(kinds); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
633 |
sourceKinds.remove(JavaFileObject.Kind.CLASS); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
634 |
boolean wantSourceFiles = !sourceKinds.isEmpty(); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
635 |
|
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
636 |
boolean haveSourcePath = includeSourcePath && fileManager.hasLocation(SOURCE_PATH); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
637 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
638 |
if (verbose && verbosePath) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
639 |
if (fileManager instanceof StandardJavaFileManager) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
640 |
StandardJavaFileManager fm = (StandardJavaFileManager)fileManager; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
641 |
if (haveSourcePath && wantSourceFiles) { |
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
642 |
List<Path> path = List.nil(); |
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
643 |
for (Path sourcePath : fm.getLocationAsPaths(SOURCE_PATH)) { |
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
644 |
path = path.prepend(sourcePath); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
645 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
646 |
log.printVerbose("sourcepath", path.reverse().toString()); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
647 |
} else if (wantSourceFiles) { |
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
648 |
List<Path> path = List.nil(); |
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
649 |
for (Path classPath : fm.getLocationAsPaths(CLASS_PATH)) { |
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
650 |
path = path.prepend(classPath); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
651 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
652 |
log.printVerbose("sourcepath", path.reverse().toString()); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
653 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
654 |
if (wantClassFiles) { |
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
655 |
List<Path> path = List.nil(); |
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
656 |
for (Path platformPath : fm.getLocationAsPaths(PLATFORM_CLASS_PATH)) { |
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
657 |
path = path.prepend(platformPath); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
658 |
} |
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
659 |
for (Path classPath : fm.getLocationAsPaths(CLASS_PATH)) { |
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
34560
diff
changeset
|
660 |
path = path.prepend(classPath); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
661 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
662 |
log.printVerbose("classpath", path.reverse().toString()); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
663 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
664 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
665 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
666 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
667 |
String packageName = p.fullname.toString(); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
668 |
if (wantSourceFiles && !haveSourcePath) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
669 |
fillIn(p, CLASS_PATH, |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
670 |
list(CLASS_PATH, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
671 |
p, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
672 |
packageName, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
673 |
kinds)); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
674 |
} else { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
675 |
if (wantClassFiles) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
676 |
fillIn(p, CLASS_PATH, |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
677 |
list(CLASS_PATH, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
678 |
p, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
679 |
packageName, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
680 |
classKinds)); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
681 |
if (wantSourceFiles) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
682 |
fillIn(p, SOURCE_PATH, |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
683 |
list(SOURCE_PATH, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
684 |
p, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
685 |
packageName, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
686 |
sourceKinds)); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
687 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
688 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
689 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
690 |
/** |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
691 |
* Scans platform class path for files in given package. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
692 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
693 |
private void scanPlatformPath(PackageSymbol p) throws IOException { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
694 |
fillIn(p, PLATFORM_CLASS_PATH, |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
695 |
list(PLATFORM_CLASS_PATH, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
696 |
p, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
697 |
p.fullname.toString(), |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
698 |
allowSigFiles ? EnumSet.of(JavaFileObject.Kind.CLASS, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
699 |
JavaFileObject.Kind.OTHER) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
700 |
: EnumSet.of(JavaFileObject.Kind.CLASS))); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
701 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
702 |
// where |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
703 |
@SuppressWarnings("fallthrough") |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
704 |
private void fillIn(PackageSymbol p, |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
705 |
Location location, |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
706 |
Iterable<JavaFileObject> files) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
707 |
{ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
708 |
currentLoc = location; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
709 |
for (JavaFileObject fo : files) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
710 |
switch (fo.getKind()) { |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
711 |
case OTHER: |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
712 |
if (!isSigFile(location, fo)) { |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
713 |
extraFileActions(p, fo); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
714 |
break; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
715 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
716 |
//intentional fall-through: |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
717 |
case CLASS: |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
718 |
case SOURCE: { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
719 |
// TODO pass binaryName to includeClassFile |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
720 |
String binaryName = fileManager.inferBinaryName(currentLoc, fo); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
721 |
String simpleName = binaryName.substring(binaryName.lastIndexOf(".") + 1); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
722 |
if (SourceVersion.isIdentifier(simpleName) || |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
723 |
simpleName.equals("package-info")) |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
724 |
includeClassFile(p, fo); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
725 |
break; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
726 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
727 |
default: |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
728 |
extraFileActions(p, fo); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
729 |
break; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
730 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
731 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
732 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
733 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
734 |
boolean isSigFile(Location location, JavaFileObject fo) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
735 |
return location == PLATFORM_CLASS_PATH && |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
736 |
allowSigFiles && |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
737 |
fo.getName().endsWith(".sig"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
738 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
739 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
740 |
Iterable<JavaFileObject> list(Location location, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
741 |
PackageSymbol p, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
742 |
String packageName, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
743 |
Set<Kind> kinds) throws IOException { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
744 |
Iterable<JavaFileObject> listed = fileManager.list(location, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
745 |
packageName, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
746 |
EnumSet.allOf(Kind.class), |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
747 |
false); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
748 |
return () -> new Iterator<JavaFileObject>() { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
749 |
private final Iterator<JavaFileObject> original = listed.iterator(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
750 |
private JavaFileObject next; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
751 |
@Override |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
752 |
public boolean hasNext() { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
753 |
if (next == null) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
754 |
while (original.hasNext()) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
755 |
JavaFileObject fo = original.next(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
756 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
757 |
if (fo.getKind() != Kind.CLASS && |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
758 |
fo.getKind() != Kind.SOURCE && |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
759 |
!isSigFile(currentLoc, fo)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
760 |
p.flags_field |= Flags.HAS_RESOURCE; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
761 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
762 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
763 |
if (kinds.contains(fo.getKind())) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
764 |
next = fo; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
765 |
break; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
766 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
767 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
768 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
769 |
return next != null; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
770 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
771 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
772 |
@Override |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
773 |
public JavaFileObject next() { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
774 |
if (!hasNext()) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
775 |
throw new NoSuchElementException(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
776 |
JavaFileObject result = next; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
777 |
next = null; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
778 |
return result; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
779 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
780 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
781 |
}; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
782 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40768
diff
changeset
|
783 |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
784 |
/** |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
785 |
* Used for bad class definition files, such as bad .class files or |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
786 |
* for .java files with unexpected package or class names. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
787 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
788 |
public static class BadClassFile extends CompletionFailure { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
789 |
private static final long serialVersionUID = 0; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
790 |
|
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
791 |
public BadClassFile(TypeSymbol sym, JavaFileObject file, JCDiagnostic diag, |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
792 |
JCDiagnostic.Factory diagFactory) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
793 |
super(sym, createBadClassFileDiagnostic(file, diag, diagFactory)); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
794 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
795 |
// where |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
796 |
private static JCDiagnostic createBadClassFileDiagnostic( |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
797 |
JavaFileObject file, JCDiagnostic diag, JCDiagnostic.Factory diagFactory) { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
798 |
String key = (file.getKind() == JavaFileObject.Kind.SOURCE |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
799 |
? "bad.source.file.header" : "bad.class.file.header"); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
800 |
return diagFactory.fragment(key, file, diag); |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
801 |
} |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
802 |
} |
37001
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
803 |
|
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
804 |
public static class BadEnclosingMethodAttr extends BadClassFile { |
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
805 |
private static final long serialVersionUID = 0; |
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
806 |
|
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
807 |
public BadEnclosingMethodAttr(TypeSymbol sym, JavaFileObject file, JCDiagnostic diag, |
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
808 |
JCDiagnostic.Factory diagFactory) { |
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
809 |
super(sym, file, diag, diagFactory); |
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
810 |
} |
594b4565d8a4
8151191: javac error when running javadoc on some inner classes
vromero
parents:
36526
diff
changeset
|
811 |
} |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
diff
changeset
|
812 |
} |