Package org.codehaus.janino
Class Compiler
- java.lang.Object
-
- org.codehaus.commons.compiler.AbstractCompiler
-
- org.codehaus.janino.Compiler
-
- All Implemented Interfaces:
ICompiler
public class Compiler extends AbstractCompiler
JANINO implementation ofICompiler.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classCompiler.CompilerIClassLoaderA specializedIClassLoaderthat loadsIClasses from the following sources: An already-parsed compilation unit A class file in the output directory (if existent and younger than source file) A source file in any of the source path directories The parent class loader
-
Field Summary
Fields Modifier and Type Field Description private Benchmarkbenchmarkstatic StringPattern[]DEFAULT_WARNING_HANDLE_PATTERNSThe default value for the warningHandlerPatterns parameter ofCompiler(File[], File[], File[], File[], File, String, boolean, boolean, boolean, boolean, StringPattern[], boolean).private IClassLoaderiClassLoaderprivate static java.util.logging.LoggerLOGGERprivate java.util.EnumSet<JaninoOption>optionsprivate java.util.List<UnitCompiler>parsedCompilationUnits-
Fields inherited from class org.codehaus.commons.compiler.AbstractCompiler
bootClassPath, classFileCreator, classFileFinder, classPath, compileErrorHandler, debugLines, debugSource, debugVars, extensionDirectories, sourceCharset, sourceFinder, sourceVersion, targetVersion, warningHandler
-
Fields inherited from interface org.codehaus.commons.compiler.ICompiler
CREATE_NEXT_TO_SOURCE_FILE, FIND_NEXT_TO_SOURCE_FILE, NO_DESTINATION_DIRECTORY
-
-
Constructor Summary
Constructors Constructor Description Compiler()Initializes a new compiler.Compiler(java.io.File[] sourcePath, java.io.File[] classPath, java.io.File[] extDirs, java.io.File[] bootClassPath, java.io.File destinationDirectory, java.lang.String characterEncoding, boolean verbose, boolean debugSource, boolean debugLines, boolean debugVars, StringPattern[] warningHandlePatterns, boolean rebuild)Deprecated.UseCompiler()and the various configuration setters insteadCompiler(ResourceFinder sourceFinder, IClassLoader parentIClassLoader)Deprecated.UseCompiler()and the various configuration setters instead
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcompile(Resource[] sourceResources)private voidcompile2(Resource[] sourceResources)static java.io.FilegetClassFile(java.lang.String className, java.io.File sourceFile, java.io.File destinationDirectory)Constructs the name of a file that could store the byte code of the class with the given name.private IClassLoadergetIClassLoader()private static <T> T[]nullToEmptyArray(T[] a, java.lang.Class<T> elementType)java.util.EnumSet<JaninoOption>options()Compileroptions(java.util.EnumSet<JaninoOption> options)Sets the options for all future compilations.private Java.AbstractCompilationUnitparseAbstractCompilationUnit(java.lang.String fileName, java.io.InputStream inputStream, java.nio.charset.Charset charset)Reads one compilation unit from a file and parses it.voidsetIClassLoader(IClassLoader iClassLoader)Explicitly sets theIClassLoaderthat will be used to load "auxiliary classes".voidsetVerbose(boolean verbose)Equivalent of-verbose.voidstoreClassFile(ClassFile classFile, java.io.File sourceFile)Stores the byte code of thisClassFilein the file system.-
Methods inherited from class org.codehaus.commons.compiler.AbstractCompiler
compile, setBootClassPath, setCharacterEncoding, setClassFileCreator, setClassFileFinder, setClassFileFinder, setClassPath, setCompileErrorHandler, setDebugLines, setDebugSource, setDebugVars, setDestinationDirectory, setEncoding, setExtensionDirectories, setSourceCharset, setSourceFinder, setSourcePath, setSourceVersion, setTargetVersion, setWarningHandler
-
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
options
private java.util.EnumSet<JaninoOption> options
-
iClassLoader
@Nullable private IClassLoader iClassLoader
-
benchmark
private Benchmark benchmark
-
parsedCompilationUnits
private final java.util.List<UnitCompiler> parsedCompilationUnits
-
DEFAULT_WARNING_HANDLE_PATTERNS
public static final StringPattern[] DEFAULT_WARNING_HANDLE_PATTERNS
The default value for the warningHandlerPatterns parameter ofCompiler(File[], File[], File[], File[], File, String, boolean, boolean, boolean, boolean, StringPattern[], boolean).
-
-
Constructor Detail
-
Compiler
public Compiler()
Initializes a new compiler.
-
Compiler
@Deprecated public Compiler(ResourceFinder sourceFinder, IClassLoader parentIClassLoader)
Deprecated.UseCompiler()and the various configuration setters instead
-
Compiler
@Deprecated public Compiler(java.io.File[] sourcePath, java.io.File[] classPath, @Nullable java.io.File[] extDirs, @Nullable java.io.File[] bootClassPath, @Nullable java.io.File destinationDirectory, @Nullable java.lang.String characterEncoding, boolean verbose, boolean debugSource, boolean debugLines, boolean debugVars, StringPattern[] warningHandlePatterns, boolean rebuild)Deprecated.UseCompiler()and the various configuration setters instead
-
-
Method Detail
-
nullToEmptyArray
private static <T> T[] nullToEmptyArray(@Nullable T[] a, java.lang.Class<T> elementType)
-
options
public java.util.EnumSet<JaninoOption> options()
- Returns:
- A reference to the currently effective compilation options; changes to it take effect immediately
-
options
public Compiler options(java.util.EnumSet<JaninoOption> options)
Sets the options for all future compilations.
-
compile
public void compile(Resource[] sourceResources) throws CompileException, java.io.IOException
Description copied from interface:ICompiler- Parameters:
sourceResources- Contain the compilation units to compile- Throws:
CompileExceptionjava.io.IOException
-
compile2
private void compile2(Resource[] sourceResources) throws CompileException, java.io.IOException
- Throws:
CompileExceptionjava.io.IOException
-
parseAbstractCompilationUnit
private Java.AbstractCompilationUnit parseAbstractCompilationUnit(java.lang.String fileName, java.io.InputStream inputStream, java.nio.charset.Charset charset) throws CompileException, java.io.IOException
Reads one compilation unit from a file and parses it.The inputStream is closed before the method returns.
- Returns:
- the parsed compilation unit
- Throws:
CompileExceptionjava.io.IOException
-
getClassFile
public static java.io.File getClassFile(java.lang.String className, java.io.File sourceFile, @Nullable java.io.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- E.g."pkg1.pkg2.Outer$Inner"sourceFile- E.g."srcdir/Outer.java"destinationDirectory- E.g."destdir"
-
storeClassFile
public void storeClassFile(ClassFile classFile, java.io.File sourceFile) throws java.io.IOException
Stores the byte code of thisClassFilein the file system. Directories are created as necessary.- Parameters:
classFile-sourceFile- Required to compute class file path if no destination directory given- Throws:
java.io.IOException
-
setIClassLoader
public void setIClassLoader(IClassLoader iClassLoader)
Explicitly sets theIClassLoaderthat will be used to load "auxiliary classes". If this method is used, thenAbstractCompiler.setBootClassPath(File[]),AbstractCompiler.setExtensionDirectories(File[])andAbstractCompiler.setClassPath(File[])have no more effect.
-
setVerbose
public void setVerbose(boolean verbose)
Description copied from interface:ICompilerEquivalent of-verbose.
-
getIClassLoader
private IClassLoader getIClassLoader()
- Returns:
- Loads "auxiliary classes", either through the
IClassLoaderthat was explicitly set withsetIClassLoader(IClassLoader), or otherwise fromAbstractCompiler.setBootClassPath(File[]),AbstractCompiler.setExtensionDirectories(File[])andAbstractCompiler.setClassPath(File[])
-
-