6
6
import net .cvs0 .mappings .generators .MethodNameGenerator ;
7
7
8
8
import java .util .HashMap ;
9
+ import java .util .HashSet ;
9
10
import java .util .Map ;
10
11
import java .util .Set ;
11
12
@@ -42,6 +43,10 @@ public void generateClassMappings(Set<String> classNames)
42
43
43
44
public void generateFieldMapping (String owner , String fieldName , String descriptor )
44
45
{
46
+ if (fieldName == null ) {
47
+ return ;
48
+ }
49
+
45
50
if (shouldRenameField (owner , fieldName )) {
46
51
String key = owner + "." + fieldName ;
47
52
String newName = fieldNameGenerator .generateName (owner , fieldName , descriptor );
@@ -56,6 +61,10 @@ public void setInheritanceTracker(InheritanceTracker inheritanceTracker)
56
61
57
62
public void generateMethodMapping (String owner , String methodName , String descriptor )
58
63
{
64
+ if (methodName == null ) {
65
+ return ;
66
+ }
67
+
59
68
if (shouldRenameMethod (owner , methodName , descriptor )) {
60
69
String key = owner + "." + methodName + descriptor ;
61
70
@@ -72,38 +81,59 @@ public void generateMethodMapping(String owner, String methodName, String descri
72
81
73
82
private void propagateMethodRename (String owner , String methodName , String descriptor , String newName )
74
83
{
84
+ Set <String > allRelatedClasses = new HashSet <>();
85
+
75
86
if (inheritanceTracker .isInterface (owner )) {
76
- Set <String > implementors = inheritanceTracker .getImplementorsOf (owner );
77
- for (String implementor : implementors ) {
78
- String implKey = implementor + "." + methodName + descriptor ;
79
- if (!methodMappings .containsKey (implKey )) {
80
- methodMappings .put (implKey , newName );
81
- }
82
- }
87
+ allRelatedClasses .addAll (inheritanceTracker .getImplementorsOf (owner ));
83
88
} else {
84
- Set <String > subclasses = inheritanceTracker .getAllSubclasses (owner );
85
- for (String subclass : subclasses ) {
86
- String subKey = subclass + "." + methodName + descriptor ;
87
- if (!methodMappings .containsKey (subKey )) {
88
- methodMappings .put (subKey , newName );
89
+ allRelatedClasses .addAll (inheritanceTracker .getAllSubclasses (owner ));
90
+ allRelatedClasses .addAll (inheritanceTracker .getAllSuperclasses (owner ));
91
+ allRelatedClasses .addAll (inheritanceTracker .getAllInterfaces (owner ));
92
+ }
93
+
94
+ for (String relatedClass : allRelatedClasses ) {
95
+ String relatedKey = relatedClass + "." + methodName + descriptor ;
96
+ if (!methodMappings .containsKey (relatedKey )) {
97
+ methodMappings .put (relatedKey , newName );
98
+ }
99
+ }
100
+
101
+ if (!inheritanceTracker .isInterface (owner )) {
102
+ Set <String > interfaces = inheritanceTracker .getAllInterfaces (owner );
103
+ for (String iface : interfaces ) {
104
+ Set <String > implementors = inheritanceTracker .getImplementorsOf (iface );
105
+ for (String implementor : implementors ) {
106
+ String implKey = implementor + "." + methodName + descriptor ;
107
+ if (!methodMappings .containsKey (implKey )) {
108
+ methodMappings .put (implKey , newName );
109
+ }
89
110
}
90
111
}
91
112
}
92
113
}
93
114
94
115
public String getClassMapping (String className )
95
116
{
117
+ if (className == null ) {
118
+ return null ;
119
+ }
96
120
return classMappings .getOrDefault (className , className );
97
121
}
98
122
99
123
public String getFieldMapping (String owner , String fieldName )
100
124
{
125
+ if (fieldName == null ) {
126
+ return null ;
127
+ }
101
128
String key = owner + "." + fieldName ;
102
129
return fieldMappings .getOrDefault (key , fieldName );
103
130
}
104
131
105
132
public String getMethodMapping (String owner , String methodName , String descriptor )
106
133
{
134
+ if (methodName == null ) {
135
+ return null ;
136
+ }
107
137
String key = owner + "." + methodName + descriptor ;
108
138
return methodMappings .getOrDefault (key , methodName );
109
139
}
@@ -134,7 +164,7 @@ private boolean shouldRenameClass(String className)
134
164
}
135
165
136
166
String packageScope = config .getPackageScope ();
137
- if (packageScope != null && !packageScope .isEmpty ()) {
167
+ if (packageScope != null && !packageScope .isEmpty () && className != null ) {
138
168
return className .startsWith (packageScope );
139
169
}
140
170
@@ -143,6 +173,10 @@ private boolean shouldRenameClass(String className)
143
173
144
174
private boolean shouldRenameField (String owner , String fieldName )
145
175
{
176
+ if (fieldName == null ) {
177
+ return false ;
178
+ }
179
+
146
180
if (!config .isRenameFields ()) {
147
181
return false ;
148
182
}
@@ -156,6 +190,10 @@ private boolean shouldRenameField(String owner, String fieldName)
156
190
157
191
private boolean shouldRenameMethod (String owner , String methodName , String descriptor )
158
192
{
193
+ if (methodName == null ) {
194
+ return false ;
195
+ }
196
+
159
197
if (!config .isRenameMethods ()) {
160
198
return false ;
161
199
}
@@ -164,11 +202,15 @@ private boolean shouldRenameMethod(String owner, String methodName, String descr
164
202
return false ;
165
203
}
166
204
167
- if (methodName .equals ("<init>" ) || methodName .equals ("<clinit>" )) {
205
+ if (methodName != null && (methodName .equals ("<init>" ) || methodName .equals ("<clinit>" ))) {
206
+ return false ;
207
+ }
208
+
209
+ if (methodName != null && methodName .startsWith ("lambda$" )) {
168
210
return false ;
169
211
}
170
212
171
- if (methodName . startsWith ( "lambda$" )) {
213
+ if (methodName != null && ( methodName . equals ( "values" ) || methodName . equals ( "valueOf" ) || methodName . equals ( "$values" ) )) {
172
214
return false ;
173
215
}
174
216
0 commit comments