@Documented
@Incubating
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.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)
}
| Type | Name and Description |
|---|---|
String |
andReturns the replacement method name for the & operator.
|
String |
andAssignGEP-15: rename the dedicated compound-assignment method for &=. |
String |
compareToReturns the replacement method name for the spaceship operator. |
String |
divReturns the replacement method name for the / operator.
|
String |
divAssignGEP-15: rename the dedicated compound-assignment method for /=. |
String |
isInReturns the replacement method name for the in membership operator
(whose default method is isIn). |
String |
isNotInReturns the replacement method name for the {@code ! |
String |
leftShiftReturns the replacement method name for the << operator.
|
String |
leftShiftAssignGEP-15: rename the dedicated compound-assignment method for <<=. |
String |
minusReturns the replacement method name for the - operator.
|
String |
minusAssignGEP-15: rename the dedicated compound-assignment method for -=. |
String |
multiplyReturns the replacement method name for the * operator.
|
String |
multiplyAssignGEP-15: rename the dedicated compound-assignment method for *=. |
String |
orReturns the replacement method name for the | operator.
|
String |
orAssignGEP-15: rename the dedicated compound-assignment method for |=. |
String |
plusReturns the replacement method name for the + operator.
|
String |
plusAssignGEP-15: rename the dedicated compound-assignment method for +=. |
String |
powerReturns the replacement method name for the ** operator.
|
String |
powerAssignGEP-15: rename the dedicated compound-assignment method for **=. |
String |
remainderReturns the replacement method name for the % operator.
|
String |
remainderAssignGEP-15: rename the dedicated compound-assignment method for %=. |
String |
rightShiftReturns the replacement method name for the >> operator.
|
String |
rightShiftAssignGEP-15: rename the dedicated compound-assignment method for >>=. |
String |
rightShiftUnsignedReturns the replacement method name for the >>> operator.
|
String |
rightShiftUnsignedAssignGEP-15: rename the dedicated compound-assignment method for >>>=. |
String |
xorReturns the replacement method name for the ^ operator.
|
String |
xorAssignGEP-15: rename the dedicated compound-assignment method for ^=. |
Returns the replacement method name for the & operator.
Defaults to Undefined.STRING, meaning no rename.
GEP-15: rename the dedicated compound-assignment method for &=.
Returns the replacement method name for the spaceship operator. Defaults to Undefined.STRING, meaning no rename.
Returns the replacement method name for the / operator.
Defaults to Undefined.STRING, meaning no rename.
GEP-15: rename the dedicated compound-assignment method for /=.
Returns the replacement method name for the in membership operator
(whose default method is isIn). Defaults to Undefined.STRING,
meaning no rename. The receiver is the right operand (the container), so
a in b dispatches to b.name(a). Setting this to 'isCase'
restores the pre-GROOVY-9848 value-based membership for maps and char sequences
within the annotated scope.
This governs in only; !in is renamed separately via isNotIn().
To change membership consistently, set both (otherwise in and
!in can disagree for maps and char sequences) -- for example
@OperatorRename(isIn='isCase', isNotIn='isNotCase') to fully restore legacy behaviour.
Returns the replacement method name for the !in membership operator
(whose default method is isNotIn). Defaults to Undefined.STRING,
meaning no rename. The receiver is the right operand (the container), so
a !in b dispatches to b.name(a). Usually set together with
isIn() so that in and !in stay consistent.
Returns the replacement method name for the << operator.
Defaults to Undefined.STRING, meaning no rename.
GEP-15: rename the dedicated compound-assignment method for <<=.
Returns the replacement method name for the - operator.
Defaults to Undefined.STRING, meaning no rename.
GEP-15: rename the dedicated compound-assignment method for -=.
Returns the replacement method name for the * operator.
Defaults to Undefined.STRING, meaning no rename.
GEP-15: rename the dedicated compound-assignment method for *=.
Returns the replacement method name for the | operator.
Defaults to Undefined.STRING, meaning no rename.
GEP-15: rename the dedicated compound-assignment method for |=.
Returns the replacement method name for the + operator.
Defaults to Undefined.STRING, meaning no rename.
GEP-15: rename the dedicated compound-assignment method for +=.
Returns the replacement method name for the ** operator.
Defaults to Undefined.STRING, meaning no rename.
GEP-15: rename the dedicated compound-assignment method for **=.
Returns the replacement method name for the % operator.
Defaults to Undefined.STRING, meaning no rename.
GEP-15: rename the dedicated compound-assignment method for %=.
Returns the replacement method name for the >> operator.
Defaults to Undefined.STRING, meaning no rename.
GEP-15: rename the dedicated compound-assignment method for >>=.
Returns the replacement method name for the >>> operator.
Defaults to Undefined.STRING, meaning no rename.
GEP-15: rename the dedicated compound-assignment method for >>>=.
Returns the replacement method name for the ^ operator.
Defaults to Undefined.STRING, meaning no rename.
GEP-15: rename the dedicated compound-assignment method for ^=.