4444import java .util .*;
4545import java .io .*;
4646import java .lang .reflect .Modifier ;
47+ import edu .rice .cs .plt .lambda .Thunk ;
4748import edu .rice .cs .plt .reflect .JavaVersion ;
4849import edu .rice .cs .plt .reflect .PathClassLoader ;
4950import edu .rice .cs .plt .reflect .EmptyClassLoader ;
@@ -224,6 +225,21 @@ protected String[] referenceType2String(ReferenceType[] rts) {
224225 return throwStrings ;
225226 }
226227
228+ /** We'll use this class loader to look up resources (*not* to load classes) */
229+ private static final Thunk <ClassLoader > RESOURCES = new Thunk <ClassLoader >() {
230+ private Options _cachedOptions = null ;
231+ private ClassLoader _cachedResult = null ;
232+ public ClassLoader value () {
233+ if (LanguageLevelConverter .OPT != _cachedOptions ) {
234+ _cachedOptions = LanguageLevelConverter .OPT ;
235+ Iterable <File > searchPath = IterUtil .compose (LanguageLevelConverter .OPT .bootClassPath (),
236+ LanguageLevelConverter .OPT .classPath ());
237+ _cachedResult = new PathClassLoader (EmptyClassLoader .INSTANCE , searchPath );
238+ }
239+ return _cachedResult ;
240+ }
241+ };
242+
227243 /**
228244 * Use the ASM class reader to read the class file corresponding to the class in
229245 * the specified directory, and use the information from ASM to build a SymbolData corresponding
@@ -232,22 +248,20 @@ protected String[] referenceType2String(ReferenceType[] rts) {
232248 * @param directoryName The directory where the class is located.
233249 */
234250 private SymbolData _classFile2SymbolData (String qualifiedClassName , String directoryName ) {
235- Iterable <File > searchPath = IterUtil .compose (LanguageLevelConverter .OPT .bootClassPath (),
236- LanguageLevelConverter .OPT .classPath ());
237- if (directoryName != null ) { searchPath = IterUtil .compose (searchPath , new File (directoryName )); }
238-
239251 ClassReader reader = null ;
240252 try {
241- /** We'll use this class loader to look up resources (*not* to load classes) */
242- PathClassLoader loader = new PathClassLoader (EmptyClassLoader .INSTANCE , searchPath );
243- InputStream stream = loader .getResourceAsStream (qualifiedClassName .replace ('.' , '/' ) + ".class" );
253+ String fileName = qualifiedClassName .replace ('.' , '/' ) + ".class" ;
254+ InputStream stream = RESOURCES .value ().getResourceAsStream (fileName );
255+ if (stream == null && directoryName != null ) {
256+ stream = PathClassLoader .getResourceInPathAsStream (fileName , new File (directoryName ));
257+ }
244258 if (stream == null ) { return null ; }
245259 // Let IOUtil handle the stream here, because it closes it when it's done, unlike ASM.
246260 reader = new ClassReader (IOUtil .toByteArray (stream ));
247261 }
248262 catch (IOException e ) { return null ; }
249263
250- //This is done so that the SymbolData in the Symboltable is updated and returned.
264+ // This is done so that the SymbolData in the Symboltable is updated and returned.
251265 final SymbolData sd ;
252266 SymbolData sdLookup = symbolTable .get (qualifiedClassName );
253267 if (sdLookup == null ) {
@@ -256,7 +270,7 @@ private SymbolData _classFile2SymbolData(String qualifiedClassName, String direc
256270 }
257271 else { sd = sdLookup ; }
258272
259- //make it be a non-continuation, since we are filing it in
273+ // make it be a non-continuation, since we are filling it in
260274 sd .setIsContinuation (false );
261275
262276 final SourceInfo lookupInfo = _makeSourceInfo (qualifiedClassName );
0 commit comments