Class SimpleCompiler
- java.lang.Object
-
- org.codehaus.commons.compiler.Cookable
-
- org.codehaus.commons.compiler.jdk.SimpleCompiler
-
- All Implemented Interfaces:
ICookable,ISimpleCompiler
public class SimpleCompiler extends Cookable implements ISimpleCompiler
The JDK-based implementation ofISimpleCompiler.
-
-
Constructor Summary
Constructors Constructor Description SimpleCompiler()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddOffset(String fileName)Derived classes call this method to "reset" the current line and column number at the currently read input character, and also changes the "file name" (seecook(String, Reader)).voidcook(String fileName, Reader r)Reads, scans, parses and compiles Java tokens from the givenReader.Map<String,byte[]>getBytecodes()ClassLoadergetClassLoader()Returns aClassLoaderobject through which the previously compiled classes can be accessed.voidsetCompileErrorHandler(ErrorHandler compileErrorHandler)By default,CompileExceptions are thrown on compile errors, but an application my install its ownErrorHandler.voidsetDebuggingInformation(boolean debugSource, boolean debugLines, boolean debugVars)Determines what kind of debugging information is included in the generates classes.voidsetParentClassLoader(ClassLoader parentClassLoader)The "parent class loader" is used to load referenced classes.voidsetParentClassLoader(ClassLoader parentClassLoader, Class<?>[] auxiliaryClasses)Deprecated.Auxiliary classes never really worked...voidsetSourceVersion(int version)Specifies the version of source code accepted, in analogy with JAVAC's-sourcecommand line option.voidsetTargetVersion(int version)Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's-targetcommand line option.voidsetWarningHandler(WarningHandler warningHandler)By default, warnings are discarded, but an application my install a customWarningHandler.-
Methods inherited from class org.codehaus.commons.compiler.Cookable
cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile
-
-
-
-
Method Detail
-
setSourceVersion
public void setSourceVersion(int version)
Description copied from interface:ICookableSpecifies the version of source code accepted, in analogy with JAVAC's-sourcecommand line option. May be ignored by an implementation (e.g. thejaninoimplementation always accepts the language features as described on the home page). Allowed values, and the default value, depend on the implementation.-1means to use a default version.- Specified by:
setSourceVersionin interfaceICookable
-
setTargetVersion
public void setTargetVersion(int version)
Description copied from interface:ICookableGenerates class files that target a specified release of the virtual machine, in analogy with JAVAC's-targetcommand line option. Allowed values depend on the implementation. The default value also depends on the implementation. The only invariant is that the generated class files are suitable for the currently executing JVM.-1means to use a default version.- Specified by:
setTargetVersionin interfaceICookable
-
getBytecodes
public Map<String,byte[]> getBytecodes()
- Specified by:
getBytecodesin interfaceICookable- Returns:
- The generated Java bytecode; maps class name to bytes
-
getClassLoader
public ClassLoader getClassLoader()
Description copied from interface:ISimpleCompilerReturns aClassLoaderobject through which the previously compiled classes can be accessed. ThisClassLoadercan be used for subsequentISimpleCompilers in order to compile compilation units that use types (e.g. declare derived types) declared in the previous one.This method must only be called after exactly one of the
ICookable.cook(String, java.io.Reader)methods was called.- Specified by:
getClassLoaderin interfaceISimpleCompiler
-
cook
public void cook(@Nullable String fileName, Reader r) throws CompileException, IOException
Description copied from interface:ICookableReads, scans, parses and compiles Java tokens from the givenReader.- Specified by:
cookin interfaceICookable- Specified by:
cookin classCookable- Parameters:
fileName- Used when reporting errors and warnings- Throws:
CompileExceptionIOException
-
setDebuggingInformation
public void setDebuggingInformation(boolean debugSource, boolean debugLines, boolean debugVars)Description copied from interface:ISimpleCompilerDetermines what kind of debugging information is included in the generates classes. The default is typically "-g:none".- Specified by:
setDebuggingInformationin interfaceISimpleCompiler
-
setParentClassLoader
public void setParentClassLoader(@Nullable ClassLoader parentClassLoader)
Description copied from interface:ISimpleCompilerThe "parent class loader" is used to load referenced classes. Useful values are:System.getSystemClassLoader()The running JVM's class path Thread.currentThread().getContextClassLoader()ornullThe class loader effective for the invoking thread ClassLoaders.BOOTCLASSPATH_CLASS_LOADERThe running JVM's boot class path The parent class loader defaults to the current thread's context class loader.
- Specified by:
setParentClassLoaderin interfaceISimpleCompiler
-
setParentClassLoader
@Deprecated public void setParentClassLoader(@Nullable ClassLoader parentClassLoader, Class<?>[] auxiliaryClasses)
Deprecated.Auxiliary classes never really worked... don't use them.
-
setCompileErrorHandler
public void setCompileErrorHandler(@Nullable ErrorHandler compileErrorHandler)
Description copied from interface:ISimpleCompilerBy default,CompileExceptions are thrown on compile errors, but an application my install its ownErrorHandler.Be aware that a single problem during compilation often causes a bunch of compile errors, so a good
ErrorHandlercounts errors and throws aCompileExceptionwhen a limit is reached.If the given
ErrorHandlerthrowsCompileExceptions, then the compilation is terminated and the exception is propagated.If the given
ErrorHandlerdoes not throwCompileExceptions, then the compiler may or may not continue compilation, but must eventually throw aCompileException.In other words: The
ErrorHandlermay throw aCompileExceptionor not, but the compiler must definitely throw aCompileExceptionif one or more compile errors have occurred.- Specified by:
setCompileErrorHandlerin interfaceISimpleCompiler- Parameters:
compileErrorHandler-nullto restore the default behavior (throwing aCompileException
-
setWarningHandler
public void setWarningHandler(@Nullable WarningHandler warningHandler)
Description copied from interface:ISimpleCompilerBy default, warnings are discarded, but an application my install a customWarningHandler.- Specified by:
setWarningHandlerin interfaceISimpleCompiler- Parameters:
warningHandler-nullto indicate that no warnings be issued
-
addOffset
protected void addOffset(@Nullable String fileName)
Derived classes call this method to "reset" the current line and column number at the currently read input character, and also changes the "file name" (seecook(String, Reader)).
-
-