java-bridge 2.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,210 @@
1
+ /**
2
+ * The supported java versions.
3
+ * Your list of supported versions
4
+ * may differ if you use a different
5
+ * version of the jvm shared library.
6
+ */
7
+ export enum JavaVersion {
8
+ /** Java version 1.1 */
9
+ VER_1_1 = '1.1',
10
+ /** Java version 1.2 */
11
+ VER_1_2 = '1.2',
12
+ /** Java version 1.4 */
13
+ VER_1_4 = '1.4',
14
+ /** Java version 1.6 */
15
+ VER_1_6 = '1.6',
16
+ /** Java version 1.8 */
17
+ VER_1_8 = '1.8',
18
+ /** Java version 9 */
19
+ VER_9 = '9',
20
+ /** Java version 10 */
21
+ VER_10 = '10',
22
+ }
23
+
24
+ Object.freeze(JavaVersion);
25
+
26
+ /**
27
+ * Any basic javascript type accepted by this library.
28
+ */
29
+ export declare type BasicType = string | number | boolean | BigInt | null;
30
+
31
+ /**
32
+ * Any java type accepted by this library, except arrays.
33
+ */
34
+ export type BasicOrJavaType = BasicType | JavaObject | JavaConstructor;
35
+
36
+ /**
37
+ * All types accepted by java
38
+ */
39
+ export type JavaType = BasicOrJavaType | BasicOrJavaType[];
40
+
41
+ /**
42
+ * A dummy java object class
43
+ */
44
+ export abstract class JavaObject {}
45
+
46
+ /**
47
+ * A java class proxy class.
48
+ * This only exists for temporarily storing
49
+ * the class name and the java instance
50
+ * to create the actual class from using the
51
+ * {@link JavaClassProxy.getClassConstructor()}
52
+ * function.
53
+ */
54
+ export declare class JavaClassProxy {
55
+ /**
56
+ * The class name
57
+ */
58
+ public 'class.name': string;
59
+
60
+ /**
61
+ * Get the class's constructor
62
+ *
63
+ * @return the java instance proxy constructor
64
+ */
65
+ public getClassConstructor<
66
+ T extends JavaClassType = JavaClassType
67
+ >(): JavaConstructor<T>;
68
+ }
69
+
70
+ export type JavaClassType = typeof JavaClassInstance;
71
+
72
+ /**
73
+ * A java class's constructor
74
+ */
75
+ export type JavaConstructor<T extends JavaClassType = JavaClassType> = T &
76
+ ImportedMembers;
77
+
78
+ /**
79
+ * Any class member imported from java
80
+ */
81
+ export interface ImportedMembers {
82
+ /**
83
+ * Get the java class instance
84
+ */
85
+ get class(): JavaClassInstance;
86
+
87
+ /**
88
+ * Any class member imported.
89
+ * We'll need to use 'any' as any is callable.
90
+ * The actual type would be JavaType | ((...args: JavaType[]) => JavaType | Promise<JavaType>)
91
+ */
92
+ [member: string]: any;
93
+ }
94
+
95
+ /**
96
+ * A constructor type.
97
+ */
98
+ export type Constructor<T> = { new (): T };
99
+
100
+ /**
101
+ * The java instance proxy class.
102
+ * This class actually does all the magic.
103
+ * After it is created, this will just be a constructor
104
+ * with all static methods and properties (the accessible ones)
105
+ * stored in it and ready for use. Once the actual instance
106
+ * using the new operator is created, a new
107
+ * java_instance_proxy instance is created, containing
108
+ * the actual java instance (that thing isn't visible though)
109
+ * and all (visible) non-static class member methods and properties.
110
+ */
111
+ export declare class JavaClassInstance extends JavaObject {
112
+ /**
113
+ * The class proxy class instance
114
+ */
115
+ public static readonly 'class.proxy': JavaClassProxy;
116
+
117
+ /**
118
+ * Create a new java class instance.
119
+ * Async version.
120
+ *
121
+ * @template T the type of this class as a new instance of this class will be returned
122
+ * @param args the arguments to create the instance
123
+ * @return the java_instance_proxy instance
124
+ */
125
+ public static newInstanceAsync(
126
+ this: never,
127
+ ...args: BasicOrJavaType[]
128
+ ): Promise<unknown>;
129
+ public static newInstanceAsync<T extends JavaClassInstance>(
130
+ this: Constructor<T>,
131
+ ...args: BasicOrJavaType[]
132
+ ): Promise<T>;
133
+
134
+ /**
135
+ * Create a new java instance of type
136
+ * java_instance_proxy["class.proxy.instance"]
137
+ *
138
+ * @param args the arguments to create the instance
139
+ */
140
+ public constructor(...args: BasicOrJavaType[]);
141
+
142
+ /**
143
+ * Check if this is an instance of another class.
144
+ * Pass either the name of the other class or the class itself
145
+ * to check if this is an instance of it.
146
+ * Does not overwrite any existing instanceof operator.
147
+ * This uses the native java instanceof operator.
148
+ *
149
+ * ## Example
150
+ * ```ts
151
+ * import { importClass } from 'java-bridge';
152
+ *
153
+ * const JavaString = importClass('java.lang.String');
154
+ * const str = new JavaString('Hello World');
155
+ *
156
+ * str.instanceOf(JavaString); // true
157
+ * str.instanceOf('java.lang.String'); // true
158
+ * str.instanceOf('java.lang.Object'); // true
159
+ * str.instanceOf('java.lang.Integer'); // false
160
+ * ```
161
+ *
162
+ * @param other the class to check if this is an instance of
163
+ * @return true if this is instance of `other`
164
+ */
165
+ public instanceOf<T extends typeof JavaClassInstance>(
166
+ other: string | T
167
+ ): boolean;
168
+
169
+ /**
170
+ * Default java equals implementation.
171
+ * Async call.
172
+ *
173
+ * @param o the object to compare this to
174
+ * @returns true if this matches o
175
+ */
176
+ public equals(o: JavaClassInstance): Promise<boolean>;
177
+
178
+ /**
179
+ * Default java equals implementation.
180
+ * Sync call.
181
+ *
182
+ * @param o the object to compare this to
183
+ * @returns true if this matches o
184
+ */
185
+ public equalsSync(o: JavaClassInstance): boolean;
186
+
187
+ /**
188
+ * Java default toString method.
189
+ * Async call.
190
+ *
191
+ * @returns this as a string
192
+ */
193
+ public toString(): Promise<string>;
194
+
195
+ /**
196
+ * Java default toString method.
197
+ * Sync call.
198
+ *
199
+ * @returns this as a string
200
+ */
201
+ public toStringSync(): string;
202
+
203
+ /**
204
+ * Any class member imported.
205
+ * We'll need to use 'any' as any is callable.
206
+ * The actual type would be JavaType | ((...args: JavaType[]) => JavaType | Promise<JavaType>).
207
+ * Just throwing it out there.
208
+ */
209
+ [member: string]: any;
210
+ }
@@ -0,0 +1,24 @@
1
+ export {
2
+ JavaVersion,
3
+ JavaObject,
4
+ JavaClassInstance,
5
+ JavaClassProxy,
6
+ JavaType,
7
+ JavaConstructor,
8
+ BasicOrJavaType,
9
+ BasicType,
10
+ ImportedMembers,
11
+ JavaClassType,
12
+ Constructor,
13
+ } from './definitions';
14
+ import type * as internal from '../native';
15
+ /**
16
+ * A namespace containing any internal type definitions.
17
+ * Do not actually use anything from this namespace
18
+ * as it only exports types.
19
+ */
20
+ export type { internal };
21
+ export * from './java';
22
+ import * as java from './java';
23
+ export default java;
24
+ export { getJavaLibPath } from '../native';