MCPcopy Index your code
hub / github.com/beanshell/beanshell / reloadClasses

Method reloadClasses

src/bsh/classpath/ClassManagerImpl.java:358–410  ·  view source on GitHub ↗

Reloading classes means creating a new classloader and using it whenever we are asked for classes in the appropriate space. For this we use a DiscreteFilesClassLoader

( String [] classNames )

Source from the content-addressed store, hash-verified

356 For this we use a DiscreteFilesClassLoader
357 */
358 @Override
359 public void reloadClasses( String [] classNames )
360 throws ClassPathException
361 {
362 // validate that it is a class here?
363
364 // init base class loader if there is none...
365 if ( baseLoader == null )
366 initBaseLoader();
367
368 DiscreteFilesClassLoader.ClassSourceMap map =
369 new DiscreteFilesClassLoader.ClassSourceMap();
370
371 for (int i=0; i< classNames.length; i++) {
372 String name = classNames[i];
373
374 // look in baseLoader class path
375 ClassSource classSource = baseClassPath.getClassSource( name );
376
377 // look in user class path
378 if ( classSource == null ) {
379 BshClassPath.getUserClassPath().insureInitialized();
380 classSource = BshClassPath.getUserClassPath().getClassSource(
381 name );
382 }
383
384 // No point in checking boot class path, can't reload those.
385 // else we could have used fullClassPath above.
386
387 if ( classSource == null )
388 throw new ClassPathException("Nothing known about class: "
389 +name );
390
391 // JarClassSource is not working... just need to implement it's
392 // getCode() method or, if we decide to, allow the BshClassManager
393 // to handle it... since it is a URLClassLoader and can handle JARs
394 if ( classSource instanceof JarClassSource )
395 throw new ClassPathException("Cannot reload class: "+name+
396 " from source: "+ classSource );
397
398 map.put( name, classSource );
399 }
400
401 // Create classloader for the set of classes
402 ClassLoader cl = new DiscreteFilesClassLoader( this, map );
403
404 // map those classes the loader in the overlay map
405 Iterator it = map.keySet().iterator();
406 while ( it.hasNext() )
407 loaderMap.put( (String)it.next(), cl );
408
409 classLoaderChanged();
410 }
411
412 /**
413 Reload all classes in the specified package: e.g. "com.sun.tools"

Callers 2

reloadPackageMethod · 0.95
defineClassMethod · 0.95

Calls 11

initBaseLoaderMethod · 0.95
getUserClassPathMethod · 0.95
putMethod · 0.95
classLoaderChangedMethod · 0.95
getClassSourceMethod · 0.80
insureInitializedMethod · 0.80
iteratorMethod · 0.80
hasNextMethod · 0.80
putMethod · 0.65
keySetMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected