@@ -51,6 +51,7 @@ public String generateDtsContent(List<JavaClass> javaClasses) {
51
51
52
52
// process class scope
53
53
for (int i = 0 ; i < javaClasses .size (); i ++) {
54
+ Set <String > methodsSet = new HashSet <>();
54
55
55
56
JavaClass currClass = javaClasses .get (i );
56
57
currentFileClassname = currClass .getClassName ();
@@ -84,7 +85,7 @@ public String generateDtsContent(List<JavaClass> javaClasses) {
84
85
processInterfaceConstructor (currClass , allInterfacesMethods );
85
86
86
87
for (Method m : allInterfacesMethods ) {
87
- processMethod (m , currClass );
88
+ processMethod (m , currClass , methodsSet );
88
89
}
89
90
90
91
for (Field f : allInterfaceFields ) {
@@ -96,7 +97,7 @@ public String generateDtsContent(List<JavaClass> javaClasses) {
96
97
if (fom instanceof Field ) {
97
98
processField ((Field ) fom , currClass );
98
99
} else if (fom instanceof Method ) {
99
- processMethod ((Method ) fom , currClass );
100
+ processMethod ((Method ) fom , currClass , methodsSet );
100
101
} else {
101
102
throw new IllegalArgumentException ("Argument is not method or field" );
102
103
}
@@ -108,10 +109,12 @@ public String generateDtsContent(List<JavaClass> javaClasses) {
108
109
List <JavaClass > allInterfaces = getAllInterfaces (currClass );
109
110
List <Method > allInterfacesMethods = getAllInterfacesMethods (allInterfaces );
110
111
for (Method m : allInterfacesMethods ) {
111
- processMethod (m , currClass );
112
+ processMethod (m , currClass , methodsSet );
112
113
}
113
114
}
114
115
116
+ writeMethods (methodsSet );
117
+
115
118
sbContent .appendln (tabs + "}" );
116
119
if (getSimpleClassname (currClass ).equals ("AccessibilityDelegate" )) {
117
120
String innerClassAlias = "export type " + getSimpleClassname (currClass ) + " = " + getFullClassNameConcatenated (currClass );
@@ -341,7 +344,7 @@ private Set<Field> getAllInterfacesFields(List<JavaClass> interfaces) {
341
344
return allInterfacesFields ;
342
345
}
343
346
//method related
344
- private void processMethod (Method m , JavaClass clazz ) {
347
+ private void processMethod (Method m , JavaClass clazz , Set < String > methodsSet ) {
345
348
String name = m .getName ();
346
349
347
350
// TODO: Pete: won't generate static initializers as invalid typescript properties
@@ -355,34 +358,43 @@ private void processMethod(Method m, JavaClass clazz) {
355
358
356
359
cacheMethodBySignature (m ); //cached in "mapNameMethod"
357
360
358
-
359
361
//generate base method content
360
362
if (baseMethodNames .contains (name )) {
361
363
for (Method bm : baseMethods ) {
362
364
if (bm .getName ().equals (name )) {
363
365
String sig = getMethodFullSignature (bm );
364
366
if (!mapNameMethod .containsKey (sig )) {
365
367
mapNameMethod .put (sig , bm );
366
- generateMethodContent (clazz , tabs , bm );
368
+ methodsSet . add ( generateMethodContent (clazz , tabs , bm ) );
367
369
}
368
370
}
369
371
}
370
372
}
371
373
372
- generateMethodContent (clazz , tabs , m );
374
+ methodsSet . add ( generateMethodContent (clazz , tabs , m ) );
373
375
}
374
376
375
- private void generateMethodContent (JavaClass clazz , String tabs , Method m ) {
376
- sbContent .append (tabs + "public " );
377
+ private String generateMethodContent (JavaClass clazz , String tabs , Method m ) {
378
+ StringBuilder2 sbTemp = new StringBuilder2 ();
379
+ sbTemp .append (tabs + "public " );
377
380
if (m .isStatic ()) {
378
- sbContent .append ("static " );
381
+ sbTemp .append ("static " );
379
382
}
380
- sbContent .append (getMethodName (m ) + getMethodParamSignature (clazz , m ));
383
+ sbTemp .append (getMethodName (m ) + getMethodParamSignature (clazz , m ));
381
384
String bmSig = "" ;
382
385
if (!isConstructor (m )) {
383
386
bmSig += ": " + getTypeScriptTypeFromJavaType (clazz , m .getReturnType ());
384
387
}
385
- sbContent .appendln (bmSig + ";" );
388
+
389
+ sbTemp .append (bmSig + ";" );
390
+
391
+ return sbTemp .toString ();
392
+ }
393
+
394
+ private void writeMethods (Set <String > methodsSet ) {
395
+ for (String m : methodsSet ) {
396
+ sbContent .appendln (m );
397
+ }
386
398
}
387
399
388
400
private void cacheMethodBySignature (Method m ) {
0 commit comments