Class Boxpiler

java.lang.Object
ortus.boxlang.compiler.Boxpiler
All Implemented Interfaces:
IBoxpiler
Direct Known Subclasses:
ASMBoxpiler, JavaBoxpiler

public abstract class Boxpiler extends Object implements IBoxpiler
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 Details

    • logger

      protected static final org.slf4j.Logger logger
      Logger Instance
    • classPools

      protected Map<String,Map<String,ClassInfo>> classPools
      Keeps track of the classes we've compiled
    • frTransService

      protected FRTransService frTransService
      The transaction service used to track subtransactions
    • diskClassUtil

      protected DiskClassUtil diskClassUtil
      The disk class util
    • classGenerationDirectory

      protected Path classGenerationDirectory
      The directory where the generated classes are stored
    • runtime

      protected BoxRuntime 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

      public Map<String,ClassInfo> getClassPool(String classPoolName)
      Get a class pool by name
      Specified by:
      getClassPool in interface IBoxpiler
      Parameters:
      classPoolName - The name of the class pool
      Returns:
      The class pool
    • getClassPools

      public Map<String,Map<String,ClassInfo>> getClassPools()
      Get all class pools
      Returns:
      A map of class pools
    • clearPagePool

      public void clearPagePool()
      Clear page pools
      Specified by:
      clearPagePool in interface IBoxpiler
    • parse

      public ParsingResult parse(String source, BoxSourceType type, Boolean classOrInterface)
      Parse source text into BoxLang AST nodes. This method will NOT throw an exception if the parse fails.
      Specified by:
      parse in interface IBoxpiler
      Parameters:
      source - The source to parse.
      type - The BoxSourceType of the source.
      Returns:
      The parsed AST nodes and any issues if encountered while parsing.
    • parseOrFail

      public ParsingResult parseOrFail(File file)
      Parse a file on disk into BoxLang AST nodes. This method will throw an exception if the parse fails.
      Specified by:
      parseOrFail in interface IBoxpiler
      Parameters:
      file - The file to parse
      Returns:
      The parsed AST nodes and any issues if encountered while parsing.
    • parse

      public ParsingResult parse(File file)
      Parse a file on disk into BoxLang AST nodes. This method will NOT throw an exception if the parse fails.
      Specified by:
      parse in interface IBoxpiler
      Parameters:
      file - The file to parse
      Returns:
      The parsed AST nodes and any issues if encountered while parsing.
    • parseOrFail

      public ParsingResult parseOrFail(String source, BoxSourceType type, Boolean classOrInterface)
      Parse source text into BoxLang AST nodes. This method will throw an exception if the parse fails.
      Specified by:
      parseOrFail in interface IBoxpiler
      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

      public ParsingResult validateParse(ParsingResult result, String source)
      Validate a parsing result and throw an exception if the parse failed.
      Specified by:
      validateParse in interface IBoxpiler
      Parameters:
      result - The parsing result to validate
      Returns:
      The parsing result if the parse was successful
    • compileStatement

      public Class<IBoxRunnable> compileStatement(String source, BoxSourceType type)
      Compile a single BoxLang statement into a Java class
      Specified by:
      compileStatement in interface IBoxpiler
      Parameters:
      source - The BoxLang source code as a string
      type - The type of BoxLang source code
      Returns:
      The loaded class
    • compileScript

      public Class<IBoxRunnable> compileScript(String source, BoxSourceType type)
      Compile a BoxLang script into a Java class
      Specified by:
      compileScript in interface IBoxpiler
      Parameters:
      source - The BoxLang source code as a string
      type - The type of BoxLang source code
      Returns:
      The loaded class
    • compileTemplate

      public Class<IBoxRunnable> compileTemplate(ResolvedFilePath resolvedFilePath)
      Compile a BoxLang template (file on disk) into a Java class
      Specified by:
      compileTemplate in interface IBoxpiler
      Parameters:
      resolvedFilePath - The BoxLang source code as a Path on disk
      Returns:
      The loaded class
    • compileClass

      public Class<IBoxRunnable> compileClass(String source, BoxSourceType type)
      Compile a BoxLang Class from source into a Java class
      Specified by:
      compileClass in interface IBoxpiler
      Parameters:
      source - The BoxLang source code as a string
      Returns:
      The loaded class
    • compileClass

      public Class<IBoxRunnable> compileClass(ResolvedFilePath resolvedFilePath)
      Compile a BoxLang Class from a file into a Java class
      Specified by:
      compileClass in interface IBoxpiler
      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:
      compileInterfaceProxy in interface IBoxpiler
    • getSourceMapFromFQN

      public SourceMap getSourceMapFromFQN(String FQN)
      Specified by:
      getSourceMapFromFQN in interface IBoxpiler