@@ -18,12 +18,50 @@ public class TestEnigmaPlugin implements EnigmaPlugin {
18
18
@ Override
19
19
public void init (EnigmaPluginContext ctx ) {
20
20
this .registerParameterNamingService (ctx );
21
+ this .registerFieldNamingService (ctx );
21
22
}
22
23
23
24
private void registerParameterNamingService (EnigmaPluginContext ctx ) {
24
25
ctx .registerService (NameProposalService .TYPE , ctx1 -> new ParameterNameProposalService ());
25
26
}
26
27
28
+ private void registerFieldNamingService (EnigmaPluginContext ctx ) {
29
+ ctx .registerService (NameProposalService .TYPE , ctx2 -> new StringFieldNameProposalService ());
30
+ }
31
+
32
+ public static class StringFieldNameProposalService implements NameProposalService {
33
+ @ Override
34
+ public String getId () {
35
+ return "test:strings" ;
36
+ }
37
+
38
+ @ Override
39
+ public Map <Entry <?>, EntryMapping > getProposedNames (JarIndex index ) {
40
+ EntryIndex entryIndex = index .getIndex (EntryIndex .class );
41
+ Map <Entry <?>, EntryMapping > names = new HashMap <>();
42
+
43
+ int fieldIndex = 0 ;
44
+ for (var field : entryIndex .getFields ()) {
45
+ if (field .getDesc ().toString ().equals ("Ljava/lang/String;" )) {
46
+ names .put (field , this .createMapping ("string" + fieldIndex , TokenType .JAR_PROPOSED ));
47
+ fieldIndex ++;
48
+ }
49
+ }
50
+
51
+ return names ;
52
+ }
53
+
54
+ @ Override
55
+ public boolean isFallback () {
56
+ return true ;
57
+ }
58
+
59
+ @ Override
60
+ public Map <Entry <?>, EntryMapping > getDynamicProposedNames (EntryRemapper remapper , Entry <?> obfEntry , EntryMapping oldMapping , EntryMapping newMapping ) {
61
+ return null ;
62
+ }
63
+ }
64
+
27
65
public static class ParameterNameProposalService implements NameProposalService {
28
66
private static final MethodDescriptor EQUALS_DESC = new MethodDescriptor ("(Ljava/lang/Object;)Z" );
29
67
@@ -41,7 +79,9 @@ public Map<Entry<?>, EntryMapping> getProposedNames(JarIndex index) {
41
79
var param = method .getParameters (entryIndex ).get (0 );
42
80
names .put (param , this .createMapping ("o" , TokenType .JAR_PROPOSED ));
43
81
} else {
44
- for (var param : method .getParameters (entryIndex )) {
82
+ // only propose a name for the first parameter
83
+ if (!method .getParameters (index .getIndex (EntryIndex .class )).isEmpty ()) {
84
+ var param = method .getParameters (entryIndex ).get (0 );
45
85
names .put (param , this .createMapping ("param" + param .getIndex (), TokenType .JAR_PROPOSED ));
46
86
}
47
87
}
0 commit comments