Skip to content

Commit

Permalink
Handle fully qualified method targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed May 28, 2024
1 parent 147b99f commit bab09b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)));
Expand All @@ -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;
}
Expand Down

0 comments on commit bab09b3

Please sign in to comment.