@@ -33,42 +33,112 @@ public InsnList getReplacement(ClassNode classNode, MethodNode methodNode, Strin
3333 if (args .length != 1 || args [0 ].getSort () != Type .ARRAY ) {
3434 final int argCount = args .length ;
3535 if (argCount == 0 ) {
36+ //
3637 replacement .add (new MethodInsnNode (
3738 Opcodes .INVOKESTATIC ,
3839 "java/util/Collections" ,
3940 "emptyList" ,
4041 "()Ljava/util/List;"
4142 ));
43+ // List
4244 return replacement ;
4345 } else if (argCount == 1 ) {
46+ // Object
4447 replacement .add (new MethodInsnNode (
4548 Opcodes .INVOKESTATIC ,
4649 "java/util/Collections" ,
4750 "singletonList" ,
48- "(Ljava/lang/Object;)Ljava/util/Set ;"
51+ "(Ljava/lang/Object;)Ljava/util/List ;"
4952 ));
53+ // List
5054 return replacement ;
5155 }
5256
53- final int freeVarIndex = ASMUtil .getFreeVarIndex (methodNode );
57+ final int arrayListIndex = ASMUtil .getFreeVarIndex (methodNode ); // ArrayList
5458
59+ // Object...
5560 replacement .add (new TypeInsnNode (Opcodes .NEW , "java/util/ArrayList" ));
61+ // Object... ArrayList?
5662 replacement .add (new InsnNode (Opcodes .DUP ));
57- replacement .add (new MethodInsnNode (Opcodes .INVOKESPECIAL , "java/util/ArrayList" , "<init>" , "()V" ));
58- replacement .add (new VarInsnNode (Opcodes .ASTORE , freeVarIndex ));
63+ // Object... ArrayList? ArrayList?
64+ replacement .add (new IntInsnNode (Opcodes .SIPUSH , argCount ));
65+ // Object... ArrayList? ArrayList? int
66+ replacement .add (new MethodInsnNode (Opcodes .INVOKESPECIAL , "java/util/ArrayList" , "<init>" , "(I)V" ));
67+ // Object... ArrayList
68+ replacement .add (new VarInsnNode (Opcodes .ASTORE , arrayListIndex ));
69+ // Object...
5970 for (int i = 0 ; i < argCount ; i ++) {
60- replacement .add (new VarInsnNode (Opcodes .ALOAD , freeVarIndex ));
71+ // Object... Object
72+ replacement .add (new MethodInsnNode (
73+ Opcodes .INVOKESTATIC ,
74+ "java/util/Objects" ,
75+ "requireNonNull" ,
76+ "(Ljava/lang/Object;)Ljava/lang/Object;"
77+ ));
78+ // Object... Object
79+ replacement .add (new VarInsnNode (Opcodes .ALOAD , arrayListIndex ));
80+ // Object... Object ArrayList
6181 replacement .add (new InsnNode (Opcodes .SWAP ));
82+ // Object... ArrayList Object
6283 replacement .add (new MethodInsnNode (Opcodes .INVOKEINTERFACE , "java/util/List" , "add" , "(Ljava/lang/Object;)Z" ));
84+ // Object... boolean
6385 replacement .add (new InsnNode (Opcodes .POP ));
86+ // Object...
6487 }
65- replacement .add (new VarInsnNode (Opcodes .ALOAD , freeVarIndex ));
88+ //
89+ replacement .add (new VarInsnNode (Opcodes .ALOAD , arrayListIndex ));
90+ // ArrayList
6691 replacement .add (new InsnNode (Opcodes .DUP ));
92+ // ArrayList ArrayList
6793 replacement .add (new MethodInsnNode (Opcodes .INVOKESTATIC , "java/util/Collections" , "reverse" , "(Ljava/util/List;)V" ));
68- replacement . add ( new MethodInsnNode ( Opcodes . INVOKESTATIC , "java/util/Collections" , "unmodifiableList" , "(Ljava/util/List;)Ljava/util/List;" ));
94+ // ArrayList
6995 } else {
96+ final LabelNode forStart = new LabelNode ();
97+ final LabelNode forEnd = new LabelNode ();
98+ final int iIndex = ASMUtil .getFreeVarIndex (methodNode ); // int
99+
100+ // Object[]
101+ replacement .add (new InsnNode (Opcodes .ICONST_0 ));
102+ // Object[] int
103+ replacement .add (new VarInsnNode (Opcodes .ISTORE , iIndex ));
104+ // Object[]
105+ replacement .add (forStart );
106+ // Object[]
107+ replacement .add (new InsnNode (Opcodes .DUP ));
108+ // Object[] Object[]
109+ replacement .add (new InsnNode (Opcodes .ARRAYLENGTH ));
110+ // Object[] int
111+ replacement .add (new VarInsnNode (Opcodes .ILOAD , iIndex ));
112+ // Object[] int int
113+ replacement .add (new JumpInsnNode (Opcodes .IF_ICMPLE , forEnd ));
114+ // Object[]
115+ replacement .add (new InsnNode (Opcodes .DUP ));
116+ // Object[] Object[]
117+ replacement .add (new VarInsnNode (Opcodes .ILOAD , iIndex ));
118+ // Object[] Object[] int
119+ replacement .add (new IincInsnNode (iIndex , 1 ));
120+ // Object[] Object[]
121+ replacement .add (new InsnNode (Opcodes .AALOAD ));
122+ // Object[] Object
123+ replacement .add (new MethodInsnNode (
124+ Opcodes .INVOKESTATIC ,
125+ "java/util/Objects" ,
126+ "requireNonNull" ,
127+ "(Ljava/lang/Object;)Ljava/lang/Object;"
128+ ));
129+ // Object[] Object
130+ replacement .add (new InsnNode (Opcodes .POP ));
131+ // Object[]
132+ replacement .add (new JumpInsnNode (Opcodes .GOTO , forStart ));
133+
134+ replacement .add (forEnd );
135+ // Object[]
70136 replacement .add (new MethodInsnNode (Opcodes .INVOKESTATIC , "java/util/Arrays" , "asList" , "([Ljava/lang/Object;)Ljava/util/List;" ));
137+ // List
71138 }
139+ // List
140+ replacement .add (new MethodInsnNode (Opcodes .INVOKESTATIC , "java/util/Collections" , "unmodifiableList" , "(Ljava/util/List;)Ljava/util/List;" ));
141+ // List
72142
73143 return replacement ;
74144 }
0 commit comments