Class Compiler

java.lang.Object
com.wyu4.snowberryjam.compiler.LocalStorage
com.wyu4.snowberryjam.compiler.Compiler

public abstract class Compiler extends LocalStorage
The Snowberry Jam compiler class
  • Field Details

  • Constructor Details

    • Compiler

      public Compiler()
  • Method Details

    • formatString

      public static String formatString(String str)
    • getTree

      private static com.fasterxml.jackson.databind.JsonNode getTree(String source) throws com.fasterxml.jackson.core.JsonProcessingException
      Creates a JsonNode tree from a JSON String
      Parameters:
      source - JSON source code as a string
      Returns:
      A JsonNode representation of the string
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - Any exceptions that arise while mapping the contents of the string
      See Also:
    • compile

      public static void compile(String source) throws com.fasterxml.jackson.databind.JsonMappingException, com.fasterxml.jackson.core.JsonProcessingException
      Compile the JSON contents of a String. Starts by creating a tree, maps project data, maps variables, and then compiles events.
      Parameters:
      source - JSON source code as a string
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - Any exceptions that arise while mapping the contents of the string
      com.fasterxml.jackson.databind.JsonMappingException
      See Also:
    • mapProjectData

      private static void mapProjectData(com.fasterxml.jackson.databind.JsonNode tree)
      Map the project data. THis includes any metadata such as the project name and description.
      Parameters:
      tree - The full project tree
    • mapProjectVariables

      private static void mapProjectVariables(com.fasterxml.jackson.databind.JsonNode projectBody)
      Maps/stores all the variables found in the project's body. This only includes variable initialization in the "variables":[] section. This uses protected methods in LocalStorage
      Parameters:
      projectBody - The body of the project
      See Also:
    • compileEvents

      private static void compileEvents(com.fasterxml.jackson.databind.JsonNode projectBody)
      Compiles and stores all the events found in the "events":[] section in the project body to stacks, and subsequently converts compiles bodies to stacks. This uses protected methods in LocalStorage
      Parameters:
      projectBody - The body of the project
      See Also:
    • compileBody

      public static void compileBody(com.fasterxml.jackson.databind.JsonNode body, BodyStack stack)
      Converts the contents of any "body":[] property into tasks, and stores them in a BodyStack.
      Parameters:
      body - The selected body to compile
      stack - The stack to store compile tasks
      See Also:
    • getProperty

      private static String getProperty(com.fasterxml.jackson.databind.JsonNode node, String key)
      Grabs the value of a property given the key. Used by more specific methods.
      Parameters:
      node - A node
      key - The key
      Returns:
      The value of the property as a string. May be null if the property isn't found.
      See Also:
    • getId

      public static String getId(com.fasterxml.jackson.databind.JsonNode node)
      Grabs the ID of the node
      Parameters:
      node - A node
      Returns:
      The ID as a string. User helper methods to convert this into its respective Enum. May be null if the ID isn't found.
      See Also:
    • getName

      public static String getName(com.fasterxml.jackson.databind.JsonNode node)
      Grabs the name of the node
      Parameters:
      node - A node
      Returns:
      The name as a string. May be null if the name isn't found.
    • asPrimitiveObject

      public static Object asPrimitiveObject(com.fasterxml.jackson.databind.JsonNode node)
      Get a node as a primitive object
      Parameters:
      node - A node
      Returns:
      A Double, String, Boolean, or Array parsed as an Object. Might return null if the node isn't primitive.
    • print

      public static void print(Object message, Object... args)
      Send a print statement to the development console.
      Parameters:
      message - Message to send (arguments can be inserted by adding "{}" in the message).
      args - Arguments to append in the message
      See Also:
    • printTab

      public static void printTab(Object message, Object... args)
      Send a print statement to the development console. Messages send using this are inlined.
      Parameters:
      message - Message to send (arguments can be inserted by adding "{}" in the message).
      args - Arguments to append in the message
      See Also:
    • error

      public static void error(Object error)
      Send an error statement to the development console.
      Parameters:
      error - Message to send (arguments can be inserted by adding "{}" in the message).
      See Also:
    • error

      public static void error(Object error, Exception e)
      Send an error statement and stack trace to the development console.
      Parameters:
      error - Error to send
      e - Exception to send (used to print stack trace)
      See Also:
    • warn

      public static void warn(Object message, Object... args)
      Send a warning statement to the development console.
      Parameters:
      message - Warning to send (arguments can be inserted by adding "{}" in the message).
      args - Arguments to append in the message
      See Also:
    • addPrintListener

      public static void addPrintListener(BiConsumer<String,String> consumer)
      Add a print listener
      Parameters:
      consumer - Consumer to run when something is printed
      See Also:
    • addWarnListener

      public static void addWarnListener(BiConsumer<String,String> consumer)
      Add a warn listener
      Parameters:
      consumer - Consumer to run when something is warned
      See Also:
    • addErrorListener

      public static void addErrorListener(BiConsumer<String,String> consumer)
      Add a error listener
      Parameters:
      consumer - Consumer to run when something is errored
      See Also: