Skip to content

Commit

Permalink
Handle isSomething methods that return a bool
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Jul 26, 2023
1 parent e09736a commit 688df27
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/io/papermc/codebook/lvt/LvtAssignmentSuggester.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ private LvtAssignmentSuggester() {}
return suggested;
}

if (insn.desc != null && insn.desc.endsWith(")Z")) { // only handle methods that return booleans
suggested = suggestNameFromIs(methodName);
if (suggested != null) {
return suggested;
}
}

suggested = suggestNameFromAs(methodName);
if (suggested != null) {
return suggested;
Expand Down Expand Up @@ -105,6 +112,18 @@ public static String suggestNameFromRecord(final String methodName) {
}
}

private static @Nullable String suggestNameFromIs(final String methodName) {
if (!methodName.startsWith("is") || methodName.equals("is")) {
return null;
}

if (Character.isUpperCase(methodName.charAt(2))) {
return methodName;
} else {
return null;
}
}

private static @Nullable String suggestNameFromAs(final String methodName) {
if (!methodName.startsWith("as") || methodName.equals("as")) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ getOrCreate,io/paper/Paper,()Ljava/lang/String;,
gettingBetter,io/paper/Paper,()Ljava/lang/String;,
as,io/paper/paper,()Ljava/lang/String;,
ass,io/paper/paper,()Ljava/lang/String;,
is,io/paper/Paper,()Z,
isValid,io/paper/Paper,()Z,isValid
isValid,io/paper/Paper,()Ljava/lang/String;,

0 comments on commit 688df27

Please sign in to comment.