Class TokenUtil

java.lang.Object
org.codehaus.groovy.syntax.TokenUtil

public class TokenUtil extends Object
Utility methods for working with tokens and operators. Provides helper functions for operator type manipulation and conversion.
  • Method Details

    • asAssignment

      public static Optional<Token> asAssignment(int op)
      Converts an increment or decrement operator to its corresponding assignment operator. For example, ++ becomes +=, and -- becomes -=.
      Parameters:
      op - the operator type (e.g., Types.PLUS_PLUS, Types.PREFIX_PLUS_PLUS)
      Returns:
      an Optional containing the assignment operator token, or empty if not applicable
    • removeAssignment

      public static int removeAssignment(int op)
      Removes the assignment portion of an assignment operator, returning the base operator. For example, += becomes +, -= becomes -. If the operator is not an assignment operator, returns it unchanged.
      Parameters:
      op - the operator type from Types
      Returns:
      the base operator type without assignment, or the original type if not an assignment operator