3030import io .papermc .codebook .lvt .suggestion .context .method .MethodInsnContext ;
3131import java .util .List ;
3232import org .checkerframework .checker .nullness .qual .Nullable ;
33+ import org .objectweb .asm .tree .AbstractInsnNode ;
34+ import org .objectweb .asm .tree .LineNumberNode ;
35+ import org .objectweb .asm .tree .MethodInsnNode ;
3336
3437/*
3538This matches against methods with a set prefix and trims that prefix off of the
@@ -49,6 +52,32 @@ public class SingleVerbSuggester implements LvtSuggester {
4952 return null ;
5053 }
5154
52- return parseSimpleTypeNameFromMethod (methodName , prefix .length ());
55+ final @ Nullable String newName = handleForLoop (methodName , insn , "getMin" , "getMax" );
56+ return newName != null ? newName : parseSimpleTypeNameFromMethod (methodName , prefix .length ());
57+ }
58+
59+ public static @ Nullable String handleForLoop (
60+ final String methodName , final MethodInsnContext insn , final String minPrefix , final String maxPrefix ) {
61+ @ Nullable String newName = handleForLoopPrefix (methodName , insn .node (), minPrefix , maxPrefix );
62+ if (newName == null ) {
63+ newName = handleForLoopPrefix (methodName , insn .node (), maxPrefix , minPrefix );
64+ }
65+ return newName ;
66+ }
67+
68+ private static @ Nullable String handleForLoopPrefix (
69+ final String methodName , final MethodInsnNode methodInsnNode , final String first , final String second ) {
70+ if (methodName .startsWith (first )) {
71+ @ Nullable
72+ AbstractInsnNode nextInsn = methodInsnNode .getNext (); // look for getMin/MaxXXX call on the same line
73+ while (nextInsn != null && !(nextInsn instanceof LineNumberNode )) {
74+ if (nextInsn instanceof final MethodInsnNode afterMethodInvoke
75+ && afterMethodInvoke .name .startsWith (second )) {
76+ return parseSimpleTypeNameFromMethod (methodName , first .length ());
77+ }
78+ nextInsn = nextInsn .getNext ();
79+ }
80+ }
81+ return null ;
5382 }
5483}
0 commit comments