Package com.llamalad7.mixinextras.sugar
Annotation Type Cancellable
-
@Documented @Retention(CLASS) @Target(PARAMETER) public @interface CancellableThe Cancellable annotation can be applied on arguments of aRedirecthandler to allow the possibility to cancel large quantities of logic within the injected method. More specifically, this annotation may only be applied on aCallbackInfoorCallbackInfoReturnableargument, which makes that argument behave similar to as if theCallbackInfowas used in a traditional setting withInjectandInject.cancellable()set totrue. Callback instances are reused where applicable and created lazily.Callback IDs
WhileInjectallows to set customidentifiersfor the callback objects in the spongeian implementation, micromixin-transformer does not allow the definition of custom callback IDs. However, both micromixin-transformer and MixinExtras forbid the explicit definition of these IDs. In the case of MixinExtras the resulting Id of the callback is left undefined by the MixinExtras documentation, where as micromixin-transformer will use the name of the method which is being targeted by the handler. As micromixin-transformer does not support the usage of refmaps, the name of the identifier will thus be dependent on the environment it is running under. This behaviour may cause differences between production and development environments. As a rule of thumb, the identifier of the callback should not be relied on for any logic except for logging and debugging.Permissible uses
MixinExtras does not strongly define where the usage of this annotation is permissible or not, however micromixin-transformer explicitly applies restrictions on where this annotation can be used and where it can't. These restrictions are follows:- This annotation can only be applied on arguments of either type
CallbackInfoorCallbackInfoReturnable. - This annotation can only be applied where argument capture would otherwise be legal.
In case of doubt, the annotated
CallbackInfoshould be appended to the end of the argument list of the handler method. - This annotation may not be applied in conjunction with
Inject. - This annotation cannot be applied on non-injecting handlers - this means that it is
illegal to use this annotation on
Unique,Overwrite, orShadow. - As of time of writing, micromixin-transformer only permits use in conjunction with
Redirect, but this restriction is likely to be lifted in future revisions of micromixin-transformer.
Example usage
Assume following target:
Execution of this method can be aborted after the redirected invocation ofprivate static int redirectStaticReturnable() { CancellableTest.counter1 = 1; CancellableTest.counter1 = new MutableInt(2).intValue(); CancellableTest.counter1 = 3; return 0; }intValueusing following mixin handler:
This results in following code:@Redirect(at = @At(value = "INVOKE", target = "intValue"), method = "redirectStaticReturnable") private static int handleRedirectStaticReturnable(@NotNull MutableInt caller, @Cancellable CallbackInfoReturnable<Integer> ci) { ci.setReturnValue(1); return 4; }
Note that in this case the assignment to@CommonCIInstance(index=1) private static void redirectStatic() { CallbackInfo callbackInfo = null; counter0 = 1; MutableInt mutableInt = new MutableInt(2); if (callbackInfo == null) { callbackInfo = new CallbackInfo("redirectStatic", true); } int i = CancellableTest.$handler$0$redirect$handleRedirectStatic(mutableInt, callbackInfo); if (callbackInfo.isCancelled()) { return; } counter0 = i; counter0 = 3; }counter0will be cancelled, too.- Since:
- 0.6.3
- This annotation can only be applied on arguments of either type