GithubHelp home page GithubHelp logo

nativescript / android-dts-generator Goto Github PK

View Code? Open in Web Editor NEW
90.0 29.0 22.0 9.38 MB

A tool that generates TypeScript declaration files (.d.ts) from Jars

Java 93.66% Batchfile 0.03% Makefile 6.31%
android typescript typings generator

android-dts-generator's Introduction

Android d.ts Generator

A tool that generates TypeScript declaration files (.d.ts) from Jars/Aars

Because there are certain incompatibilities between Java and TypeScript, definitions MAY NOT always be completely accurate. They will however compile and provide auto complete feature inside a modern text editor supporting typings.

Quirks

  • Interfaces are represented by classes, this will allow you to extend them by using the new syntax, as well as show you all its members that need to be implemented
  • Classes from the package java.util.function don't have their typings generated, as function is a reserved keyword in TypeScript and JavaScript
  • Classes returning values of Type in the package java.util.function will return any instead
  • Classes using methods with parameters of Type in the package java.util.function will take any instead
  • Classes implementing java.util.Iterator, android.animation.TypeEvaluator, java.lang.Comparable do not implement those interfaces in the generated definitions for compatibility-related issues

Prerequisites

Generate definitions following any of the approaches described below. Once you have run any of commands, you can find the generated typings in dts-generator/out directory.

Generate definitons for Android SDK

cd dts-generator
./gradlew jar
java -jar build/libs/dts-generator.jar -input %ANDROID_HOME%/platforms/android-<Platform Level (21/22/23/24)>/android.jar

Generate definitions for any Jar/Aar

cd dts-generator
./gradlew jar
java -jar build/libs/dts-generator.jar -input <Path to your Jar/Aar>

Pass multiple jars/aars to generator

cd dts-generator
./gradlew jar
java -jar build/libs/dts-generator.jar -input <jar1> <jar2> <jar3>

Another option is to pass the folder containing the jars you want to pass

cd dts-generator
./gradlew jar
java -jar build/libs/dts-generator.jar -input <jarFolder>

Note: Check the Makefile for sample usage

Test

In order to test the tool there are some predefined androuidx packages. We are running the tool and comparing the output with the expected output commited in the repo. To run the test:

make test-compare-output

Then check whether the make command will return an error comparing the files.

Note: If the libs folder content is changed, the expected output should also be changed

Generate definitions for .aar

Pass the aar as input as you would normally do

Complex typings generation

Generating the typings corresponding to the android and android-support jar files is a bit tricky operation, so here's a detailed explanation how to do it. There are different andoid support versions and they depend on main android classes it is a little bit complicated to generate those typings. One option is to generate a big d.ts file with all the libraries inside. The downside of this approach is that you have to generate a big file for every API level and if the android support version is changed all those d.ts files need to be regenerated. To avoid this there's some functionality in the tool for passing dependencies when generating typings. There are two type of dependencies that can be passed:

  1. Super class jars - this is needed when the current jar has classes which are extending classes from another jar file, but we don't want to have all that jar files' typings in a single output file. To achieve this we can provide the super class jar with the super argument(which works the same way as input for multiple files). For instance if we want to generate typings for android.support.v4.view.ViewPager and we don't pass the super classes jar the generated typings won't extend any class as there's no information in the jar that contains the ViewPager. However this class extends android.view.ViewGroup class which is a part of the android jar file(any of the API levels). So if we pass one of the android.jar files as a super class jar file the generated typing will contain extends android.view.ViewGroup.
  2. Input generics - When trying to get the type of a parameter which is a generic class we cannot really get the generic types of that class, so we cannot generate working typings. To fix this we are adding information about the generics of each package at the end of the file with comments starting with //Generics information:. So to fix this we need to provide a file with all the generic information for the packages the current jar relies on. You need to create a file and copy all the generic informations of the related packages and provide it in the input-generics argument. This will make all the generic classes referenced without passing types to pass any so that the ouput will be valid.

Adding all implements for generic types

There is an option all-generic-implements which is disabled by default which controls whether to add implements for all interfaces (if they are more than one) to generic type declarations. The problem is that in most of the cases one of those interfaces is actually an extend, so it should be manual reviewed and fixed after generation.

Finding package dependencies

If you want to generate typings of a package but you are not sure how you can get all the needed dependencies you can follow the steps bellow:

  1. Open dts-generator/build.gradle file and locate dependencies part.

  2. Add as a testCompileOnly dependency the one that you want to generate typings for:

    dependencies {
        implementation 'org.apache.bcel:bcel:6.2'
        implementation 'commons-io:commons-io:2.6'
        implementation 'com.google.code.findbugs:findbugs:3.0.1'
    
        // add your dependency bellow
        testCompileOnly  "com.android.support:support-v4:27.0.1"
    }
  3. Open the dts-generator folder in your terminal

  4. Run the following command:

    ./gradlew extractAllJars
    
  5. The command above will get the needed jar files for your dependency and will output them in the dts-generator/jar-files folder (or you can optionaly pass another output folder -PjarsOutput=another-folder)

  6. You can run the following command to check what are the dependencies between the packages:

    ./gradlew dependencies --configuration testCompileOnly
    
  7. Run the dts-generator tool passing as input arguments the path to the output jars folder

Androidx specifics

To get all the jar files for androidx follow the steps above. You can find the jar files for androidx 1.0.0 in the current repository As androidx needs the base android jar file to create its typings you need to pass the android.jar file as a super parameter to the generator. To avoid having typings for every different API level you can reuse typings built with API level 17 for all API levels until 23. It's quite easy to test this:

  1. Run the typings generator for androidx passing android-17/android.jar as a supper jar
  2. Add /// <reference path="android-17.d.ts"/> at the top of the generated typings file where android-17.d.ts is the typings file of the android API level 17
  3. Run tsc passing the generated typings file and there shouldn't be errors
  4. Now start replacing the reference file with the files from other API level while the tsc execution completes with no error
  5. If there's an error this means that you need to generate the android support typings with the same android API level super jar

By repeating the steps above we've found that:

  • Androidx 17 typings(built with supper jar from android API 17) can be reused until android API 22
  • Androidx 23 typings(built with supper jar from android API 23) can be reused until android API 25
  • Androidx 26 typings(built with supper jar from android API 26) can be reused for API 26 and 27

The corresponding typings files can be found in the tns-platform-declarations package. The repo's Makefile can be used as a reference for creating these typings files

android-dts-generator's People

Contributors

adjenkov avatar eddyverbruggen avatar farfromrefug avatar kazemihabib avatar manoldonev avatar mukaschultze avatar nathanaela avatar nathanwalker avatar nickiliev avatar panayotcankov avatar petekanev avatar plamen5kov avatar ptomato avatar rigor789 avatar roblav96 avatar tgpetrov avatar triniwiz avatar vtrifonov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-dts-generator's Issues

Error in generated .d.ts file

I generated d.ts file for java.util, and paytm android sdk, both giving few errors in the file

app/item/android.d.ts(18,8): error TS2300: Duplicate identifier 'javalangThrowable'.

app/item/android.d.ts(18,28): error TS2503: Cannot find namespace 'java'.

app/item/android.d.ts(133,22): error TS2503: Cannot find namespace 'java'.
app/item/android.d.ts(153,26): error TS2503: Cannot find namespace 'android'.
app/item/android.d.ts(154,30): error TS2503: Cannot find namespace 'android'.
app/item/android.d.ts(155,35): error TS2503: Cannot find namespace 'android'.
app/item/android.d.ts(181,32): error TS2503: Cannot find namespace 'android'.

app/item/android.d.ts(283,24): error TS2503: Cannot find namespace 'java'.
app/item/android.d.ts(284,29): error TS2503: Cannot find namespace 'java'.
app/item/android.d.ts(340,28): error TS2503: Cannot find namespace 'java'.
app/item/android.d.ts(362,31): error TS2503: Cannot find namespace 'android'.
app/item/android.d.ts(363,32): error TS2503: Cannot find namespace 'android'.
app/item/android.d.ts(364,39): error TS2503: Cannot find namespace 'android'.
app/item/android.d.ts(365,33): error TS2503: Cannot find namespace 'android'.
app/item/items.component.ts(113,24): error TS2339: Property 'java' does not exist on type 'typeof com'.

app/item/java-util/java.util.d.ts(2,8): error TS2300: Duplicate identifier 'javalangThrowable'.

app/item/java-util/java.util.d.ts(2,28): error TS2503: Cannot find namespace 'java'.
app/item/java-util/java.util.d.ts(16,28): error TS2503: Cannot find namespace 'java'.
app/item/java-util/java.util.d.ts(69,22): error TS2503: Cannot find namespace 'java'.
app/item/java-util/java.util.d.ts(85,25): error TS2503: Cannot find namespace 'java'.
app/item/java-util/java.util.d.ts(86,29): error TS2503: Cannot find namespace 'java'.
app/item/java-util/java.util.d.ts(106,29): error TS2503: Cannot find namespace 'java'.
app/item/java-util/java.util.d.ts(107,28): error TS2503: Cannot find namespace 'java'.

app/item/java-util/java.util.d.ts(108,29): error TS2503: Cannot find namespace 'java'.

TypeScript compiler failed with exit code 1

DtsApi.getInterfaces - Exception in thread "main" java.lang.NullPointerException

This happens with only a few jar files, but I get this error when throwing them through the dts-generator:

Exception in thread "main" java.lang.NullPointerException
	at com.telerik.dts.DtsApi.getInterfaces(DtsApi.java:352)
	at com.telerik.dts.DtsApi.generateDtsContent(DtsApi.java:75)
	at com.telerik.dts.Generator.generateDts(Generator.java:37)
	at com.telerik.dts.Generator.start(Generator.java:29)
	at com.telerik.Main.main(Main.java:21)

I've found that adding a check if clazz1 != null allows the generator to work.
JavaClass clazz1 = ClassRepo.findClass(intface);
The fix source:
roblav96@1dae532#diff-84b371273f2d411517c3ef4981518716

Jar Examples

Download jars here:
https://drive.google.com/file/d/0BzsNfWSNiUKLRlNOWkctb1JvZ1E/view?usp=sharing

OneSignal

java -jar dts-generator-debug.jar \
-input android24.jar \
-input android-support-v4.jar \
-input android-support-v7-appcompat.jar \
-input amazon-device-messaging-1.0.1.jar \
-input OneSignalSDK.jar \
-generate-multiple

materialdrawer

java -jar dts-generator.jar \
-input android24.jar \
-input android-support-v4.jar \
-input android-support-v7-appcompat.jar \
-input android-support-v7-recyclerview.jar \
-input materialize-1.0.0.jar \
-input materialdrawer-5.7.0.jar \
-generate-multiple

remove ofuscated classes

It would be best to remove offuscated classes because they create a lot of TS errors because they use private words.

Check for changed method signatures in inherited types

We do not need to generate entries for methods in inherited types if the signature hasn't changed. For example:

class A {
    public void method1() {
    }
}

class B extends A {
    @Override
    public method1() {
        super.method1();
        // extended logic
    }
}

In the above case we do not need to generate signature for method1 in class B. This will improve the size of the generated definitions.

Recover method parameter names for generated files

Replacing getMethodParamSignature with the below (it's a drop-in backwards-compatible replacement) means that most parameter names are recovered (rather than being param0, param1 etc).

I'd do a pull request if I knew how :)

private String getMethodParamSignature(JavaClass clazz, TypeDefinition typeDefinition, Method m) {

    LocalVariableTable table = m.getLocalVariableTable();

    StringBuilder sb = new StringBuilder();
    sb.append("(");
    int idx = 0;
    for (Type type : this.getArgumentTypes(m)) {
        if (idx > 0) {
            sb.append(", ");
        }
        int localVarIndex;
        if (!m.isStatic()) {
            localVarIndex = idx + 1;

        } else {
            localVarIndex = idx;
        }
        if (table != null && table.getLocalVariable(localVarIndex, 0) != null) {
            sb.append(table.getLocalVariable(localVarIndex, 0).getName());
        } else {
            sb.append("param");
            sb.append(idx);
        }
        idx+=1;
        sb.append(": ");

        String paramTypeName = getTypeScriptTypeFromJavaType(type, typeDefinition);

        // TODO: Pete:
        if (paramTypeName.startsWith("java.util.function")) {
            sb.append("any /* " + paramTypeName + "*/");
        } else {
            addReference(type);
            sb.append(paramTypeName);
        }
    }
    sb.append(")");
    String sig = sb.toString();
    return sig;
}

Type inheritance is not considered in the generated output

Currently the generated files do not reflect any base types. For example:

declare module android {
    export module view {
        export class ViewGroup {

Should be:

declare module android {
    export module view {
        export class ViewGroup extends android.view.View{

Importing dependencies for a .jar file

TLDR

How do I import all the dependencies required for a jar file I'm setting as input?

First I want to say, this repository is a game changer for debugging native Android plugins. I'm using it to see exactly what APIs are exposed to TypeScript for any .jar file.

For example, here's a gist of the BoltsFramework/Bolts-Android bolts.Task.d.ts.

I'm having an issue with dts-generator.jar and detecting dependentcies for the input jar file.

Example:

java -jar dts-generator.jar -input bolts-tasks-1.4.0.jar

Error:

Exception in thread "main" java.lang.NoClassDefFoundError: Couldn't find class: java.lang.Exception required by class: bolts.AggregateException. You need to provide the jar containing the missing class: java.lang.Exception

What I've been doing so far is adding android.jar from $ANDROID_HOME/platforms/android-23/android.jar and adding it to an input like so:

java -jar dts-generator.jar -input android.jar -input bolts-tasks-1.4.0.jar -generate-multiple

Which most of the time results in a working output of *.d.ts files.

Although sometimes for example,

java -jar dts-generator.jar -input android.jar -input OneSignalSDK.jar -generate-multiple

Errors

Exception in thread "main" java.lang.NoClassDefFoundError: Couldn't find class: com.amazon.device.messaging.ADMMessageHandlerBase required by class: com.onesignal.ADMMessageHandler. You need to provide the jar containing the missing class: com.amazon.device.messaging.ADMMessageHandlerBase

Since the android.jar file does not contain com.amazon.device classes.

How do I import all the dependencies required for a jar file I'm setting as input?

Classes don't expose static fields from interfaces

Hi,

I'm using the aforementioned experimental build option and it is quite handy.

What I noticed though is that if there is an inheritance then it is not possible to access the base class field from the derived class. Say, Android has the Telephony.Sms.Inbox.BODY where Inbox is

public static final class Inbox implements BaseColumns, TextBasedSmsColumns

and BODY is defined in the TextBasedSmsColumns. What ends up generated is:

export class Inbox extends java.lang.Object implements android.provider.BaseColumns, android.provider.Telephony.TextBasedSmsColumns {
					public static CONTENT_URI: android.net.Uri;
					public static DEFAULT_SORT_ORDER: string;
				} 

and basically an attempt to use in a native-like way android.provider.Telephony.Sms.Inbox.BODY fails, instead I need to do android.provider.Telephony.TextBasedSmsColumns.BODY.

Something you may want to check out and some point :)

Thank you!

P.S.: also keeping the original parameter names instead of paramX would have been nice, though I guess that's in the works too :)

Input aar file type support

How would I go about using an aar file instead of jar? I'd like to input play-services-maps-9.4.0.aar into the dts-generator.

Updating definitions to arbitrary android sdk version

I'm trying to update my tns-platform-declarations to use the latest android sdk.

I've generated the definitions for the respective sdks and replaced the include in tns-platform-declarations/android/android.d.ts to use the generated file (currently android23.d.ts).

Problem is I now get - among others, including a lot of duplicate identifiers - a million error TS2503: Cannot find namespace 'native'., which tells me not everything has been extracted. Where do I go from here? The sdk declaration files have wildly differing sizes:

-rw-rw-r-- 1 yule yule 13777754 Apr 25 13:17 android17.d.ts # Original file
-rw-rw-r-- 1 yule yule  4686196 Apr 25 14:20 android20.d.ts
-rw-rw-r-- 1 yule yule  5191200 Apr 25 14:20 android21.d.ts
-rw-rw-r-- 1 yule yule  5214515 Apr 25 14:20 android22.d.ts
-rw-rw-r-- 1 yule yule  5006948 Apr 25 14:20 android23.d.ts
-rw-rw-r-- 1 yule yule 17178798 Apr 25 14:19 android24.d.ts
-rw-rw-r-- 1 yule yule  5730638 Apr 25 13:17 android25.d.ts

Which tells me I'm probably doing something wrong.

Do I have to include anything else?

whats the location that .d.ts file gets saved ?

Hi,
i tried to generate .d.ts file for java-util-1.3.1, and the command i have given is

java -jar build\libs\dts-generator.jar -input g:\ java-util-1.3.1
Generation of definition took 10ms.

  • where that generated .d.ts file will be located ?
  • can i have to give the extension as .jar in input ?? like java-util-1.3.1.jar

[Windows] gradlew extractAllJars fails due to invalid symbols in file paths

Windows only issue. Steps to reproduce:

Set a library with testCompileOnly

testCompileOnly  "com.android.support:support-v4:27.0.1"

Execute

$ ./gradlew extractAllJars

Result:

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\repositories\android-dts-generator\dts-generator\build.gradle' line: 62

* What went wrong:
Execution failed for task ':extractAllJars'.
> Illegal char <:> at index 45: jar-files\support-v4.aar (com.android.support:support-v4:27.0.1)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
1 actionable task: 1 executed

Update readme

  • Describe generation of androidX instead of android support
  • Add more details about the Makefile in the beginning

Add tests

The generated TS definitions are currently generated manually and tested with tsc, we can automate that work by passing various android/java libraries and testing compilability of the output.

Invalid byte tag in constant pool: 19

Hello friends ,
I am getting following error while generating typings.

java -jar build/libs/dts-generator.jar -input ../jars/opencv-platform-4.0.1-1.5.jar
Android d.ts Generator Version : 2.0.0
Exception in thread "main" org.apache.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 19
	at org.apache.bcel.classfile.Constant.readConstant(Constant.java:161)
	at org.apache.bcel.classfile.ConstantPool.<init>(ConstantPool.java:69)
	at org.apache.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:235)
	at org.apache.bcel.classfile.ClassParser.parse(ClassParser.java:143)
	at com.telerik.dts.JarFile.readJar(JarFile.java:45)
	at com.telerik.dts.Generator.loadJavaClasses(Generator.java:98)
	at com.telerik.dts.Generator.start(Generator.java:38)
	at com.telerik.Main.main(Main.java:37)

./gradlew jar not working

Wanted to clone this to geenrate typings for my own Android library (to be used in a NativeScript plugin)
Steps to reproduce

git clone https://github.com/NativeScript/android-dts-generator.git
cd android-dts-generator

cd dts-generator/
./gradlew jar

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/adriann/Developer/android-dts-generator/dts-generator/build.gradle' line: 14

* What went wrong:
A problem occurred evaluating root project 'dts-generator'.
> /Users/adriann/Developer/android-dts-generator/dts-generator/gradle.properties (No such file or directory)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 483ms

It seems gradle.properties is missing.

some classes are missing there parent class

building typings for androidx :

testCompileOnly  "com.google.android.material:material:1.0.0"

then using

java -jar build/libs/dts-generator.jar --skip-declarations -input dts-generator/jar-files

Some genearted classes are missing their parent class. Example com.google.android.material.textfield.TextInputLayout or com.google.android.material.textfield.TextInputEditText

If you fix it by adding the extends you end up with some incompatible method declarations compared to parent class.

Error on Iterable and other generics and base-classes

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.

Support generic (non-Android) uses

I've been using this for development with Rhino (JS engine in Java) which provides access to Java libraries.

I had to manually hack the output somewhat (there's no concept of Native.Array for example)

It would be great if there was an option to make the generator produce more "vanilla" Typescript definitions. Any chance?

I can possibly help with the implementation.

Classes java.* do not include dots between them eg. javalangObject

Recently updated to the latest generator and I'm noticing that many times java.* classes do not include periods.

I notice you create a reference outside the module declarations but most of the time they are not included:

import javaniocharsetCharset = java.nio.charset.Charset;
declare module okhttp3 {
	export class MediaType extends javalangObject { // SHOULD BE java.lang.Object
		public type(): string;
		public subtype(): string;
		public charset(): javaniocharsetCharset;
		public hashCode(): number;
		public charset(param0: javaniocharsetCharset): javaniocharsetCharset;
		public static parse(param0: string): okhttp3.MediaType;
		public equals(param0: javalangObject): boolean; // SHOULD BE java.lang.Object
		public toString(): string;
	}
}

Java class with static member and public nested/inner class collide

Java class with static member named B, and a nested/inner class of the same name - B will collide, and not let TSC to compile.

Consider the following Java class, which is completely valid:

public class A {
 public static A.B B;

 public class B {
   // ...
 }
}

While the Java compiler can tell whether the static member is used, or the class, that same intention cannot be translated easily to JavaScript, and the TypeScript compiler complains with Duplicate identifier errors.

Real scenario - the com.google.android.gms.cast.Cast API:

declare module com {
	export module google {
		export module android {
			export module gms {
				export module cast {
					export class Cast extends javalangObject {
						// ...
						public static CastApi: com.google.android.gms.cast.Cast.CastApi;
					}
					export module Cast {
						export class CastApi extends javalangObject {
							// ...
                        }
                    }
                }
            }
        }
    }
}

We could try to read if the current class has nested/inner classes, and omit writing methods/fields with the same names.

Resolve generics properly and don't include unnamed modules

The AppCues SDK demonstrates a great case of conditions to consider to improve the typing generation.

If types are generated the following issues will be seen:

  • generics that aren't resolve to proper class name
  • unnamed modules nested within other named packages
  • some other generic related cases

Error when trying to generate definitions

I'm trying to generate definitions like described in the docs:

Generate definitons for Android SDK

cd dts-generator
./gradlew jar
java -jar build/libs/dts-generator.jar -input %ANDROID_HOME%/platforms/android-<Platform Level (21/22/23/24)>/android.jar
[17:22:36] hettiger:android-dts-generator git:(master*) $ cd dts-generator
[17:22:46] hettiger:dts-generator git:(master*) $ ./gradlew jar

BUILD SUCCESSFUL in 0s
3 actionable tasks: 3 up-to-date
[17:22:51] hettiger:dts-generator git:(master*) $ java -jar build/libs/dts-generator.jar -input ${ANDROID_HOME}/platforms/android-28/android.jar
Android d.ts Generator Version : 2.0.0
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/bcel/classfile/FieldOrMethod
	at com.telerik.dts.Generator.start(Generator.java:34)
	at com.telerik.Main.main(Main.java:37)
Caused by: java.lang.ClassNotFoundException: org.apache.bcel.classfile.FieldOrMethod
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 2 more

Am I doing something wrong here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.