NativeScript / android-dts-generator

A tool that generates TypeScript declaration files (.d.ts) from Jars
90 stars 23 forks source link

Error on Iterable and other generics and base-classes #35

Closed derchirurg closed 6 years ago

derchirurg commented 6 years ago

I'm trying to write a plugin for PDFBox-Android. I am running the tool with a slightly modified jar (because namespace functions is invalid).

When I compile my typescript files, everything is fine. But when I run the plugin (with npm run demo.android), I am getting the following errors:

../src/platforms/android/typings/pdfbox-android.d.ts:1611:19 - error TS2720: Class 'PairData0Format0' incorrectly implements class 'Comparator<Array<number>>'. Did you mean to extend 'Comparator<Array<number>>' and inherit its members as a subclass?
  Property 'equals' is missing in type 'PairData0Format0'.

1611                            export class PairData0Format0 extends com.tom_roush.fontbox.ttf.KerningSubtable.PairData implements java.util.Comparator<native.Array<number>>  {
                                             ~~~~~~~~~~~~~~~~

../src/platforms/android/typings/pdfbox-android.d.ts:4714:18 - error TS2720: Class 'COSArray' incorrectly implements class 'Iterable<COSBase>'. Did you mean to extend 'Iterable<COSBase>' and inherit its members as a subclass?
  Property 'wait' is missing in type 'COSArray'.

4714                    export class COSArray extends com.tom_roush.pdfbox.cos.COSBase implements java.lang.Iterable<com.tom_roush.pdfbox.cos.COSBase>  {
                                     ~~~~~~~~

../src/platforms/android/typings/pdfbox-android.d.ts:5034:18 - error TS2720: Class 'COSName' incorrectly implements class 'Comparable<COSName>'. Did you mean to extend 'Comparable<COSName>' and inherit its members as a subclass?
  Property 'wait' is missing in type 'COSName'.

5034                    export class COSName extends com.tom_roush.pdfbox.cos.COSBase implements java.lang.Comparable<com.tom_roush.pdfbox.cos.COSName>  {
                                     ~~~~~~~

../src/platforms/android/typings/pdfbox-android.d.ts:7309:33 - error TS2314: Generic type 'List<E>' requires 1 type argument(s).

7309                            public writeTokens(param0: java.util.List): void;
                                                           ~~~~~~~~~~~~~~

../src/platforms/android/typings/pdfbox-android.d.ts:7463:32 - error TS2314: Generic type 'List<E>' requires 1 type argument(s).

7463                            public setThreads(param0: java.util.List): void;
                                                          ~~~~~~~~~~~~~~

../src/platforms/android/typings/pdfbox-android.d.ts:11087:31 - error TS2314: Generic type 'List<E>' requires 1 type argument(s).

11087                                   public setPages(param0: java.util.List): void;
                                                                ~~~~~~~~~~~~~~

../src/platforms/android/typings/pdfbox-android.d.ts:11099:38 - error TS2314: Generic type 'List<E>' requires 1 type argument(s).

11099                                   public setEmbeddedFDFs(param0: java.util.List): void;
                                                                       ~~~~~~~~~~~~~~

../src/platforms/android/typings/pdfbox-android.d.ts:11192:33 - error TS2314: Generic type 'List<E>' requires 1 type argument(s).

11192                                   public setOptions(param0: java.util.List): void;
                                                                  ~~~~~~~~~~~~~~

../src/platforms/android/typings/pdfbox-android.d.ts:17568:33 - error TS2314: Generic type 'List<E>' requires 1 type argument(s).

17568                           public static sort(param0: java.util.List): void;
                                                           ~~~~~~~~~~~~~~

../src/platforms/android/typings/pdfbox-android.d.ts:17569:33 - error TS2314: Generic type 'List<E>' requires 1 type argument(s).

17569                           public static sort(param0: java.util.List, param1: java.util.Comparator): void;
                                                           ~~~~~~~~~~~~~~

../src/platforms/android/typings/pdfbox-android.d.ts:17569:57 - error TS2314: Generic type 'Comparator<T>' requires 1 type argument(s).

17569                           public static sort(param0: java.util.List, param1: java.util.Comparator): void;
                                                                                   ~~~~~~~~~~~~~~~~~~~~

Can someone tell me how to fix them? I really need the typings.

vtrifonov commented 6 years ago

Can you give some more details. How do you run the dts-generator, what arguments are you passing? You will need to look at the complex typings generation. The thing is that there are classes extending native classes, so you need to pass both Super class jars(-super) and Input generics(-input-generics) so that the tool will know what methods have the super class to add them in the inheritor. The easiest way will be to pass the following additional parameters to the dts generator:

java -jar dts-generator/build/libs/dts-generator.jar -input dts-generator/jar-files/pdfbox-android.aar -input-generics libs/generics.txt -super ${ANDROID_HOME}/platforms/android-17/android.jar

Using that approach I've generated the following typings file pdfbox.android.d.ts.zip (note that it needs tns-platform-declarations as it references the android typings from there).

We've improved the ignored namespaces functionality not to generate classes from an ignored namespace and com.tom_roush.pdfbox.pdmodel.common.function is added to the list of ignored ones as we cannot generate a working typings for it.

I hope this helps! Please let me know if this works for you!

derchirurg commented 6 years ago

This seems to work. I can run the demo with the compiled jar. Thank you very much!

derchirurg commented 6 years ago

@vtrifonov This seems to work for me. Thank you very much.