Skip to content

Commit

Permalink
handle static methods correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Jul 28, 2023
1 parent 9de90ff commit d3b62c0
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/main/java/io/papermc/codebook/lvt/LvtAssignmentSuggester.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ private static boolean isStringAllUppercase(final String input) {
// I think it's best to only work with primitive types here, as other types should already have names
// and this dramatically cuts down on the number of methods analyzed because we aren't filtering by
// method name
if (!(method.descriptor().getReturnType() instanceof PrimitiveType)) {
if (!(method.descriptor().getReturnType() instanceof PrimitiveType)
|| !method.params().isEmpty()) {
return null;
}
int opcodeIndex = 0;
Expand All @@ -500,15 +501,21 @@ private static boolean isStringAllUppercase(final String input) {
continue;
}
if (opcodeIndex == OPCODES_IN_ORDER.length) {
return null;
break; // matched the correct order
}
if (OPCODES_IN_ORDER[opcodeIndex].test(methodInsn.getOpcode())) {
opcodeIndex++;
} else {
return null;
}
}
if (opcodeIndex != OPCODES_IN_ORDER.length) {
return null;
if (method.isStatic()) { // limit static matches
if ("java/lang/System".equals(insn.owner) && "currentTimeMillis".equals(insn.name)) {
return "currentTimeMillis";
}
} else {
return method.name();
}
return method.name();
return null;
}
}

0 comments on commit d3b62c0

Please sign in to comment.