Annotation Interface OperatorRename


@Documented @Incubating @Retention(SOURCE) @Target({METHOD,CONSTRUCTOR,TYPE}) public @interface OperatorRename
Allows renaming of Groovy's operator methods. This can be useful for using Groovy's operator overloading with libraries designed with different method names. As an example, here is using the Commons Numbers Fraction library. This normally has an "add" method, but we can use the "+" operator using this transform.
 @OperatorRename(plus="add")
 def testAddOfTwoFractions() {
     var half = Fraction.of(1, 2)
     var third = Fraction.of(1, 3)
     assert half + third == Fraction.of(5, 6)
 }
 
Since:
5.0.0
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Returns the replacement method name for the & operator.
    GEP-15: rename the dedicated compound-assignment method for &=.
    Returns the replacement method name for the spaceship operator.
    Returns the replacement method name for the / operator.
    GEP-15: rename the dedicated compound-assignment method for /=.
    Returns the replacement method name for the << operator.
    GEP-15: rename the dedicated compound-assignment method for <<=.
    Returns the replacement method name for the - operator.
    GEP-15: rename the dedicated compound-assignment method for -=.
    Returns the replacement method name for the * operator.
    GEP-15: rename the dedicated compound-assignment method for *=.
    Returns the replacement method name for the | operator.
    GEP-15: rename the dedicated compound-assignment method for |=.
    Returns the replacement method name for the + operator.
    GEP-15: rename the dedicated compound-assignment method for +=.
    Returns the replacement method name for the ** operator.
    GEP-15: rename the dedicated compound-assignment method for **=.
    Returns the replacement method name for the % operator.
    GEP-15: rename the dedicated compound-assignment method for %=.
    Returns the replacement method name for the >> operator.
    GEP-15: rename the dedicated compound-assignment method for >>=.
    Returns the replacement method name for the >>> operator.
    GEP-15: rename the dedicated compound-assignment method for >>>=.
    Returns the replacement method name for the ^ operator.
    GEP-15: rename the dedicated compound-assignment method for ^=.
  • Element Details

    • plus

      String plus
      Returns the replacement method name for the + operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • minus

      String minus
      Returns the replacement method name for the - operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • multiply

      String multiply
      Returns the replacement method name for the * operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • div

      String div
      Returns the replacement method name for the / operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • remainder

      String remainder
      Returns the replacement method name for the % operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • power

      String power
      Returns the replacement method name for the ** operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • leftShift

      String leftShift
      Returns the replacement method name for the << operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • rightShift

      String rightShift
      Returns the replacement method name for the >> operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • rightShiftUnsigned

      String rightShiftUnsigned
      Returns the replacement method name for the >>> operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • and

      String and
      Returns the replacement method name for the & operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • or

      String or
      Returns the replacement method name for the | operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • xor

      String xor
      Returns the replacement method name for the ^ operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • compareTo

      String compareTo
      Returns the replacement method name for the spaceship operator. Defaults to Undefined.STRING, meaning no rename.
      Returns:
      the replacement method name
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • plusAssign

      String plusAssign
      GEP-15: rename the dedicated compound-assignment method for +=.
      Since:
      6.0.0
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • minusAssign

      String minusAssign
      GEP-15: rename the dedicated compound-assignment method for -=.
      Since:
      6.0.0
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • multiplyAssign

      String multiplyAssign
      GEP-15: rename the dedicated compound-assignment method for *=.
      Since:
      6.0.0
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • divAssign

      String divAssign
      GEP-15: rename the dedicated compound-assignment method for /=.
      Since:
      6.0.0
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • remainderAssign

      String remainderAssign
      GEP-15: rename the dedicated compound-assignment method for %=.
      Since:
      6.0.0
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • powerAssign

      String powerAssign
      GEP-15: rename the dedicated compound-assignment method for **=.
      Since:
      6.0.0
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • leftShiftAssign

      String leftShiftAssign
      GEP-15: rename the dedicated compound-assignment method for <<=.
      Since:
      6.0.0
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • rightShiftAssign

      String rightShiftAssign
      GEP-15: rename the dedicated compound-assignment method for >>=.
      Since:
      6.0.0
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • rightShiftUnsignedAssign

      String rightShiftUnsignedAssign
      GEP-15: rename the dedicated compound-assignment method for >>>=.
      Since:
      6.0.0
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • andAssign

      String andAssign
      GEP-15: rename the dedicated compound-assignment method for &=.
      Since:
      6.0.0
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • orAssign

      String orAssign
      GEP-15: rename the dedicated compound-assignment method for |=.
      Since:
      6.0.0
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"
    • xorAssign

      String xorAssign
      GEP-15: rename the dedicated compound-assignment method for ^=.
      Since:
      6.0.0
      Default:
      "<DummyUndefinedMarkerString-DoNotUse>"