Package groovy.transform
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 ElementsModifier and TypeOptional ElementDescriptionReturns 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 plusReturns the replacement method name for the+operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
minus
String minusReturns the replacement method name for the-operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
multiply
String multiplyReturns the replacement method name for the*operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
div
String divReturns the replacement method name for the/operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
remainder
String remainderReturns the replacement method name for the%operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
power
String powerReturns the replacement method name for the**operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
leftShift
String leftShiftReturns the replacement method name for the<<operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
rightShift
String rightShiftReturns the replacement method name for the>>operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
rightShiftUnsigned
String rightShiftUnsignedReturns the replacement method name for the>>>operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
and
String andReturns the replacement method name for the&operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
or
String orReturns the replacement method name for the|operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
xor
String xorReturns the replacement method name for the^operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
compareTo
String compareToReturns the replacement method name for the spaceship operator. Defaults toUndefined.STRING, meaning no rename.- Returns:
- the replacement method name
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
plusAssign
String plusAssignGEP-15: rename the dedicated compound-assignment method for+=.- Since:
- 6.0.0
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
minusAssign
String minusAssignGEP-15: rename the dedicated compound-assignment method for-=.- Since:
- 6.0.0
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
multiplyAssign
String multiplyAssignGEP-15: rename the dedicated compound-assignment method for*=.- Since:
- 6.0.0
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
divAssign
String divAssignGEP-15: rename the dedicated compound-assignment method for/=.- Since:
- 6.0.0
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
remainderAssign
String remainderAssignGEP-15: rename the dedicated compound-assignment method for%=.- Since:
- 6.0.0
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
powerAssign
String powerAssignGEP-15: rename the dedicated compound-assignment method for**=.- Since:
- 6.0.0
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
leftShiftAssign
String leftShiftAssignGEP-15: rename the dedicated compound-assignment method for<<=.- Since:
- 6.0.0
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
rightShiftAssign
String rightShiftAssignGEP-15: rename the dedicated compound-assignment method for>>=.- Since:
- 6.0.0
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
rightShiftUnsignedAssign
String rightShiftUnsignedAssignGEP-15: rename the dedicated compound-assignment method for>>>=.- Since:
- 6.0.0
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
andAssign
String andAssignGEP-15: rename the dedicated compound-assignment method for&=.- Since:
- 6.0.0
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
orAssign
String orAssignGEP-15: rename the dedicated compound-assignment method for|=.- Since:
- 6.0.0
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-
xorAssign
String xorAssignGEP-15: rename the dedicated compound-assignment method for^=.- Since:
- 6.0.0
- Default:
- "<DummyUndefinedMarkerString-DoNotUse>"
-