From d3b62c000901fd41d529390af1a5d3e815b5c96e Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Fri, 28 Jul 2023 01:49:14 -0700 Subject: [PATCH] handle static methods correctly --- .../codebook/lvt/LvtAssignmentSuggester.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/papermc/codebook/lvt/LvtAssignmentSuggester.java b/src/main/java/io/papermc/codebook/lvt/LvtAssignmentSuggester.java index 785c65e..4016b61 100644 --- a/src/main/java/io/papermc/codebook/lvt/LvtAssignmentSuggester.java +++ b/src/main/java/io/papermc/codebook/lvt/LvtAssignmentSuggester.java @@ -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; @@ -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; } }