Skip to content

Commit a6cfab4

Browse files
committed
Merge pull request DefinitelyTyped#5874 from RedSeal-co/chore/TSD-upstream-for-node-java_103610104
node-java 0.5.4
2 parents a7cf77b + eb56bb5 commit a6cfab4

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

java/java-tests.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
///<reference path="java.d.ts"/>
2+
///<reference path="../bluebird/bluebird.d.ts"/>
3+
4+
import java = require('java');
5+
import BluePromise = require('bluebird');
6+
7+
java.asyncOptions = {
8+
syncSuffix: 'Sync',
9+
asyncSuffix: '',
10+
promiseSuffix: 'P',
11+
promisify: BluePromise.promisify
12+
};
13+
14+
java.registerClientP((): Promise<void> => {
15+
return BluePromise.resolve();
16+
});
17+
18+
interface ProxyFunctions {
19+
[index: string]: Function;
20+
}
21+
22+
java.ensureJvm()
23+
.then(() => {
24+
25+
// java.d.ts does not declare any Java types.
26+
// We can import a java class, but we don't know the shape of the class here, so must use any
27+
var Boolean: any = java.import('java.lang.Boolean');
28+
29+
var functions: ProxyFunctions = {
30+
accept: function(t: any): void { },
31+
andThen: function(after: any): any {}
32+
};
33+
var proxy: any = java.newProxy('java.util.function.Consumer', functions);
34+
});

java/java.d.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Type definitions for java 0.5.4
2+
// Project: https://github.com/joeferner/java
3+
// Definitions by: Jim Lloyd <https://github.com/jimlloyd>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
/// <reference path="../bluebird/bluebird.d.ts" />
7+
/// <reference path="../node/node.d.ts" />
8+
9+
// This is the core API exposed by https://github.com/joeferner/java.
10+
// To get the full power of Typescript with Java, see https://github.com/RedSeal-co/ts-java.
11+
12+
declare module 'java' {
13+
var NodeJavaCore: NodeJavaCore.NodeAPI;
14+
export = NodeJavaCore;
15+
}
16+
17+
declare module NodeJavaCore {
18+
export interface Callback<T> {
19+
(err?: Error, result?: T): void;
20+
}
21+
22+
interface Promisify {
23+
(funct: Function, receiver?: any): Function;
24+
}
25+
26+
interface AsyncOptions {
27+
syncSuffix: string;
28+
asyncSuffix?: string;
29+
promiseSuffix?: string;
30+
promisify?: Promisify;
31+
}
32+
33+
interface ProxyFunctions {
34+
[index: string]: Function;
35+
}
36+
37+
// *NodeAPI* declares methods & members exported by the node java module.
38+
interface NodeAPI {
39+
classpath: string[];
40+
asyncOptions: AsyncOptions;
41+
callMethod(instance: any, className: string, methodName: string, args: any[], callback: Callback<any>): void;
42+
callMethodSync(instance: any, className: string, methodName: string, ...args: any[]): any;
43+
callStaticMethodSync(className: string, methodName: string, ...args: any[]): any;
44+
instanceOf(javaObject: any, className: string): boolean;
45+
registerClient(before: (cb: Callback<void>) => void, after?: (cb: Callback<void>) => void): void;
46+
registerClientP(beforeP: () => Promise<void>, afterP?: () => Promise<void>): void;
47+
ensureJvm(done: Callback<void>): void;
48+
ensureJvm(): Promise<void>;
49+
50+
newShort(val: number): any;
51+
newLong(val: number): any;
52+
newFloat(val: number): any;
53+
newDouble(val: number): any;
54+
55+
import(className: string): any;
56+
newInstance(className: string, ...args: any[]): void;
57+
newInstanceSync(className: string, ...args: any[]): any;
58+
newInstanceP(className: string, ...args: any[]): Promise<any>;
59+
newArray<T>(className: string, arg: any[]): any;
60+
getClassLoader(): any;
61+
62+
newProxy(interfaceName: string, functions: ProxyFunctions): any;
63+
}
64+
}

0 commit comments

Comments
 (0)