Package org.codehaus.janino

# Class JavaSourceClassLoader

java.lang.Object
java.lang.ClassLoader
org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
org.codehaus.janino.JavaSourceClassLoader

Direct Known Subclasses:
  `CachingJavaSourceClassLoader`

public class JavaSourceClassLoader extends AbstractJavaSourceClassLoader
A `ClassLoader` that, unlike usual `ClassLoader`s, does not load byte code, but reads Java source code and then scans, parses, compiles and loads it into the virtual machine.

As with any `ClassLoader`, it is not possible to "update" classes after they've been loaded. The way to achieve this is to give up on the `JavaSourceClassLoader` and create a new one.

Notice that this class loader does not support resoures in the sense of `ClassLoader.getResource(String)`, `ClassLoader.getResourceAsStream(String)` nd `ClassLoader.getResources(String)`.

See Also:
  - `ClassLoaders`

## Nested Class Summary

## Nested classes/interfaces inherited from class org.codehaus.commons.compiler.AbstractJavaSourceClassLoader

`AbstractJavaSourceClassLoader.ProtectionDomainFactory`

## Field Summary

### Fields inherited from class org.codehaus.commons.compiler.AbstractJavaSourceClassLoader

`protectionDomainFactory`

## Constructor Summary

Constructors
Constructor
Description
`JavaSourceClassLoader()`
`JavaSourceClassLoader(ClassLoader parentClassLoader)`
`JavaSourceClassLoader(ClassLoader parentClassLoader, File[] sourcePath, String characterEncoding)`
Sets up a `JavaSourceClassLoader` that finds Java source code in a file that resides in either of the directories specified by the given source path.
`JavaSourceClassLoader(ClassLoader parentClassLoader, ResourceFinder sourceFinder, String characterEncoding)`
Constructs a `JavaSourceClassLoader` that finds Java source code through a given `ResourceFinder`.
`JavaSourceClassLoader(ClassLoader parentClassLoader, JavaSourceIClassLoader iClassLoader)`
Constructs a `JavaSourceClassLoader` that finds classes through an `JavaSourceIClassLoader`.

## Method Summary

Modifier and Type
Method
Description
`protected Class<?>`
`findClass(String name)`
Implementation of `ClassLoader.findClass(String)`.
`protected Map<String,byte[]>`
`generateBytecodes(String name)`
Finds, scans, parses the right compilation unit.
`void`
`setCompileErrorHandler(ErrorHandler compileErrorHandler)`
`void`
`setDebuggingInfo(boolean debugSource, boolean debugLines, boolean debugVars)`
`void`
`setSourceCharset(Charset charset)`
`void`
`setSourceFinder(ResourceFinder sourceFinder)`
`void`
`setSourcePath(File[] sourcePath)`
`void`
`setTargetVersion(int version)`
`void`
`setWarningHandler(WarningHandler warningHandler)`

### Methods inherited from class org.codehaus.commons.compiler.AbstractJavaSourceClassLoader

`getResourceAsStream, main, setProtectionDomainFactory, setSourceFileCharacterEncoding`

### Methods inherited from class java.lang.ClassLoader

`clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### JavaSourceClassLoader

public JavaSourceClassLoader()

### JavaSourceClassLoader

public JavaSourceClassLoader(ClassLoader parentClassLoader)

### JavaSourceClassLoader

public JavaSourceClassLoader(ClassLoader parentClassLoader, @Nullable File[] sourcePath, @Nullable String characterEncoding)
Sets up a `JavaSourceClassLoader` that finds Java source code in a file that resides in either of the directories specified by the given source path.

Parameters:
  `parentClassLoader` - See `ClassLoader`
  `sourcePath` - A collection of directories that are searched for Java source files in the given order
  `characterEncoding` - The encoding of the Java source files (`null` for platform default encoding)

### JavaSourceClassLoader

public JavaSourceClassLoader(ClassLoader parentClassLoader, ResourceFinder sourceFinder, @Nullable String characterEncoding)
Constructs a `JavaSourceClassLoader` that finds Java source code through a given `ResourceFinder`.

You can specify to include certain debugging information in the generated class files, which is useful if you want to debug through the generated classes (see `Scanner(String, Reader)`).

Parameters:
  `parentClassLoader` - See `ClassLoader`
  `sourceFinder` - Used to locate additional source files
  `characterEncoding` - The encoding of the Java source files (`null` for platform default encoding)

### JavaSourceClassLoader

public JavaSourceClassLoader(ClassLoader parentClassLoader, JavaSourceIClassLoader iClassLoader)
Constructs a `JavaSourceClassLoader` that finds classes through an `JavaSourceIClassLoader`.

## Method Details

### setSourcePath

public void setSourcePath(File[] sourcePath)

Specified by:
  `setSourcePath` in class `AbstractJavaSourceClassLoader`
Parameters:
  `sourcePath` - The sequence of directories to search for Java source files

### setSourceFinder

public void setSourceFinder(ResourceFinder sourceFinder)

Specified by:
  `setSourceFinder` in class `AbstractJavaSourceClassLoader`
Parameters:
  `sourceFinder` - Is used when searching for Java source files

### setSourceCharset

public void setSourceCharset(Charset charset)

Specified by:
  `setSourceCharset` in class `AbstractJavaSourceClassLoader`
Parameters:
  `charset` - The character set to using when reading characters from a source file

### setDebuggingInfo

public void setDebuggingInfo(boolean debugSource, boolean debugLines, boolean debugVars)

Specified by:
  `setDebuggingInfo` in class `AbstractJavaSourceClassLoader`
Parameters:
  `debugSource` - Whether line number debugging information should be generated
  `debugLines` - Whether variables debugging information should be generated
  `debugVars` - Whether source file debugging information should be generated

### setTargetVersion

public void setTargetVersion(int version)

### setCompileErrorHandler

public void setCompileErrorHandler(@Nullable ErrorHandler compileErrorHandler)

See Also:
  - `UnitCompiler.setCompileErrorHandler(org.codehaus.commons.compiler.ErrorHandler)`

### setWarningHandler

public void setWarningHandler(@Nullable WarningHandler warningHandler)

See Also:
  - `Parser.setWarningHandler(WarningHandler)`
  - `UnitCompiler.setCompileErrorHandler(org.codehaus.commons.compiler.ErrorHandler)`

### findClass

protected Class<?> findClass(@Nullable String name) throws ClassNotFoundException
Implementation of `ClassLoader.findClass(String)`.

Overrides:
  `findClass` in class `ClassLoader`
Throws:
  `ClassNotFoundException`

### generateBytecodes

@Nullable protected Map<String,byte[]> generateBytecodes(String name) throws ClassNotFoundException
Finds, scans, parses the right compilation unit. Compile the parsed compilation unit to bytecode. This may cause more compilation units being scanned and parsed. Continue until all compilation units are compiled.

Returns:
  String name => byte[] bytecode, or `null` if no source code could be found
Throws:
  `ClassNotFoundException` - on compilation problems