Top Description Inners Fields Constructors Methods
org.codehaus.janino

public Class Compiler

extends AbstractCompiler
Class Inheritance
Imports
java.io.BufferedInputStream, .File, .IOException, .InputStream, .InputStreamReader, .OutputStream, java.lang.reflect.Array, java.net.URI, .URL, .URLConnection, java.nio.charset.Charset, java.util.ArrayList, .Arrays, .EnumSet, .List, .Set, java.util.logging.Level, .Logger, org.codehaus.commons.compiler.AbstractCompiler, .CompileException, .ICompiler, .InternalCompilerException, .Location, .WarningHandler, org.codehaus.commons.compiler.java9.java.lang.module.ModuleFinder, .ModuleReference, org.codehaus.commons.compiler.util.Benchmark, .StringPattern, .StringUtil, org.codehaus.commons.compiler.util.resource.DirectoryResourceFinder, .FileResource, .FileResourceCreator, .JarDirectoriesResourceFinder, .MultiResourceFinder, .PathResourceFinder, .Resource, .ResourceCreator, .ResourceFinder, org.codehaus.commons.nullanalysis.Nullable, org.codehaus.janino.UnitCompiler.ClassFileConsumer, org.codehaus.janino.util.ClassFile

JANINO implementation of ICompiler.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
Compiler.CompilerIClassLoader

A specialized IClassLoader that loads IClasses from the following sources:

  1. An already-parsed compilation unit
  2. A class file in the output directory (if existent and younger than source file)
  3. A source file in any of the source path directories
  4. The parent class loader

Field Summary

Modifier and TypeField and Description
private Benchmark
public static final StringPattern[]
private IClassLoader
private static final Logger
private EnumSet<JaninoOption>
private final List<UnitCompiler>
Inherited from org.codehaus.commons.compiler.AbstractCompiler:
bootClassPathclassFileCreatorclassFileFinderclassPathcompileErrorHandlerdebugLinesdebugSourcedebugVarsextensionDirectoriessourceCharsetsourceFindersourceVersiontargetVersionwarningHandler

Constructor Summary

AccessConstructor and Description
public
Compiler()

Initializes a new compiler.

public
Compiler(ResourceFinder sourceFinder, IClassLoader parentIClassLoader)

Deprecated Use Compiler() and the various configuration setters instead
public
Compiler(final File[] sourcePath, final File[] classPath, final File[] extDirs, final File[] bootClassPath, final File destinationDirectory, final String characterEncoding, boolean verbose, boolean debugSource, boolean debugLines, boolean debugVars, StringPattern[] warningHandlePatterns, boolean rebuild)

Deprecated Use Compiler() and the various configuration setters instead

Method Summary

Modifier and TypeMethod and Description
public void
compile(Resource[]
Contain the compilation units to compile
sourceResources
)

Implements org.codehaus.commons.compiler.ICompiler.compile.

See compile(File[]).
private void
compile2(Resource[] sourceResources)

public static File
getClassFile(String
E.g. "pkg1.pkg2.Outer$Inner"
className
,
File
E.g. "srcdir/Outer.java"
sourceFile
,
File
E.g. "destdir"
destinationDirectory
)

Constructs the name of a file that could store the byte code of the class with the given name.

private IClassLoader

Returns:

Loads "auxiliary classes", either through the IClassLoader that was explicitly set with setIClassLoader(IClassLoader), or otherwise from setBootClassPath(File[]), setExtensionDirectories(File[]) and setClassPath(File[])
getIClassLoader
()

private static <T> T[]
nullToEmptyArray(T[] a, Class<T> elementType)

public EnumSet<JaninoOption>

Returns:

A reference to the currently effective compilation options; changes to it take effect immediately
options
()

public Compiler
options(EnumSet<JaninoOption> options)

Sets the options for all future compilations.

private Java.AbstractCompilationUnit

Returns:

the parsed compilation unit
parseAbstractCompilationUnit
(String fileName, InputStream inputStream, Charset charset)

Reads one compilation unit from a file and parses it.

public void
setIClassLoader(IClassLoader iClassLoader)

Explicitly sets the IClassLoader that will be used to load "auxiliary classes".

public void
setVerbose(boolean verbose)

Implements org.codehaus.commons.compiler.ICompiler.setVerbose.

Equivalent of -verbose.
public void
storeClassFile(ClassFile classFile, final File
Required to compute class file path if no destination directory given
sourceFile
)

Stores the byte code of this ClassFile in the file system.

Inherited from org.codehaus.commons.compiler.AbstractCompiler:
compilesetBootClassPathsetCharacterEncodingsetClassFileCreatorsetClassFileFindersetClassFileFindersetClassPathsetCompileErrorHandlersetDebugLinessetDebugSourcesetDebugVarssetDestinationDirectorysetEncodingsetExtensionDirectoriessetSourceCharsetsetSourceFindersetSourcePathsetSourceVersionsetTargetVersionsetWarningHandler

Field Detail

benchmarkback to summary
private Benchmark benchmark
DEFAULT_WARNING_HANDLE_PATTERNSback to summary
public static final StringPattern[] DEFAULT_WARNING_HANDLE_PATTERNS

The default value for the warningHandlerPatterns parameter of Compiler#Compiler(File[], File[], File[], File[], File, String, boolean, boolean, boolean, boolean, StringPattern[], boolean).

iClassLoaderback to summary
private IClassLoader iClassLoader
Annotations
@Nullable
LOGGERback to summary
private static final Logger LOGGER
optionsback to summary
private EnumSet<JaninoOption> options
parsedCompilationUnitsback to summary
private final List<UnitCompiler> parsedCompilationUnits

Constructor Detail

Compilerback to summary
public Compiler()

Initializes a new compiler.

Compilerback to summary
public Compiler(ResourceFinder sourceFinder, IClassLoader parentIClassLoader)

Deprecated

Use Compiler() and the various configuration setters instead

Annotations
@Deprecated
Compilerback to summary
public Compiler(final File[] sourcePath, final File[] classPath, final File[] extDirs, final File[] bootClassPath, final File destinationDirectory, final String characterEncoding, boolean verbose, boolean debugSource, boolean debugLines, boolean debugVars, StringPattern[] warningHandlePatterns, boolean rebuild)

Deprecated

Use Compiler() and the various configuration setters instead

Annotations
@Deprecated

Method Detail

compileback to summary
public void compile(Resource[] sourceResources) throws CompileException, IOException

Implements org.codehaus.commons.compiler.ICompiler.compile.

Doc from org.codehaus.commons.compiler.ICompiler.compile.

See compile(File[]).

Parameters
sourceResources:Resource[]

Contain the compilation units to compile

Annotations
@Override
compile2back to summary
private void compile2(Resource[] sourceResources) throws CompileException, IOException
getClassFileback to summary
public static File getClassFile(String className, File sourceFile, File destinationDirectory)

Constructs the name of a file that could store the byte code of the class with the given name.

If destinationDirectory is non-null, the returned path is the destinationDirectory plus the package of the class (with dots replaced with file separators) plus the class name plus ".class". Example: "destdir/pkg1/pkg2/Outer$Inner.class"

If destinationDirectory is null, the returned path is the directory of the sourceFile plus the class name plus ".class". Example: "srcdir/Outer$Inner.class"

Parameters
className:String

E.g. "pkg1.pkg2.Outer$Inner"

sourceFile:File

E.g. "srcdir/Outer.java"

destinationDirectory:File

E.g. "destdir"

getIClassLoaderback to summary
private IClassLoader getIClassLoader()
Returns:IClassLoader

Loads "auxiliary classes", either through the IClassLoader that was explicitly set with setIClassLoader(IClassLoader), or otherwise from setBootClassPath(File[]), setExtensionDirectories(File[]) and setClassPath(File[])

nullToEmptyArrayback to summary
private static <T> T[] nullToEmptyArray(T[] a, Class<T> elementType)
Annotations
@SuppressWarnings:unchecked
optionsback to summary
public EnumSet<JaninoOption> options()
Returns:EnumSet<JaninoOption>

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

optionsback to summary
public Compiler options(EnumSet<JaninoOption> options)

Sets the options for all future compilations.

parseAbstractCompilationUnitback to summary
private Java.AbstractCompilationUnit parseAbstractCompilationUnit(String fileName, InputStream inputStream, Charset charset) throws CompileException, IOException

Reads one compilation unit from a file and parses it.

The inputStream is closed before the method returns.

Returns:Java.AbstractCompilationUnit

the parsed compilation unit

setIClassLoaderback to summary
public void setIClassLoader(IClassLoader iClassLoader)

Explicitly sets the IClassLoader that will be used to load "auxiliary classes". If this method is used, then setBootClassPath(File[]), setExtensionDirectories(File[]) and setClassPath(File[]) have no more effect.

setVerboseback to summary
public void setVerbose(boolean verbose)

Implements org.codehaus.commons.compiler.ICompiler.setVerbose.

Doc from org.codehaus.commons.compiler.ICompiler.setVerbose.

Equivalent of -verbose.

Annotations
@Override
storeClassFileback to summary
public void storeClassFile(ClassFile classFile, final File sourceFile) throws IOException

Stores the byte code of this ClassFile in the file system. Directories are created as necessary.

Parameters
sourceFile:File

Required to compute class file path if no destination directory given

org.codehaus.janino back to summary

private Class Compiler.CompilerIClassLoader

extends IClassLoader
Class Inheritance

A specialized IClassLoader that loads IClasses from the following sources:
  1. An already-parsed compilation unit
  2. A class file in the output directory (if existent and younger than source file)
  3. A source file in any of the source path directories
  4. The parent class loader

Notice that the CompilerIClassLoader is an inner class of Compiler and heavily uses Compiler's members.

Field Summary

Modifier and TypeField and Description
private final ResourceFinder
private final ResourceFinder
Inherited from org.codehaus.janino.IClassLoader:
CTOR_java_lang_StringBuilder__java_lang_StringMETH_java_lang_Enum__ordinalMETH_java_lang_Iterable__iteratorMETH_java_lang_String__concat__java_lang_StringMETH_java_lang_String__equals__java_lang_ObjectMETH_java_lang_String__hashCodeMETH_java_lang_String__valueOf__booleanMETH_java_lang_String__valueOf__charMETH_java_lang_String__valueOf__doubleMETH_java_lang_String__valueOf__floatMETH_java_lang_String__valueOf__intMETH_java_lang_String__valueOf__java_lang_ObjectMETH_java_lang_String__valueOf__longMETH_java_lang_StringBuilder__append__booleanMETH_java_lang_StringBuilder__append__charMETH_java_lang_StringBuilder__append__doubleMETH_java_lang_StringBuilder__append__floatMETH_java_lang_StringBuilder__append__intMETH_java_lang_StringBuilder__append__java_lang_ObjectMETH_java_lang_StringBuilder__append__java_lang_StringMETH_java_lang_StringBuilder__append__longMETH_java_lang_StringBuilder__toStringMETH_java_lang_Throwable__addSuppressedMETH_java_util_Iterator__hasNextMETH_java_util_Iterator__nextTYPE_java_io_SerializableTYPE_java_lang_annotation_RetentionTYPE_java_lang_AssertionErrorTYPE_java_lang_BooleanTYPE_java_lang_ByteTYPE_java_lang_CharacterTYPE_java_lang_ClassTYPE_java_lang_CloneableTYPE_java_lang_DoubleTYPE_java_lang_EnumTYPE_java_lang_ErrorTYPE_java_lang_ExceptionTYPE_java_lang_FloatTYPE_java_lang_IntegerTYPE_java_lang_IterableTYPE_java_lang_LongTYPE_java_lang_ObjectTYPE_java_lang_OverrideTYPE_java_lang_RuntimeExceptionTYPE_java_lang_ShortTYPE_java_lang_StringTYPE_java_lang_StringBuilderTYPE_java_lang_SystemTYPE_java_lang_ThrowableTYPE_java_lang_VoidTYPE_java_util_Iterator

Constructor Summary

AccessConstructor and Description
pack-priv
CompilerIClassLoader(ResourceFinder
Where to look for more source files
sourceFinder
,
ResourceFinder
Where to look for previously generated .class resources, or FIND_NEXT_TO_SOURCE_FILE
classFileFinder
,
IClassLoader
IClassLoader through which IClasses are to be loaded
parentIClassLoader
)

Method Summary

Modifier and TypeMethod and Description
private IClass
defineIClassFromClassFileResource(Resource classFileResource)

Opens the given classFileResource, reads its contents, defines it in the IClassLoader, and resolves it (this step may involve loading more classes).

private IClass
defineIClassFromSourceResource(Resource sourceResource, String className)

Parses the compilation unit stored in the given sourceResource, remembers it in Compiler.this.parsedCompilationUnits (it may declare other classes that are needed later), finds the declaration of the type with the given className, and defines it in the IClassLoader.

protected IClass

Returns:

null if a the type could not be found
findIClass
(final String
field descriptor of the IClass to load, e.g. "Lpkg1/pkg2/Outer$Inner;"
type
)

Implements abstract org.codehaus.janino.IClassLoader.findIClass.

Finds a new IClass by descriptor and calls defineIClass(IClass).
Inherited from org.codehaus.janino.IClassLoader:
createJavacLikePathIClassLoaderdefineIClassgetArrayIClassgetArrayIClassgetParentIClassLoaderloadIClasspostConstruct

Field Detail

classFileFinderback to summary
private final ResourceFinder classFileFinder
Annotations
@Nullable
sourceFinderback to summary
private final ResourceFinder sourceFinder

Constructor Detail

CompilerIClassLoaderback to summary
pack-priv CompilerIClassLoader(ResourceFinder sourceFinder, ResourceFinder classFileFinder, IClassLoader parentIClassLoader)
Parameters
sourceFinder:ResourceFinder

Where to look for more source files

classFileFinder:ResourceFinder

Where to look for previously generated .class resources, or FIND_NEXT_TO_SOURCE_FILE

parentIClassLoader:IClassLoader

IClassLoader through which IClasses are to be loaded

Method Detail

defineIClassFromClassFileResourceback to summary
private IClass defineIClassFromClassFileResource(Resource classFileResource) throws ClassNotFoundException

Opens the given classFileResource, reads its contents, defines it in the IClassLoader, and resolves it (this step may involve loading more classes).

defineIClassFromSourceResourceback to summary
private IClass defineIClassFromSourceResource(Resource sourceResource, String className) throws ClassNotFoundException

Parses the compilation unit stored in the given sourceResource, remembers it in Compiler.this.parsedCompilationUnits (it may declare other classes that are needed later), finds the declaration of the type with the given className, and defines it in the IClassLoader.

Notice that the compilation unit is not compiled here!

findIClassback to summary
protected IClass findIClass(final String type) throws ClassNotFoundException

Implements abstract org.codehaus.janino.IClassLoader.findIClass.

Doc from org.codehaus.janino.IClassLoader.findIClass.

Finds a new IClass by descriptor and calls defineIClass(IClass).

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

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.

Parameters
type:String

field descriptor of the IClass to load, e.g. "Lpkg1/pkg2/Outer$Inner;"

Returns:IClass

null if a the type could not be found

Annotations
@Override
@Nullable
Exceptions
ClassNotFoundException:
An exception was raised while loading the IClass