Class Compiler
java.lang.Object
org.codehaus.commons.compiler.AbstractCompiler
org.codehaus.janino.Compiler
- All Implemented Interfaces:
ICompiler
JANINO implementation of
ICompiler.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classA 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
FieldsModifier and TypeFieldDescriptionprivate Benchmarkstatic final StringPattern[]The default value for the warningHandlerPatterns parameter ofCompiler(File[], File[], File[], File[], File, String, boolean, boolean, boolean, boolean, StringPattern[], boolean).private IClassLoaderprivate static final Loggerprivate EnumSet<JaninoOption> private final List<UnitCompiler> Fields inherited from class AbstractCompiler
bootClassPath, classFileCreator, classFileFinder, classPath, compileErrorHandler, debugLines, debugSource, debugVars, extensionDirectories, sourceCharset, sourceFinder, sourceVersion, targetVersion, warningHandlerFields inherited from interface ICompiler
CREATE_NEXT_TO_SOURCE_FILE, FIND_NEXT_TO_SOURCE_FILE, NO_DESTINATION_DIRECTORY -
Constructor Summary
ConstructorsConstructorDescriptionCompiler()Initializes a new compiler.Compiler(File[] sourcePath, File[] classPath, File[] extDirs, File[] bootClassPath, File destinationDirectory, String characterEncoding, boolean verbose, boolean debugSource, boolean debugLines, boolean debugVars, StringPattern[] warningHandlePatterns, boolean rebuild) Deprecated.Compiler(ResourceFinder sourceFinder, IClassLoader parentIClassLoader) Deprecated.UseCompiler()and the various configuration setters instead -
Method Summary
Modifier and TypeMethodDescriptionvoidprivate voidstatic FilegetClassFile(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.private IClassLoaderprivate static <T> T[]nullToEmptyArray(T[] a, Class<T> elementType) options()options(EnumSet<JaninoOption> options) Sets the options for all future compilations.private Java.AbstractCompilationUnitparseAbstractCompilationUnit(String fileName, InputStream inputStream, 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, File sourceFile) Stores the byte code of thisClassFilein the file system.Methods inherited from class AbstractCompiler
compile, setBootClassPath, setCharacterEncoding, setClassFileCreator, setClassFileFinder, setClassFileFinder, setClassPath, setCompileErrorHandler, setDebugLines, setDebugSource, setDebugVars, setDestinationDirectory, setEncoding, setExtensionDirectories, setSourceCharset, setSourceFinder, setSourcePath, setSourceVersion, setTargetVersion, setWarningHandler
-
Field Details
-
LOGGER
-
options
-
iClassLoader
-
benchmark
-
parsedCompilationUnits
-
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 Details
-
Compiler
public Compiler()Initializes a new compiler. -
Compiler
Deprecated.UseCompiler()and the various configuration setters instead -
Compiler
@Deprecated public Compiler(File[] sourcePath, File[] classPath, @Nullable File[] extDirs, @Nullable File[] bootClassPath, @Nullable File destinationDirectory, @Nullable String characterEncoding, boolean verbose, boolean debugSource, boolean debugLines, boolean debugVars, StringPattern[] warningHandlePatterns, boolean rebuild) Deprecated.UseCompiler()and the various configuration setters instead
-
-
Method Details
-
nullToEmptyArray
-
options
- Returns:
- A reference to the currently effective compilation options; changes to it take effect immediately
-
options
Sets the options for all future compilations. -
compile
Description copied from interface:ICompiler- Parameters:
sourceResources- Contain the compilation units to compile- Throws:
CompileExceptionIOException
-
compile2
- Throws:
CompileExceptionIOException
-
parseAbstractCompilationUnit
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:
- the parsed compilation unit
- Throws:
CompileExceptionIOException
-
getClassFile
public static File getClassFile(String className, File sourceFile, @Nullable 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
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:
IOException
-
setIClassLoader
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
- Returns:
- Loads "auxiliary classes", either through the
IClassLoaderthat was explicitly set withsetIClassLoader(IClassLoader), or otherwise fromAbstractCompiler.setBootClassPath(File[]),AbstractCompiler.setExtensionDirectories(File[])andAbstractCompiler.setClassPath(File[])
-
Compiler()and the various configuration setters instead