diff --git a/java/java-tests.ts b/java/java-tests.ts new file mode 100644 index 0000000000..568bd35a8c --- /dev/null +++ b/java/java-tests.ts @@ -0,0 +1,34 @@ +/// +/// + +import java = require('java'); +import BluePromise = require('bluebird'); + +java.asyncOptions = { + syncSuffix: 'Sync', + asyncSuffix: '', + promiseSuffix: 'P', + promisify: BluePromise.promisify +}; + +java.registerClientP((): Promise => { + return BluePromise.resolve(); +}); + +interface ProxyFunctions { + [index: string]: Function; +} + +java.ensureJvm() + .then(() => { + + // java.d.ts does not declare any Java types. + // We can import a java class, but we don't know the shape of the class here, so must use any + var Boolean: any = java.import('java.lang.Boolean'); + + var functions: ProxyFunctions = { + accept: function(t: any): void { }, + andThen: function(after: any): any {} + }; + var proxy: any = java.newProxy('java.util.function.Consumer', functions); + }); diff --git a/java/java.d.ts b/java/java.d.ts new file mode 100644 index 0000000000..87125355da --- /dev/null +++ b/java/java.d.ts @@ -0,0 +1,64 @@ +// Type definitions for java 0.5.4 +// Project: https://github.com/joeferner/java +// Definitions by: Jim Lloyd +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// + +// This is the core API exposed by https://github.com/joeferner/java. +// To get the full power of Typescript with Java, see https://github.com/RedSeal-co/ts-java. + +declare module 'java' { + var NodeJavaCore: NodeJavaCore.NodeAPI; + export = NodeJavaCore; +} + +declare module NodeJavaCore { + export interface Callback { + (err?: Error, result?: T): void; + } + + interface Promisify { + (funct: Function, receiver?: any): Function; + } + + interface AsyncOptions { + syncSuffix: string; + asyncSuffix?: string; + promiseSuffix?: string; + promisify?: Promisify; + } + + interface ProxyFunctions { + [index: string]: Function; + } + + // *NodeAPI* declares methods & members exported by the node java module. + interface NodeAPI { + classpath: string[]; + asyncOptions: AsyncOptions; + callMethod(instance: any, className: string, methodName: string, args: any[], callback: Callback): void; + callMethodSync(instance: any, className: string, methodName: string, ...args: any[]): any; + callStaticMethodSync(className: string, methodName: string, ...args: any[]): any; + instanceOf(javaObject: any, className: string): boolean; + registerClient(before: (cb: Callback) => void, after?: (cb: Callback) => void): void; + registerClientP(beforeP: () => Promise, afterP?: () => Promise): void; + ensureJvm(done: Callback): void; + ensureJvm(): Promise; + + newShort(val: number): any; + newLong(val: number): any; + newFloat(val: number): any; + newDouble(val: number): any; + + import(className: string): any; + newInstance(className: string, ...args: any[]): void; + newInstanceSync(className: string, ...args: any[]): any; + newInstanceP(className: string, ...args: any[]): Promise; + newArray(className: string, arg: any[]): any; + getClassLoader(): any; + + newProxy(interfaceName: string, functions: ProxyFunctions): any; + } +}