Package net.mcreator.blockly.java
Class ProcedureCodeOptimizer
java.lang.Object
net.mcreator.blockly.java.ProcedureCodeOptimizer
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
removeMarkers
(String code) This method removes blockstate/itemstack/int markers from the given codestatic String
removeParentheses
(String code) This method attempts to remove the parentheses surrounding the given code, if they are paired.static String
removeParentheses
(String code, String blacklist) This method attempts to remove the parentheses surrounding the given code, if they are paired.static String
This method performs parentheses optimization and adds a (float) cast to the given code if needed.static String
This method performs parentheses optimization and adds an (int) cast to the given code if needed.
-
Constructor Details
-
ProcedureCodeOptimizer
public ProcedureCodeOptimizer()
-
-
Method Details
-
removeParentheses
This method attempts to remove the parentheses surrounding the given code, if they are paired. Eventual marker comments at the beginning of the input are ignored.- Parameters:
code
- The code to optimize- Returns:
- If possible, the code without surrounding parentheses
-
removeParentheses
This method attempts to remove the parentheses surrounding the given code, if they are paired. The optimization will fail if any of the blacklisted characters appears at the top nesting level. Eventual marker comments at the beginning of the input are ignored.- Parameters:
code
- The code to optimizeblacklist
- The characters that can't be contained at the top nesting level- Returns:
- If possible, the code without surrounding parentheses
-
toInt
This method performs parentheses optimization and adds an (int) cast to the given code if needed.- Parameters:
code
- The code representing the number to cast- Returns:
- The code without parentheses, if it's already an int, or with a cast to (int) behind otherwise
-
toFloat
This method performs parentheses optimization and adds a (float) cast to the given code if needed.- Parameters:
code
- The code representing the number to cast- Returns:
- The code without parentheses, if it's already an int or float, or with a cast to (float) behind otherwise
-
removeMarkers
This method removes blockstate/itemstack/int markers from the given code- Parameters:
code
- The code to optimize- Returns:
- The code without blockstate/itemstack markers
-