Class ConstraintParser.Constraint

java.lang.Object
org.spongepowered.asm.util.ConstraintParser.Constraint
Enclosing class:
ConstraintParser

public static class ConstraintParser.Constraint extends Object
A constraint. Constraints are parsed from string expressions which are always of the form:
<token>(<constraint>)

token is normalised to uppercase and must be provided by the environment.

constraint is an integer range specified in one of the following formats:

()
The token value must be present in the environment, but can have any value
(1234)
The token value must be exactly equal to 1234
(1234+)
(1234-)
(1234>)
All of these variants mean the same thing, and can be read as "1234 or greater"
(<1234)
Less than 123
(<=1234)
Less than or equal to 1234 (equivalent to 1234< )
(>1234)
Greater than 1234
(>=1234)
Greater than or equal to 1234 (equivalent to 1234 >)
(1234-1300)
Value must be between 1234 and 1300 (inclusive)
(1234+10)
Value must be between 1234 and 1234+10 (1234-1244 inclusive)

All whitespace is ignored in constraint declarations. The following declarations are equivalent:

token(123-456)
token   (   123 - 456   )

Multiple constraints should be separated by semicolon (;) and are conjoined by an implied logical AND operator. That is: all constraints must pass for the constraint to be considered valid.

  • Field Details

  • Method Details

    • getToken

      public String getToken()
    • getMin

      public int getMin()
    • getMax

      public int getMax()
    • check

      public void check(ITokenProvider environment) throws org.spongepowered.asm.util.throwables.ConstraintViolationException
      Checks the current token against the environment and throws a ConstraintViolationException if the constraint is invalid
      Parameters:
      environment - environment to fetch constraints
      Throws:
      org.spongepowered.asm.util.throwables.ConstraintViolationException - if constraint is not valid
    • getRangeHumanReadable

      public String getRangeHumanReadable()
      Gets a human-readable description of the range expressed by this constraint
    • toString

      public String toString()
      Overrides:
      toString in class Object