diff --git a/src/main/java/org/cadixdev/mercury/mixin/MixinRemapperVisitor.java b/src/main/java/org/cadixdev/mercury/mixin/MixinRemapperVisitor.java index 2ce7d71..f7de71a 100644 --- a/src/main/java/org/cadixdev/mercury/mixin/MixinRemapperVisitor.java +++ b/src/main/java/org/cadixdev/mercury/mixin/MixinRemapperVisitor.java @@ -461,10 +461,14 @@ private String remapInjectTarget(final ClassMapping target, final InjectTa } final MappingSet mappings = target.getMappings(); + final String targetOwner = injectTarget.getOwnerName(); final MethodDescriptor descriptor = injectTarget.getMethodDescriptor().orElse(null); final Type type = injectTarget.getFieldType().orElse(null); final StringBuilder remappedFull = new StringBuilder(); + if (targetOwner != null) { + remappedFull.append("L").append(targetOwner).append(";"); + } remappedFull.append(targetName); if (descriptor != null) { remappedFull.append(mappings.deobfuscate(descriptor)); diff --git a/src/main/java/org/cadixdev/mercury/mixin/annotation/InjectTarget.java b/src/main/java/org/cadixdev/mercury/mixin/annotation/InjectTarget.java index efe7c87..b6cabde 100644 --- a/src/main/java/org/cadixdev/mercury/mixin/annotation/InjectTarget.java +++ b/src/main/java/org/cadixdev/mercury/mixin/annotation/InjectTarget.java @@ -11,6 +11,8 @@ import org.cadixdev.bombe.type.TypeReader; import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Inject target can either be a name, a name and method signature, or a name and field type. @@ -19,30 +21,47 @@ * @since 0.1.0 */ public class InjectTarget { + public static final Pattern FULL_REF_PATTERN = Pattern.compile("([\\w_$/]+)\\.(.*)(\\(.*?\\).+)|L([\\w_$/]+);(.*)(\\(.*?\\).+)"); + private final String ownerName; private final String targetName; private final MethodDescriptor methodDescriptor; private final Type fieldType; public InjectTarget(final String targetName) { + this.ownerName = null; this.targetName = targetName; this.methodDescriptor = null; this.fieldType = null; } public InjectTarget(final String targetName, final MethodDescriptor methodDescriptor) { + this.ownerName = null; this.targetName = targetName; this.methodDescriptor = methodDescriptor; this.fieldType = null; } public InjectTarget(final String targetName, final Type fieldType) { + this.ownerName = null; this.targetName = targetName; this.methodDescriptor = null; this.fieldType = fieldType; } + + public InjectTarget(final String ownerName, final String targetName, final MethodDescriptor methodDescriptor) { + this.ownerName = ownerName; + this.targetName = targetName; + this.methodDescriptor = methodDescriptor; + this.fieldType = null; + } public static InjectTarget of(final String target) { + Matcher matcher = FULL_REF_PATTERN.matcher(target); + if (matcher.matches()) { + return new InjectTarget(matcher.group(1), matcher.group(2), MethodDescriptor.of(matcher.group(3))); + } + int index = target.indexOf('('); if (index >= 0) { return new InjectTarget(target.substring(0, index), MethodDescriptor.of(target.substring(index))); @@ -55,6 +74,10 @@ public static InjectTarget of(final String target) { return new InjectTarget(target); } + public String getOwnerName() { + return this.ownerName; + } + public String getTargetName() { return this.targetName; }