10
10
import java .util .Set ;
11
11
import java .util .logging .Level ;
12
12
13
+ import de .oceanlabs .mcp .mcinjector .data .Parameters ;
13
14
import org .objectweb .asm .ClassVisitor ;
14
15
import org .objectweb .asm .MethodVisitor ;
15
16
import org .objectweb .asm .Opcodes ;
21
22
22
23
import de .oceanlabs .mcp .mcinjector .MCInjector ;
23
24
import de .oceanlabs .mcp .mcinjector .MCInjectorImpl ;
24
- import de .oceanlabs .mcp .mcinjector .data .Constructors ;
25
25
import de .oceanlabs .mcp .mcinjector .data .Exceptions ;
26
26
27
27
public class ApplyMap extends ClassVisitor
28
28
{
29
29
String className ;
30
+ boolean isEnum ;
30
31
MCInjectorImpl injector ;
31
32
32
33
public ApplyMap (MCInjectorImpl injector , ClassVisitor cn )
@@ -39,6 +40,7 @@ public ApplyMap(MCInjectorImpl injector, ClassVisitor cn)
39
40
public void visit (int version , int access , String name , String signature , String superName , String [] interfaces )
40
41
{
41
42
this .className = name ;
43
+ isEnum = (access & Opcodes .ACC_ENUM ) != 0 ;
42
44
super .visit (version , access , name , signature , superName , interfaces );
43
45
}
44
46
@@ -95,9 +97,11 @@ private void processLVT(String cls, String name, String desc, MethodNode mn)
95
97
{
96
98
List <String > params = new ArrayList <>();
97
99
List <Type > types = new ArrayList <>();
100
+ boolean isStatic = true ;
98
101
99
102
if ((mn .access & Opcodes .ACC_STATIC ) == 0 )
100
103
{
104
+ isStatic = false ;
101
105
types .add (Type .getType ("L" + cls + ";" ));
102
106
params .add (0 , "this" );
103
107
}
@@ -109,11 +113,12 @@ private void processLVT(String cls, String name, String desc, MethodNode mn)
109
113
return ;
110
114
111
115
MCInjector .LOG .fine (" Generating map:" );
112
- String nameFormat = "p_" + name + "_%d_" ;
116
+ String nameFormat = null ;
113
117
if (name .matches ("func_\\ d+_.+" )) // A srg name method params are just p_MethodID_ParamIndex_
114
118
nameFormat = "p_" + name .substring (5 , name .indexOf ('_' , 5 )) + "_%s_" ;
115
- else if (name .equals ("<init>" )) // Every constructor is given a unique ID, try to load the ID from the map, if none is found assign a new one
116
- nameFormat = "p_i" + Constructors .INSTANCE .getID (className , desc , types .size () > 1 ) + "_%s_" ;
119
+ else if (!isSynthetic (mn ))
120
+ nameFormat = "p_" + Parameters .INSTANCE .getName (className , name , desc , types .size () > params .size (), isStatic ) + "_%s_" ; //assign new name only if there are names remaining
121
+ else nameFormat = "p_%s_" ; //don't really care about synthetics
117
122
118
123
for (int x = params .size (), y = x ; x < types .size (); x ++)
119
124
{
@@ -190,4 +195,18 @@ else if (tmp.getType() != AbstractInsnNode.LABEL)
190
195
191
196
Collections .sort (mn .localVariables , (o1 , o2 ) -> o1 .index < o2 .index ? -1 : (o1 .index == o2 .index ? 0 : 1 ));
192
197
}
198
+
199
+ private boolean isSynthetic (MethodNode mn ){
200
+ if ((mn .access & Opcodes .ACC_SYNTHETIC ) != 0 ) return true ;
201
+
202
+ //check for special case pursuant to JLS 13.1.7
203
+ //which specifies that are the one and only proper methods that may be generated and not be marked synthetic
204
+ if (isEnum && (mn .access & Opcodes .ACC_STATIC ) != 0 ) {
205
+ if ("valueOf" .equals (mn .name ) && mn .desc .equals ("(Ljava/lang/String;)L" + className + ";" ))
206
+ return true ;
207
+ if ("values" .equals (mn .name ) && mn .desc .equals ("()[L" + className + ";" ))
208
+ return true ;
209
+ }
210
+ return false ;
211
+ }
193
212
}
0 commit comments