66import net .cvs0 .mappings .generators .MethodNameGenerator ;
77
88import java .util .HashMap ;
9+ import java .util .HashSet ;
910import java .util .Map ;
1011import java .util .Set ;
1112
@@ -42,6 +43,10 @@ public void generateClassMappings(Set<String> classNames)
4243
4344 public void generateFieldMapping (String owner , String fieldName , String descriptor )
4445 {
46+ if (fieldName == null ) {
47+ return ;
48+ }
49+
4550 if (shouldRenameField (owner , fieldName )) {
4651 String key = owner + "." + fieldName ;
4752 String newName = fieldNameGenerator .generateName (owner , fieldName , descriptor );
@@ -56,6 +61,10 @@ public void setInheritanceTracker(InheritanceTracker inheritanceTracker)
5661
5762 public void generateMethodMapping (String owner , String methodName , String descriptor )
5863 {
64+ if (methodName == null ) {
65+ return ;
66+ }
67+
5968 if (shouldRenameMethod (owner , methodName , descriptor )) {
6069 String key = owner + "." + methodName + descriptor ;
6170
@@ -72,38 +81,59 @@ public void generateMethodMapping(String owner, String methodName, String descri
7281
7382 private void propagateMethodRename (String owner , String methodName , String descriptor , String newName )
7483 {
84+ Set <String > allRelatedClasses = new HashSet <>();
85+
7586 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 ));
8388 } 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+ }
89110 }
90111 }
91112 }
92113 }
93114
94115 public String getClassMapping (String className )
95116 {
117+ if (className == null ) {
118+ return null ;
119+ }
96120 return classMappings .getOrDefault (className , className );
97121 }
98122
99123 public String getFieldMapping (String owner , String fieldName )
100124 {
125+ if (fieldName == null ) {
126+ return null ;
127+ }
101128 String key = owner + "." + fieldName ;
102129 return fieldMappings .getOrDefault (key , fieldName );
103130 }
104131
105132 public String getMethodMapping (String owner , String methodName , String descriptor )
106133 {
134+ if (methodName == null ) {
135+ return null ;
136+ }
107137 String key = owner + "." + methodName + descriptor ;
108138 return methodMappings .getOrDefault (key , methodName );
109139 }
@@ -134,7 +164,7 @@ private boolean shouldRenameClass(String className)
134164 }
135165
136166 String packageScope = config .getPackageScope ();
137- if (packageScope != null && !packageScope .isEmpty ()) {
167+ if (packageScope != null && !packageScope .isEmpty () && className != null ) {
138168 return className .startsWith (packageScope );
139169 }
140170
@@ -143,6 +173,10 @@ private boolean shouldRenameClass(String className)
143173
144174 private boolean shouldRenameField (String owner , String fieldName )
145175 {
176+ if (fieldName == null ) {
177+ return false ;
178+ }
179+
146180 if (!config .isRenameFields ()) {
147181 return false ;
148182 }
@@ -156,6 +190,10 @@ private boolean shouldRenameField(String owner, String fieldName)
156190
157191 private boolean shouldRenameMethod (String owner , String methodName , String descriptor )
158192 {
193+ if (methodName == null ) {
194+ return false ;
195+ }
196+
159197 if (!config .isRenameMethods ()) {
160198 return false ;
161199 }
@@ -164,11 +202,15 @@ private boolean shouldRenameMethod(String owner, String methodName, String descr
164202 return false ;
165203 }
166204
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$" )) {
168210 return false ;
169211 }
170212
171- if (methodName . startsWith ( "lambda$" )) {
213+ if (methodName != null && ( methodName . equals ( "values" ) || methodName . equals ( "valueOf" ) || methodName . equals ( "$values" ) )) {
172214 return false ;
173215 }
174216
0 commit comments