Skip to content

Commit 54af033

Browse files
committed
add fix for default methods not being inherited by children
1 parent b1a3ec0 commit 54af033

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

dts-generator/src/main/java/com/telerik/dts/DtsApi.java

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java.util.ArrayList;
1414
import java.util.Arrays;
15+
import java.util.Collection;
1516
import java.util.HashMap;
1617
import java.util.HashSet;
1718
import java.util.LinkedList;
@@ -92,7 +93,7 @@ public String generateDtsContent(List<JavaClass> javaClasses) {
9293
processInterfaceConstructor(currClass, allInterfacesMethods);
9394

9495
for(Method m : allInterfacesMethods) {
95-
processMethod(m, currClass, methodsSet);
96+
processMethod(m, currClass, isInterface, methodsSet);
9697
}
9798

9899
for(Field f : allInterfaceFields) {
@@ -104,19 +105,28 @@ public String generateDtsContent(List<JavaClass> javaClasses) {
104105
if (fom instanceof Field) {
105106
processField((Field) fom, currClass);
106107
} else if (fom instanceof Method) {
107-
processMethod((Method) fom, currClass, methodsSet);
108+
processMethod((Method) fom, currClass, isInterface, methodsSet);
108109
} else {
109110
throw new IllegalArgumentException("Argument is not method or field");
110111
}
111112
}
112113
// process member scope end
113114
}
114115

115-
if(isAbstract && !isInterface) {
116-
List<JavaClass> allInterfaces = getAllInterfaces(currClass);
116+
if(!isInterface) {
117+
HashSet<JavaClass> allInterfaces = new HashSet<>(getAllInterfaces(currClass));
118+
119+
List<JavaClass> allClasses = getAllSuperClasses(currClass);
120+
121+
// Include interfaces of extended classes
122+
for(JavaClass jclass: allClasses) {
123+
allInterfaces.addAll(getInterfaces(jclass));
124+
}
125+
117126
List<Method> allInterfacesMethods = getAllInterfacesMethods(allInterfaces);
127+
118128
for(Method m : allInterfacesMethods) {
119-
processMethod(m, currClass, methodsSet);
129+
processMethod(m, currClass, isInterface, methodsSet);
120130
}
121131
}
122132

@@ -309,6 +319,27 @@ private List<JavaClass> getAllInterfaces(JavaClass classInterface) {
309319
return interfaces;
310320
}
311321

322+
private List<JavaClass> getAllSuperClasses(JavaClass clazz) {
323+
ArrayList<JavaClass> classes = new ArrayList<>();
324+
325+
Queue<JavaClass> classQueue = new LinkedList<>();
326+
classQueue.add(clazz);
327+
328+
while(!classQueue.isEmpty()) {
329+
JavaClass currClazz = classQueue.poll();
330+
331+
if (currClazz.getClassName().equals("java.lang.Object")) {
332+
break;
333+
}
334+
335+
classes.add(currClazz);
336+
337+
classQueue.add(getSuperClass(currClazz));
338+
}
339+
340+
return classes;
341+
}
342+
312343
private List<JavaClass> getInterfaces(JavaClass classInterface) {
313344
List<JavaClass> interfaces = new ArrayList<>();
314345

@@ -331,7 +362,7 @@ private List<JavaClass> getInterfaces(JavaClass classInterface) {
331362
return interfaces;
332363
}
333364

334-
private List<Method> getAllInterfacesMethods(List<JavaClass> interfaces) {
365+
private List<Method> getAllInterfacesMethods(Collection<JavaClass> interfaces) {
335366
ArrayList<Method> allInterfacesMethods = new ArrayList<>();
336367

337368
for(JavaClass clazz : interfaces) {
@@ -352,7 +383,7 @@ private Set<Field> getAllInterfacesFields(List<JavaClass> interfaces) {
352383
return allInterfacesFields;
353384
}
354385
//method related
355-
private void processMethod(Method m, JavaClass clazz, Set<String> methodsSet) {
386+
private void processMethod(Method m, JavaClass clazz, boolean isInterface, Set<String> methodsSet) {
356387
String name = m.getName();
357388

358389
if (m.isSynthetic() || (!m.isPublic() && !m.isProtected())) {
@@ -377,21 +408,23 @@ private void processMethod(Method m, JavaClass clazz, Set<String> methodsSet) {
377408
String sig = getMethodFullSignature(bm);
378409
if (!mapNameMethod.containsKey(sig)) {
379410
mapNameMethod.put(sig, bm);
380-
methodsSet.add(generateMethodContent(clazz, tabs, bm));
411+
methodsSet.add(generateMethodContent(clazz, isInterface, tabs, bm));
381412
}
382413
}
383414
}
384415
}
385416

386-
methodsSet.add(generateMethodContent(clazz, tabs, m));
417+
methodsSet.add(generateMethodContent(clazz, isInterface, tabs, m));
387418
}
388419

389-
private String generateMethodContent(JavaClass clazz, String tabs, Method m) {
420+
private String generateMethodContent(JavaClass clazz, boolean isInterface, String tabs, Method m) {
390421
StringBuilder2 sbTemp = new StringBuilder2();
391422
sbTemp.append(tabs + "public ");
423+
392424
if (m.isStatic()) {
393425
sbTemp.append("static ");
394426
}
427+
395428
sbTemp.append(getMethodName(m) + getMethodParamSignature(clazz, m));
396429
String bmSig = "";
397430
if (!isConstructor(m)) {

0 commit comments

Comments
 (0)