Skip to content

Commit

Permalink
Fix wildcard targets
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Nov 8, 2024
1 parent fccc068 commit c5d1beb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,26 @@ public static MemberInfo parse(String str) {
@Override
public String toString() {
String owner = getOwner().isEmpty() ? "" : StringUtility.classNameToDesc(getOwner());
String desc = getDesc().isEmpty() ? "" : (Objects.equals(getType(), MemberType.FIELD) ? ":" : "") + getDesc();

return owner + name + quantifier + desc;
return owner + name + quantifier + formattedDesc();
}

private String formattedDesc() {
final String desc = getDesc();

if (desc.isEmpty()) {
return "";
}

if (Objects.equals(getType(), MemberType.FIELD)) {
return ":" + desc;
}

// Wildcards match regardless of descriptor
if (getQuantifier().equals("*")) {
return "";
}

return desc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,23 @@ void parse() {
assertEquals(info.getQuantifier(), "");
assertEquals(info.getDesc(), "([C)Ljava/lang/String;");
assertEquals(info.toString(), "([C)Ljava/lang/String;");

info = MemberInfo.parse("<init>*");
assertNotNull(info);
assertNull(info.getType());
assertEquals(info.getOwner(), "");
assertEquals(info.getName(), "<init>");
assertEquals(info.getQuantifier(), "*");
assertEquals(info.getDesc(), "");
assertEquals(info.toString(), "<init>*");

info = new MemberInfo("", "<init>", "*", "()V");
assertNotNull(info);
assertEquals(info.getType(), MemberType.METHOD);
assertEquals(info.getOwner(), "");
assertEquals(info.getName(), "<init>");
assertEquals(info.getQuantifier(), "*");
assertEquals(info.getDesc(), "()V");
assertEquals(info.toString(), "<init>*");
}
}

0 comments on commit c5d1beb

Please sign in to comment.