Class ProcedureCodeOptimizer

java.lang.Object
net.mcreator.blockly.java.ProcedureCodeOptimizer

public class ProcedureCodeOptimizer extends Object
  • Constructor Details

    • ProcedureCodeOptimizer

      public ProcedureCodeOptimizer()
  • Method Details

    • removeParentheses

      public static String removeParentheses(String code)
      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

      public static String removeParentheses(String code, String blacklist)
      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 optimize
      blacklist - The characters that can't be contained at the top nesting level
      Returns:
      If possible, the code without surrounding parentheses
    • toInt

      public static String toInt(String code)
      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

      public static String toFloat(String code)
      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

      public static String removeMarkers(String code)
      This method removes blockstate/itemstack/int markers from the given code
      Parameters:
      code - The code to optimize
      Returns:
      The code without blockstate/itemstack markers