Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@

import java.util.Map.Entry;

import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.tree.FieldNode;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Field;
import org.spongepowered.asm.mixin.transformer.throwables.InvalidInterfaceMixinException;
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.Bytecode;

/**
* Applicator for interface mixins, mainly just disables things which aren't
Expand Down Expand Up @@ -101,23 +107,29 @@ protected void prepareInjections(MixinTargetContext mixin) {
try {
InjectionInfo injectInfo = InjectionInfo.parse(mixin, method);
if (injectInfo != null) {
throw new InvalidInterfaceMixinException(mixin, injectInfo + " is not supported on interface mixin method " + method.name);
if (!Bytecode.hasFlag(method, Opcodes.ACC_STATIC) && !MixinEnvironment.getCompatibilityLevel().isAtLeast(MixinEnvironment.CompatibilityLevel.JAVA_8)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually support default methods ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as long as Mixin is configured to run on, or running on, Java 8+. We don't want to accidentally allow inserting default methods where they're unsupported.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you actually allow inserting into any interface method when on Java 8. Seems good to me.

throw new InvalidInterfaceMixinException(mixin, injectInfo + " is not supported on interface mixin method " + method.name);
}
}
} catch (InvalidInjectionException ex) {
String description = ex.getInjectionInfo() != null ? ex.getInjectionInfo().toString() : "Injection";
throw new InvalidInterfaceMixinException(mixin, description + " is not supported in interface mixin");
}
}

super.prepareInjections(mixin);
}

/* (non-Javadoc)
* @see org.spongepowered.asm.mixin.transformer.MixinApplicator
* #applyInjections(
* org.spongepowered.asm.mixin.transformer.MixinTargetContext)
*/

@Override
protected void applyInjections(MixinTargetContext mixin) {
// Do nothing
}
protected void checkMethodVisibility(MixinTargetContext mixin, MethodNode mixinMethod) {
// support injecting into static interface methods
if (Bytecode.hasFlag(mixinMethod, Opcodes.ACC_STATIC)) {
InjectionInfo injectInfo = InjectionInfo.parse(mixin, mixinMethod);
if (injectInfo != null) {
return;
}
}

super.checkMethodVisibility(mixin, mixinMethod);
}
}