Package ortus.boxlang.compiler
Class Boxpiler
java.lang.Object
ortus.boxlang.compiler.Boxpiler
- All Implemented Interfaces:
IBoxpiler
- Direct Known Subclasses:
ASMBoxpiler,JavaBoxpiler
The `Boxpiler` class serves as an abstract base implementation of the `IBoxpiler` interface,
providing core functionality for compiling BoxLang source code into Java classes. It handles
parsing, validation, and compilation of BoxLang scripts, statements, templates, and classes.
This class manages class pools for compiled classes, supports caching mechanisms, and ensures
that generated classes are stored in a specified directory. It also integrates with the
`BoxRuntime` environment for logging, configuration, and transaction management.
Key features include:
- Parsing BoxLang source code into Abstract Syntax Tree (AST) nodes.
- Compiling BoxLang source code into Java classes for execution.
- Managing class pools for efficient reuse of compiled classes.
- Supporting debug mode to clean up generated class directories on startup.
- Handling interface proxies for dynamic runtime behavior.
- Providing source map information for debugging and error reporting.
This class is designed to be extended by concrete implementations that provide additional
functionality or customization for specific use cases.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PathThe directory where the generated classes are storedKeeps track of the classes we've compiledprotected DiskClassUtilThe disk class utilprotected FRTransServiceThe transaction service used to track subtransactionsprotected static final org.slf4j.LoggerLogger Instanceprotected BoxRuntimeThe BoxRuntime instanceFields inherited from interface ortus.boxlang.compiler.IBoxpiler
FQNBasePattern, RESERVED_WORDS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClear page poolscompileClass(String source, BoxSourceType type) Compile a BoxLang Class from source into a Java classcompileClass(ResolvedFilePath resolvedFilePath) Compile a BoxLang Class from a file into a Java classcompileInterfaceProxy(IBoxContext context, InterfaceProxyDefinition definition) compileScript(String source, BoxSourceType type) Compile a BoxLang script into a Java classcompileStatement(String source, BoxSourceType type) Compile a single BoxLang statement into a Java classcompileTemplate(ResolvedFilePath resolvedFilePath) Compile a BoxLang template (file on disk) into a Java classgetClassPool(String classPoolName) Get a class pool by nameGet all class poolsParse a file on disk into BoxLang AST nodes.parse(String source, BoxSourceType type, Boolean classOrInterface) Parse source text into BoxLang AST nodes.parseOrFail(File file) Parse a file on disk into BoxLang AST nodes.parseOrFail(String source, BoxSourceType type, Boolean classOrInterface) Parse source text into BoxLang AST nodes.validateParse(ParsingResult result, String source) Validate a parsing result and throw an exception if the parse failed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ortus.boxlang.compiler.IBoxpiler
compileClassInfo, compileTemplateBytes, printTranspiledCode
-
Field Details
-
logger
protected static final org.slf4j.Logger loggerLogger Instance -
classPools
Keeps track of the classes we've compiled -
frTransService
The transaction service used to track subtransactions -
diskClassUtil
The disk class util -
classGenerationDirectory
The directory where the generated classes are stored -
runtime
The BoxRuntime instance
-
-
Constructor Details
-
Boxpiler
public Boxpiler()The constructor for the Boxpiler class. It initializes the class generation directory and sets up the disk class utility. If in debug mode, it cleans out the class generation directory on startup.
-
-
Method Details
-
getClassPool
Get a class pool by name- Specified by:
getClassPoolin interfaceIBoxpiler- Parameters:
classPoolName- The name of the class pool- Returns:
- The class pool
-
getClassPools
Get all class pools- Returns:
- A map of class pools
-
clearPagePool
public void clearPagePool()Clear page pools- Specified by:
clearPagePoolin interfaceIBoxpiler
-
parse
Parse source text into BoxLang AST nodes. This method will NOT throw an exception if the parse fails. -
parseOrFail
Parse a file on disk into BoxLang AST nodes. This method will throw an exception if the parse fails.- Specified by:
parseOrFailin interfaceIBoxpiler- Parameters:
file- The file to parse- Returns:
- The parsed AST nodes and any issues if encountered while parsing.
-
parse
Parse a file on disk into BoxLang AST nodes. This method will NOT throw an exception if the parse fails. -
parseOrFail
Parse source text into BoxLang AST nodes. This method will throw an exception if the parse fails.- Specified by:
parseOrFailin interfaceIBoxpiler- Parameters:
source- The source to parse.type- The BoxSourceType of the source.- Returns:
- The parsed AST nodes and any issues if encountered while parsing.
-
validateParse
Validate a parsing result and throw an exception if the parse failed.- Specified by:
validateParsein interfaceIBoxpiler- Parameters:
result- The parsing result to validate- Returns:
- The parsing result if the parse was successful
-
compileStatement
Compile a single BoxLang statement into a Java class- Specified by:
compileStatementin interfaceIBoxpiler- Parameters:
source- The BoxLang source code as a stringtype- The type of BoxLang source code- Returns:
- The loaded class
-
compileScript
Compile a BoxLang script into a Java class- Specified by:
compileScriptin interfaceIBoxpiler- Parameters:
source- The BoxLang source code as a stringtype- The type of BoxLang source code- Returns:
- The loaded class
-
compileTemplate
Compile a BoxLang template (file on disk) into a Java class- Specified by:
compileTemplatein interfaceIBoxpiler- Parameters:
resolvedFilePath- The BoxLang source code as a Path on disk- Returns:
- The loaded class
-
compileClass
Compile a BoxLang Class from source into a Java class- Specified by:
compileClassin interfaceIBoxpiler- Parameters:
source- The BoxLang source code as a string- Returns:
- The loaded class
-
compileClass
Compile a BoxLang Class from a file into a Java class- Specified by:
compileClassin interfaceIBoxpiler- Parameters:
resolvedFilePath- The BoxLang source code as a Path on disk- Returns:
- The loaded class
-
compileInterfaceProxy
public Class<IProxyRunnable> compileInterfaceProxy(IBoxContext context, InterfaceProxyDefinition definition) - Specified by:
compileInterfaceProxyin interfaceIBoxpiler
-
getSourceMapFromFQN
- Specified by:
getSourceMapFromFQNin interfaceIBoxpiler
-