Class AbstractTransformer

java.lang.Object
ortus.boxlang.compiler.javaboxpiler.transformer.AbstractTransformer
All Implemented Interfaces:
Transformer
Direct Known Subclasses:
BoxAccessTransformer, BoxArgumentDeclarationTransformer, BoxArgumentTransformer, BoxArrayLiteralTransformer, BoxAssertTransformer, BoxAssignmentTransformer, BoxBinaryOperationTransformer, BoxBooleanLiteralTransformer, BoxBreakTransformer, BoxBufferOutputTransformer, BoxClassTransformer, BoxClosureTransformer, BoxComparisonOperationTransformer, BoxComponentTransformer, BoxContinueTransformer, BoxDecimalLiteralTransformer, BoxDoTransformer, BoxExpressionInvocationTransformer, BoxExpressionStatementTransformer, BoxForIndexTransformer, BoxForInTransformer, BoxFQNTransformer, BoxFunctionalBIFAccessTransformer, BoxFunctionalMemberAccessTransformer, BoxFunctionDeclarationTransformer, BoxFunctionInvocationTransformer, BoxIdentifierTransformer, BoxIfElseTransformer, BoxImportTransformer, BoxIntegerLiteralTransformer, BoxInterfaceTransformer, BoxLambdaTransformer, BoxMethodInvocationTransformer, BoxNegateOperationTransformer, BoxNewTransformer, BoxNullTransformer, BoxParamTransformer, BoxParenthesisTransformer, BoxRethrowTransformer, BoxReturnTransformer, BoxScopeTransformer, BoxScriptIslandTransformer, BoxScriptTransformer, BoxStatementBlockTransformer, BoxStaticAccessTransformer, BoxStaticInitializerTransformer, BoxStaticMethodInvocationTransformer, BoxStringConcatTransformer, BoxStringLiteralTransformer, BoxStructLiteralTransformer, BoxSwitchTransformer, BoxTemplateIslandTransformer, BoxTernaryOperationTransformer, BoxThrowTransformer, BoxTryTransformer, BoxUnaryOperationTransformer, BoxWhileTransformer

public abstract class AbstractTransformer extends Object implements Transformer
Abstract Transformer class Implements common functionality used by all the transformer sub classes
  • Field Details

    • transpiler

      protected Transpiler transpiler
    • javaParser

      protected com.github.javaparser.JavaParser javaParser
    • logger

      protected org.slf4j.Logger logger
      Logger
  • Constructor Details

    • AbstractTransformer

      public AbstractTransformer(Transpiler transpiler)
  • Method Details

    • transform

      public abstract com.github.javaparser.ast.Node transform(BoxNode node, TransformerContext context) throws IllegalStateException
      Specified by:
      transform in interface Transformer
      Throws:
      IllegalStateException
    • transform

      public com.github.javaparser.ast.Node transform(BoxNode node) throws IllegalStateException
      Specified by:
      transform in interface Transformer
      Throws:
      IllegalStateException
    • parseExpression

      protected com.github.javaparser.ast.expr.Expression parseExpression(String template, Map<String,String> values)
      Returns the Java Parser AST nodes for the given template
      Parameters:
      template - a string template with the expression to parse
      values - a map of values to be replaced in the template
      Returns:
      the Java Parser AST representation of the expression
    • parseStatement

      protected com.github.javaparser.ast.stmt.Statement parseStatement(String template, Map<String,String> values)
      Returns the Java Parser AST for the given template
      Parameters:
      template - a string template with the statement to parse
      values - a map of values to be replaced in the template
      Returns:
      the Java Parser AST representation of the statement
    • createKey

      public com.github.javaparser.ast.expr.Expression createKey(BoxExpression expr)
      Create a Key instance out of any expression. May optimize requests for the same key more than once in a template
      Parameters:
      expr - expression to be turned into a Key. May be a literal, or expression
      Returns:
      The method call expression
    • createKey

      public com.github.javaparser.ast.expr.Expression createKey(String expr)
      Create a Key instance from a string literal. May optimize requests for the same key more than once in a template
      Parameters:
      expr - expression to be turned into a Key. May be a literal, or expression
      Returns:
      Instance of the Key.of method call expression
    • requiresBooleanCaster

      protected boolean requiresBooleanCaster(BoxExpression condition)
      Detects if a statement requires a BooleanCaster
      Parameters:
      condition - the expression to evaluate
      Returns:
      true if the BooleanCaster is required
    • addIndex

      protected com.github.javaparser.ast.Node addIndex(com.github.javaparser.ast.Node javaNode, BoxNode boxNode)
      Add cross-reference index entry
      Parameters:
      javaNode - Java Parser Node
      boxNode - BoxLang Node
      Returns:
      the Java Parser Node
    • transformDocumentation

      public com.github.javaparser.ast.expr.Expression transformDocumentation(List<BoxDocumentationAnnotation> documentation)
      Transforms a collection of documentation annotations in a BoxLang Struct
      Parameters:
      documentation - list of documentation annotation
      Returns:
      an Expression node
    • transformAnnotations

      public com.github.javaparser.ast.expr.Expression transformAnnotations(List<BoxAnnotation> annotations, Boolean defaultTrue, boolean onlyLiteralValues)
      Transforms a collection of annotations in a BoxLang Struct
      Parameters:
      annotations - list of annotation
      Returns:
      an Expression node
    • transformAnnotations

      public com.github.javaparser.ast.expr.Expression transformAnnotations(List<BoxAnnotation> annotations)
      Transforms a collection of annotations in a BoxLang Struct
      Parameters:
      annotations - list of annotation
      Returns:
      an Expression node
    • generateArguments

      protected String generateArguments(List<BoxArgument> arguments)
    • getExitsAllowed

      public AbstractTransformer.ExitsAllowed getExitsAllowed(BoxNode node)