9
9
import java .io .PrintStream ;
10
10
import java .util .ArrayDeque ;
11
11
import java .util .ArrayList ;
12
+ import java .util .Arrays ;
12
13
import java .util .HashMap ;
13
14
import java .util .HashSet ;
14
15
import java .util .List ;
@@ -141,6 +142,9 @@ private Binding[] processRows(List<DataRow> rows) throws IOException {
141
142
String classname = dataRow .getBaseClassname ();
142
143
boolean isJavaExtend = classes .containsKey (classname );
143
144
if (isJavaExtend ) {
145
+
146
+ // System.out.println("SBG: DataRow: baseClassName: " + classname + ", suffix: " + dataRow.getSuffix() + ", interfaces: " + String.join(", ", Arrays.asList(dataRow.getInterfaces())) + ", jsFileName: " + dataRow.getJsFilename());
147
+
144
148
Binding binding = generateBinding (dataRow , interfaceNames );
145
149
146
150
if (binding != null ) {
@@ -187,42 +191,56 @@ private String getNormalizedName(String filename) {
187
191
private Map <String , List <Method >> getPublicApi (JavaClass clazz ) {
188
192
Map <String , List <Method >> api = new HashMap <String , List <Method >>();
189
193
JavaClass currentClass = clazz ;
194
+ String clazzName = clazz .getClassName ();
190
195
while (true ) {
191
196
String currentClassname = currentClass .getClassName ();
192
- List <Method > methods = new ArrayList <Method >();
193
- for (Method m : currentClass .getMethods ()) {
194
- methods .add (m );
195
- }
196
- collectInterfaceMethods (clazz , methods );
197
- for (Method m : methods ) {
198
- if (!m .isSynthetic () && (m .isPublic () || m .isProtected ()) && !m .isStatic ()) {
199
- String name = m .getName ();
200
-
201
- List <Method > methodGroup ;
202
- if (api .containsKey (name )) {
203
- methodGroup = api .get (name );
204
- } else {
205
- methodGroup = new ArrayList <Method >();
206
- api .put (name , methodGroup );
207
- }
208
- boolean found = false ;
209
- String methodSig = m .getSignature ();
210
- for (Method m1 : methodGroup ) {
211
- found = methodSig .equals (m1 .getSignature ());
212
- if (found ) {
213
- break ;
197
+
198
+ boolean shouldCollectMethods = !(!clazzName .equals (currentClassname ) && currentClass .isAbstract ());
199
+
200
+ if (shouldCollectMethods || currentClass .isInterface ()) {
201
+ // Don't include abstract parent class's methods to avoid compilation issues
202
+ // where a child class has 2 methods, of the same type, with just a
203
+ // return type/parameter type that differs by being of a superclass of the class being extended.
204
+ // see Test testCanCompileBindingClassExtendingAnExtendedClassWithMethodsWithTheSameSignature
205
+ List <Method > methods = new ArrayList <Method >();
206
+ for (Method m : currentClass .getMethods ()) {
207
+ methods .add (m );
208
+ }
209
+
210
+ // System.out.println("SBG: getPublicApi:collectInterfaceMethods classname: " + currentClassname);
211
+
212
+ collectInterfaceMethods (clazz , methods );
213
+ for (Method m : methods ) {
214
+ if (!m .isSynthetic () && (m .isPublic () || m .isProtected ()) && !m .isStatic ()) {
215
+ String name = m .getName ();
216
+
217
+ List <Method > methodGroup ;
218
+ if (api .containsKey (name )) {
219
+ methodGroup = api .get (name );
220
+ } else {
221
+ methodGroup = new ArrayList <Method >();
222
+ api .put (name , methodGroup );
223
+ }
224
+ boolean found = false ;
225
+ String methodSig = m .getSignature ();
226
+ for (Method m1 : methodGroup ) {
227
+ found = methodSig .equals (m1 .getSignature ());
228
+ if (found ) {
229
+ break ;
230
+ }
231
+ }
232
+ if (!found ) {
233
+ methodGroup .add (m );
214
234
}
215
- }
216
- if (!found ) {
217
- methodGroup .add (m );
218
235
}
219
236
}
220
237
}
221
238
222
239
if (currentClassname .equals ("java.lang.Object" )) {
223
240
break ;
224
241
} else {
225
- currentClass = classes .get (currentClass .getSuperclassName ());
242
+ String superClassName = currentClass .getSuperclassName ();
243
+ currentClass = classes .get (superClassName .replace ('$' , '.' ));
226
244
}
227
245
}
228
246
return api ;
@@ -640,6 +658,7 @@ private void writeType(Type t, Writer w) {
640
658
641
659
private void collectInterfaceMethods (JavaClass clazz , List <Method > methods ) {
642
660
JavaClass currentClass = clazz ;
661
+
643
662
while (true ) {
644
663
String currentClassname = currentClass .getClassName ();
645
664
@@ -663,7 +682,8 @@ private void collectInterfaceMethods(JavaClass clazz, List<Method> methods) {
663
682
if (currentClassname .equals ("java.lang.Object" )) {
664
683
break ;
665
684
} else {
666
- currentClass = classes .get (currentClass .getSuperclassName ());
685
+ String superClassName = currentClass .getSuperclassName ();
686
+ currentClass = classes .get (superClassName .replace ('$' , '.' ));
667
687
}
668
688
}
669
689
}
@@ -686,7 +706,8 @@ private boolean isApplicationClass(JavaClass clazz, Map<String, JavaClass> class
686
706
break ;
687
707
}
688
708
689
- currentClass = classes .get (currentClass .getSuperclassName ());
709
+ String superClassName = currentClass .getSuperclassName ();
710
+ currentClass = classes .get (superClassName .replace ('$' , '.' ));
690
711
}
691
712
692
713
return isApplicationClass ;
0 commit comments