java.lang.Object
com.wyu4.snowberryjam.compiler.LocalStorage
com.wyu4.snowberryjam.compiler.Compiler
The Snowberry Jam compiler class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final List<BiConsumer<String, String>> private static final org.slf4j.Loggerprivate static final List<BiConsumer<String, String>> private static final List<BiConsumer<String, String>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddErrorListener(BiConsumer<String, String> consumer) Add a error listenerstatic voidaddPrintListener(BiConsumer<String, String> consumer) Add a print listenerstatic voidaddWarnListener(BiConsumer<String, String> consumer) Add a warn listenerstatic ObjectasPrimitiveObject(com.fasterxml.jackson.databind.JsonNode node) Get a node as a primitive objectstatic voidCompile the JSON contents of aString.static voidcompileBody(com.fasterxml.jackson.databind.JsonNode body, BodyStack stack) Converts the contents of any"body":[]property into tasks, and stores them in aBodyStack.private static voidcompileEvents(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.static voidSend an error statement to the development console.static voidSend an error statement and stack trace to the development console.static StringformatString(String str) static StringgetId(com.fasterxml.jackson.databind.JsonNode node) Grabs the ID of the nodestatic StringgetName(com.fasterxml.jackson.databind.JsonNode node) Grabs the name of the nodeprivate static StringgetProperty(com.fasterxml.jackson.databind.JsonNode node, String key) Grabs the value of a property given the key.private static com.fasterxml.jackson.databind.JsonNodeCreates aJsonNodetree from a JSONStringprivate static voidmapProjectData(com.fasterxml.jackson.databind.JsonNode tree) Map the project data.private static voidmapProjectVariables(com.fasterxml.jackson.databind.JsonNode projectBody) Maps/stores all the variables found in the project's body.static voidSend a print statement to the development console.static voidSend a print statement to the development console.static voidSend a warning statement to the development console.Methods inherited from class com.wyu4.snowberryjam.compiler.LocalStorage
addCachedValue, addInputSubscription, addVariableListener, copyStack, createThread, createVariable, flush, formatMessage, getDefaultSource, getPointer, getRaw, getVariableNames, increasePointer, isRunning, runStack, sendInput, setDescription, setName, setVariable, stackAdd, stopRun
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
PRINT_LISTENERS
-
WARN_LISTENERS
-
ERROR_LISTENERS
-
-
Constructor Details
-
Compiler
public Compiler()
-
-
Method Details
-
formatString
-
getTree
private static com.fasterxml.jackson.databind.JsonNode getTree(String source) throws com.fasterxml.jackson.core.JsonProcessingException Creates aJsonNodetree from a JSONString- 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 aString. 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 stringcom.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 inLocalStorage- 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 inLocalStorage- Parameters:
projectBody- The body of the project- See Also:
-
compileBody
Converts the contents of any"body":[]property into tasks, and stores them in aBodyStack.- Parameters:
body- The selected body to compilestack- The stack to store compile tasks- See Also:
-
getProperty
Grabs the value of a property given the key. Used by more specific methods.- Parameters:
node- A nodekey- The key- Returns:
- The value of the property as a string. May be
nullif the property isn't found. - See Also:
-
getId
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 benullif the ID isn't found. - See Also:
-
getName
Grabs the name of the node- Parameters:
node- A node- Returns:
- The name as a string. May be
nullif the name isn't found.
-
asPrimitiveObject
Get a node as a primitive object -
print
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
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
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
Send an error statement and stack trace to the development console.- Parameters:
error- Error to sende- Exception to send (used to print stack trace)- See Also:
-
warn
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
Add a print listener- Parameters:
consumer- Consumer to run when something is printed- See Also:
-
addWarnListener
Add a warn listener- Parameters:
consumer- Consumer to run when something is warned- See Also:
-
addErrorListener
Add a error listener- Parameters:
consumer- Consumer to run when something is errored- See Also:
-