Package org.codehaus.janino

# Class JavaSourceIClassLoader

java.lang.Object
org.codehaus.janino.IClassLoader
org.codehaus.janino.JavaSourceIClassLoader

public class JavaSourceIClassLoader extends IClassLoader
This `IClassLoader` finds, scans and parses compilation units.

Notice that it does not compile them!

## Field Summary

### Fields inherited from class org.codehaus.janino.IClassLoader

`CTOR_java_lang_StringBuilder__java_lang_String, METH_java_lang_Enum__ordinal, METH_java_lang_Iterable__iterator, METH_java_lang_String__concat__java_lang_String, METH_java_lang_String__equals__java_lang_Object, METH_java_lang_String__hashCode, METH_java_lang_String__valueOf__boolean, METH_java_lang_String__valueOf__char, METH_java_lang_String__valueOf__double, METH_java_lang_String__valueOf__float, METH_java_lang_String__valueOf__int, METH_java_lang_String__valueOf__java_lang_Object, METH_java_lang_String__valueOf__long, METH_java_lang_StringBuilder__append__boolean, METH_java_lang_StringBuilder__append__char, METH_java_lang_StringBuilder__append__double, METH_java_lang_StringBuilder__append__float, METH_java_lang_StringBuilder__append__int, METH_java_lang_StringBuilder__append__java_lang_Object, METH_java_lang_StringBuilder__append__java_lang_String, METH_java_lang_StringBuilder__append__long, METH_java_lang_StringBuilder__toString, METH_java_lang_Throwable__addSuppressed, METH_java_util_Iterator__hasNext, METH_java_util_Iterator__next, TYPE_java_io_Serializable, TYPE_java_lang_annotation_Retention, TYPE_java_lang_AssertionError, TYPE_java_lang_Boolean, TYPE_java_lang_Byte, TYPE_java_lang_Character, TYPE_java_lang_Class, TYPE_java_lang_Cloneable, TYPE_java_lang_Double, TYPE_java_lang_Enum, TYPE_java_lang_Error, TYPE_java_lang_Exception, TYPE_java_lang_Float, TYPE_java_lang_Integer, TYPE_java_lang_Iterable, TYPE_java_lang_Long, TYPE_java_lang_Object, TYPE_java_lang_Override, TYPE_java_lang_RuntimeException, TYPE_java_lang_Short, TYPE_java_lang_String, TYPE_java_lang_StringBuilder, TYPE_java_lang_System, TYPE_java_lang_Throwable, TYPE_java_lang_Void, TYPE_java_util_Iterator`

## Constructor Summary

Constructors
Constructor
Description
`JavaSourceIClassLoader(ResourceFinder sourceFinder, String sourceCharsetName, IClassLoader parentIClassLoader)`

## Method Summary

Modifier and Type
Method
Description
`protected Java.AbstractCompilationUnit`
`findCompilationUnit(String className)`
Finds the Java source file for the named class through the configured 'source resource finder' and parses it.
`IClass`
`findIClass(String fieldDescriptor)`
Finds a new `IClass` by descriptor and calls `IClassLoader.defineIClass(IClass)`.
`ResourceFinder`
`getSourceFinder()`
`Set<UnitCompiler>`
`getUnitCompilers()`
Returns the set of `UnitCompiler`s that were created so far.
`EnumSet<JaninoOption>`
`options()`
`JavaSourceIClassLoader`
`options(EnumSet<JaninoOption> options)`
Sets the options for all future compilations.
`void`
`setCharacterEncoding(String sourceCharsetName)`
Deprecated.
Use `setSourceCharset(Charset)` instead
`void`
`setCompileErrorHandler(ErrorHandler compileErrorHandler)`
`void`
`setSourceCharset(Charset sourceCharset)`
`void`
`setSourceFinder(ResourceFinder sourceFinder)`
`void`
`setSourceVersion(int version)`
`void`
`setTargetVersion(int version)`
`void`
`setWarningHandler(WarningHandler warningHandler)`

### Methods inherited from class org.codehaus.janino.IClassLoader

`createJavacLikePathIClassLoader, defineIClass, getArrayIClass, getArrayIClass, getParentIClassLoader, loadIClass, postConstruct`

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

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

## Constructor Details

### JavaSourceIClassLoader

public JavaSourceIClassLoader(ResourceFinder sourceFinder, @Nullable String sourceCharsetName, @Nullable IClassLoader parentIClassLoader)

## Method Details

### setSourceVersion

public void setSourceVersion(int version)

### setTargetVersion

public void setTargetVersion(int version)

### getUnitCompilers

public Set<UnitCompiler> getUnitCompilers()
Returns the set of `UnitCompiler`s that were created so far.

### setSourceFinder

public void setSourceFinder(ResourceFinder sourceFinder)

Parameters:
  `sourceFinder` - The source path

### getSourceFinder

public ResourceFinder getSourceFinder()

### setCharacterEncoding

@Deprecated public void setCharacterEncoding(@Nullable String sourceCharsetName)
Deprecated.
Use `setSourceCharset(Charset)` instead

### setSourceCharset

public void setSourceCharset(Charset sourceCharset)

Parameters:
  `sourceCharset` - The charset that is used to read source files

### setCompileErrorHandler

public void setCompileErrorHandler(@Nullable ErrorHandler compileErrorHandler)

See Also:
  - `UnitCompiler.setCompileErrorHandler(ErrorHandler)`

### setWarningHandler

public void setWarningHandler(@Nullable WarningHandler warningHandler)

See Also:
  - `Parser.setWarningHandler(WarningHandler)`
  - `UnitCompiler.setCompileErrorHandler(ErrorHandler)`

### options

public EnumSet<JaninoOption> options()

Returns:
  A reference to the currently effective compilation options; changes to it take effect immediately

### options

public JavaSourceIClassLoader options(EnumSet<JaninoOption> options)
Sets the options for all future compilations.

### findIClass

@Nullable public IClass findIClass(String fieldDescriptor) throws ClassNotFoundException
Description copied from class: `IClassLoader`
Finds a new `IClass` by descriptor and calls `IClassLoader.defineIClass(IClass)`.

Similar `ClassLoader.findClass(java.lang.String)`, this method must

- Get an `IClass` object from somewhere for the given type
- Call `IClassLoader.defineIClass(IClass)` with that `IClass` object as the argument
- Return the `IClass` object

The format of a `descriptor` is defined in JVMS 4.3.2. Typical descriptors are:

- `I` (Integer)
- `Lpkg1/pkg2/Clazz;` (Class declared in package)
- `Lpkg1/pkg2/Outer$Inner;` Member class

Notice that this method is never called for array types.

Notice that this method is never called from more than one thread at a time. In other words, implementations of this method need not be thread-safe.

Specified by:
  `findIClass` in class `IClassLoader`
Parameters:
  `fieldDescriptor` - Field descriptor of the `IClass` to load, e.g. "Lpkg1/pkg2/Outer$Inner;"
Returns:
  `null` if a class with that descriptor could not be found
Throws:
  `ClassNotFoundException` - An exception was raised while loading the `IClass`

### findCompilationUnit

@Nullable protected Java.AbstractCompilationUnit findCompilationUnit(String className) throws IOException, CompileException
Finds the Java source file for the named class through the configured 'source resource finder' and parses it.

Returns:
  `null` iff the source file could not be found
Throws:
  `IOException`
  `CompileException`