Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/org/spongepowered/asm/mixin/Overwrite.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,13 @@
*/
public boolean remap() default true;

/**
* By default, if the target for an overwrite cannot be found in the target class an
* exception will be thrown, however in cases where you do not want that behaviour
* you can mark it as optional, and it will silently not apply rather than throwing an exception.
*
* @return True to not throw an exception if the target cannot be found
*/
public boolean optional() default false;

}
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,9 @@ protected void applyNormalMethod(MixinTargetContext mixin, MethodNode mixinMetho
* @param method Method to merge
*/
protected void mergeMethod(MixinTargetContext mixin, MethodNode method) {
boolean isOverwrite = Annotations.getVisible(method, Overwrite.class) != null;
AnnotationNode overwrite = Annotations.getVisible(method, Overwrite.class);
boolean isOverwrite = overwrite != null;
boolean isOptionalOverwrite = Annotations.<Boolean>getValue(overwrite, "optional", Boolean.FALSE);
MethodNode target = this.findTargetMethod(method);

if (target != null) {
Expand All @@ -504,7 +506,7 @@ protected void mergeMethod(MixinTargetContext mixin, MethodNode method) {

this.targetClass.methods.remove(target);
}
} else if (isOverwrite) {
} else if (isOverwrite && !isOptionalOverwrite) {
throw new InvalidMixinException(mixin, String.format("Overwrite target \"%s\" was not located in target class %s",
method.name, mixin.getTargetClassRef()));
}
Expand Down
Loading