@idlizer/core 2.0.17 → 2.0.19

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.
Files changed (39) hide show
  1. package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +30 -0
  2. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +154 -0
  3. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +2 -2
  4. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +13 -0
  5. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +118 -0
  6. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +32 -0
  7. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +175 -0
  8. package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +27 -0
  9. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +173 -0
  10. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +1 -1
  11. package/build/lib/src/LibraryInterface.d.ts +2 -0
  12. package/build/lib/src/config.js +14 -0
  13. package/build/lib/src/configMerge.d.ts +2 -0
  14. package/build/lib/src/configMerge.js +42 -0
  15. package/build/lib/src/from-idl/common.d.ts +1 -1
  16. package/build/lib/src/from-idl/common.js +20 -11
  17. package/build/lib/src/idl.d.ts +6 -3
  18. package/build/lib/src/idl.js +14 -10
  19. package/build/lib/src/idlize.d.ts +1 -1
  20. package/build/lib/src/idlize.js +57 -13
  21. package/build/lib/src/index.d.ts +7 -0
  22. package/build/lib/src/index.js +7 -0
  23. package/build/lib/src/options.d.ts +1 -0
  24. package/build/lib/src/peer-generation/LanguageWriters/index.d.ts +2 -0
  25. package/build/lib/src/peer-generation/LanguageWriters/index.js +2 -0
  26. package/build/lib/src/peer-generation/LanguageWriters/nameConvertor.d.ts +25 -0
  27. package/build/lib/src/peer-generation/LanguageWriters/nameConvertor.js +55 -0
  28. package/build/lib/src/peer-generation/LayoutManager.d.ts +15 -0
  29. package/build/lib/src/peer-generation/LayoutManager.js +32 -0
  30. package/build/lib/src/peer-generation/Materialized.d.ts +2 -0
  31. package/build/lib/src/peer-generation/Materialized.js +28 -0
  32. package/build/lib/src/peer-generation/PeerLibrary.d.ts +53 -0
  33. package/build/lib/src/peer-generation/PeerLibrary.js +340 -0
  34. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +1 -0
  35. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +3 -0
  36. package/package.json +2 -2
  37. package/webidl2.js/LICENSE +0 -21
  38. package/webidl2.js/README.md +0 -827
  39. package/webidl2.js/dist/package.json +0 -3
@@ -0,0 +1,30 @@
1
+ import * as idl from '../../idl';
2
+ import { ReferenceResolver } from '../../peer-generation/ReferenceResolver';
3
+ import { IdlNameConvertor, NodeConvertor } from '../nameConvertor';
4
+ export declare class CJTypeNameConvertor implements NodeConvertor<string>, IdlNameConvertor {
5
+ protected resolver: ReferenceResolver;
6
+ constructor(resolver: ReferenceResolver);
7
+ convert(node: idl.IDLNode): string;
8
+ /***** TypeConvertor<string> **********************************/
9
+ convertOptional(type: idl.IDLOptionalType): string;
10
+ convertUnion(type: idl.IDLUnionType): string;
11
+ convertContainer(type: idl.IDLContainerType): string;
12
+ convertNamespace(node: idl.IDLNamespace): string;
13
+ convertInterface(node: idl.IDLInterface): string;
14
+ convertEnum(node: idl.IDLEnum): string;
15
+ convertTypedef(node: idl.IDLTypedef): string;
16
+ convertCallback(type: idl.IDLCallback): string;
17
+ convertMethod(node: idl.IDLMethod): string;
18
+ convertConstant(node: idl.IDLConstant): string;
19
+ convertImport(type: idl.IDLReferenceType, importClause: string): string;
20
+ convertTypeReference(type: idl.IDLReferenceType): string;
21
+ convertTypeParameter(type: idl.IDLTypeParameterType): string;
22
+ convertPrimitiveType(type: idl.IDLPrimitiveType): string;
23
+ private callbackType;
24
+ private productType;
25
+ }
26
+ export declare class CJIDLTypeToForeignStringConvertor extends CJTypeNameConvertor {
27
+ convert(type: idl.IDLNode): string;
28
+ convertPrimitiveType(type: idl.IDLPrimitiveType): string;
29
+ }
30
+ //# sourceMappingURL=CJConvertors.d.ts.map
@@ -0,0 +1,154 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import * as idl from '../../idl';
16
+ import { convertNode, convertType } from '../nameConvertor';
17
+ export class CJTypeNameConvertor {
18
+ constructor(resolver) {
19
+ this.resolver = resolver;
20
+ }
21
+ convert(node) {
22
+ return convertNode(this, node);
23
+ }
24
+ /***** TypeConvertor<string> **********************************/
25
+ convertOptional(type) {
26
+ return `Option<${this.convert(type.type)}>`;
27
+ }
28
+ convertUnion(type) {
29
+ return type.name;
30
+ }
31
+ convertContainer(type) {
32
+ if (idl.IDLContainerUtils.isSequence(type)) {
33
+ return `ArrayList<${convertType(this, type.elementType[0])}>`;
34
+ }
35
+ if (idl.IDLContainerUtils.isRecord(type)) {
36
+ const stringes = type.elementType.slice(0, 2).map(it => convertType(this, it));
37
+ return `Map<${stringes[0]}, ${stringes[1]}>`;
38
+ }
39
+ throw new Error(`IDL type ${idl.DebugUtils.debugPrintType(type)} not supported`);
40
+ }
41
+ convertNamespace(node) {
42
+ throw new Error('Method not implemented.');
43
+ }
44
+ convertInterface(node) {
45
+ return node.name;
46
+ }
47
+ convertEnum(node) {
48
+ return node.name;
49
+ }
50
+ convertTypedef(node) {
51
+ return node.name;
52
+ }
53
+ convertCallback(type) {
54
+ const params = type.parameters.map(it => `${it.name}: ${it.isOptional ? "?" : ""}${this.convert(it.type)}`);
55
+ return `\{(${params.join(", ")}) => ${this.convert(type.returnType)}\}`;
56
+ }
57
+ convertMethod(node) {
58
+ throw new Error('Method not implemented.');
59
+ }
60
+ convertConstant(node) {
61
+ throw new Error('Method not implemented.');
62
+ }
63
+ convertImport(type, importClause) {
64
+ return type.name;
65
+ }
66
+ convertTypeReference(type) {
67
+ if (type.name === "Object")
68
+ return "KPointer";
69
+ const importAttr = idl.getExtAttribute(type, idl.IDLExtendedAttributes.Import);
70
+ if (importAttr) {
71
+ return this.convertImport(type, importAttr);
72
+ }
73
+ // resolve synthetic types
74
+ const decl = this.resolver.resolveTypeReference(type);
75
+ if (decl && idl.isSyntheticEntry(decl)) {
76
+ if (idl.isCallback(decl)) {
77
+ return this.callbackType(decl);
78
+ }
79
+ const entity = idl.getExtAttribute(decl, idl.IDLExtendedAttributes.Entity);
80
+ if (entity) {
81
+ const isTuple = entity === idl.IDLEntity.Tuple;
82
+ return this.productType(decl, isTuple, !isTuple);
83
+ }
84
+ }
85
+ return type.name;
86
+ }
87
+ convertTypeParameter(type) {
88
+ return type.name;
89
+ }
90
+ convertPrimitiveType(type) {
91
+ switch (type) {
92
+ case idl.IDLStringType: return 'String';
93
+ case idl.IDLBooleanType: return 'Bool';
94
+ case idl.IDLNumberType: return 'Float64';
95
+ case idl.IDLUndefinedType: return 'Unit'; // might be wrong
96
+ case idl.IDLI8Type: return 'Int8';
97
+ case idl.IDLU8Type: return 'UInt8';
98
+ case idl.IDLI16Type: return 'Int16';
99
+ case idl.IDLU16Type: return 'UInt16';
100
+ case idl.IDLI32Type: return 'Int32';
101
+ case idl.IDLU32Type: return 'UInt32';
102
+ case idl.IDLI64Type: return 'Int64';
103
+ case idl.IDLU64Type: return 'UInt64';
104
+ case idl.IDLF32Type: return 'Float32';
105
+ case idl.IDLF64Type: return 'Float64';
106
+ case idl.IDLPointerType: return 'UInt64';
107
+ case idl.IDLVoidType: return 'Unit';
108
+ case idl.IDLBufferType: return 'ArrayList<UInt8>';
109
+ }
110
+ throw new Error(`Unsupported IDL primitive ${idl.DebugUtils.debugPrintType(type)}`);
111
+ }
112
+ callbackType(decl) {
113
+ const params = decl.parameters.map(it => `${it.name}: ${it.isOptional ? "?" : ""}${this.convert(it.type)}`);
114
+ return `((${params.join(", ")}) -> ${this.convert(decl.returnType)})`;
115
+ }
116
+ productType(decl, isTuple, includeFieldNames) {
117
+ if (!isTuple)
118
+ throw new Error('Only tuples supported from IDL synthetic types for now');
119
+ return decl.name;
120
+ }
121
+ }
122
+ export class CJIDLTypeToForeignStringConvertor extends CJTypeNameConvertor {
123
+ convert(type) {
124
+ if (idl.isPrimitiveType(type)) {
125
+ switch (type) {
126
+ case idl.IDLStringType: return 'CString';
127
+ }
128
+ }
129
+ if (idl.isContainerType(type)) {
130
+ if (idl.IDLContainerUtils.isSequence(type)) {
131
+ return `CPointer<${this.convert(type.elementType[0])}>`;
132
+ }
133
+ }
134
+ if (idl.isReferenceType(type)) {
135
+ // Fix, actual mapping has to be due to IDLType
136
+ if (super.convert(type).startsWith('Array'))
137
+ return `CPointer<UInt8>`;
138
+ if (super.convert(type) == 'String' || super.convert(type) == 'KStringPtr') {
139
+ return `CString`;
140
+ }
141
+ if (super.convert(type) == 'Object') {
142
+ return `KPointer`;
143
+ }
144
+ }
145
+ return super.convert(type);
146
+ }
147
+ convertPrimitiveType(type) {
148
+ switch (type) {
149
+ case idl.IDLBufferType: return 'CPointer<UInt8>';
150
+ }
151
+ return super.convertPrimitiveType(type);
152
+ }
153
+ }
154
+ //# sourceMappingURL=CJConvertors.js.map
@@ -17,13 +17,13 @@ import { generatorConfiguration } from "../../config";
17
17
  import { InteropConvertor } from '../InteropConvertor';
18
18
  export class CppInteropConvertor extends InteropConvertor {
19
19
  unwrap(type, result) {
20
+ const conf = generatorConfiguration();
20
21
  if (idl.isType(type) && idl.isOptionalType(type)) {
21
- return `Opt_${result.text}`;
22
+ return `${conf.param("OptionalPrefix")}${result.text}`;
22
23
  }
23
24
  if (result.noPrefix) {
24
25
  return result.text;
25
26
  }
26
- const conf = generatorConfiguration();
27
27
  const typePrefix = conf.param("TypePrefix");
28
28
  // TODO remove this ugly hack for CustomObject's
29
29
  const convertedToCustomObject = result.text === idl.IDLCustomObjectType.name;
@@ -0,0 +1,13 @@
1
+ import * as idl from "../../idl";
2
+ import { TSTypeNameConvertor } from "./TSConvertors";
3
+ export declare class ETSTypeNameConvertor extends TSTypeNameConvertor {
4
+ convertTypeReference(type: idl.IDLReferenceType): string;
5
+ convertEnum(node: idl.IDLEnum): string;
6
+ convertContainer(type: idl.IDLContainerType): string;
7
+ convertPrimitiveType(type: idl.IDLPrimitiveType): string;
8
+ protected productType(decl: idl.IDLInterface, isTuple: boolean, includeFieldNames: boolean): string;
9
+ protected processTupleType(idlProperty: idl.IDLProperty): idl.IDLProperty;
10
+ protected mapCallback(decl: idl.IDLCallback): string;
11
+ protected mapFunctionType(typeArgs: string[]): string;
12
+ }
13
+ //# sourceMappingURL=ETSConvertors.d.ts.map
@@ -0,0 +1,118 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import * as idl from "../../idl";
16
+ import { Language } from "../../Language";
17
+ import { createDeclarationNameConvertor } from "../../peer-generation/idl/IdlNameConvertor";
18
+ import { convertDeclaration } from "../nameConvertor";
19
+ import { TSTypeNameConvertor } from "./TSConvertors";
20
+ export class ETSTypeNameConvertor extends TSTypeNameConvertor {
21
+ convertTypeReference(type) {
22
+ // Only to deal with namespaces. TODO: remove later
23
+ const decl = this.resolver.resolveTypeReference(type);
24
+ if (decl && idl.isEnum(decl)) {
25
+ return convertDeclaration(createDeclarationNameConvertor(Language.ARKTS), decl);
26
+ }
27
+ // TODO: Needs to be implemented properly
28
+ const types = type.name.split(".");
29
+ if (types.length > 1) {
30
+ // Takes only name without the namespace prefix
31
+ const decl = this.resolver.resolveTypeReference(idl.createReferenceType(types.slice(-1).join(), undefined, type));
32
+ if (decl !== undefined) {
33
+ return convertDeclaration(createDeclarationNameConvertor(Language.ARKTS), decl);
34
+ }
35
+ }
36
+ const typeName = super.convertTypeReference(type);
37
+ // TODO: Fix for 'TypeError: Type 'Function<R>' is generic but type argument were not provided.'
38
+ if (typeName === "Function") {
39
+ return "Function<void>";
40
+ }
41
+ return typeName;
42
+ }
43
+ convertEnum(node) {
44
+ let ns = idl.getNamespaceName(node).split('.').join('_');
45
+ if (ns !== '') {
46
+ ns += '_';
47
+ }
48
+ return ns + node.name;
49
+ }
50
+ convertContainer(type) {
51
+ if (idl.IDLContainerUtils.isSequence(type)) {
52
+ switch (type.elementType[0]) {
53
+ case idl.IDLU8Type: return 'KUint8ArrayPtr';
54
+ case idl.IDLI32Type: return 'KInt32ArrayPtr';
55
+ case idl.IDLF32Type: return 'KFloat32ArrayPtr';
56
+ }
57
+ return `Array<${this.convert(type.elementType[0])}>`;
58
+ }
59
+ return super.convertContainer(type);
60
+ }
61
+ convertPrimitiveType(type) {
62
+ switch (type) {
63
+ case idl.IDLAnyType: return "object";
64
+ case idl.IDLUnknownType: return "object";
65
+ case idl.IDLPointerType: return 'KPointer';
66
+ case idl.IDLVoidType: return 'void';
67
+ case idl.IDLBooleanType: return 'boolean';
68
+ case idl.IDLU8Type:
69
+ case idl.IDLI8Type:
70
+ case idl.IDLI16Type:
71
+ case idl.IDLU16Type:
72
+ case idl.IDLI32Type:
73
+ case idl.IDLU32Type:
74
+ return 'int32';
75
+ case idl.IDLI64Type:
76
+ case idl.IDLU64Type:
77
+ return 'int64';
78
+ case idl.IDLF32Type:
79
+ return 'float32';
80
+ case idl.IDLF64Type:
81
+ return 'float64';
82
+ case idl.IDLNumberType:
83
+ return 'number';
84
+ case idl.IDLStringType: return 'string';
85
+ case idl.IDLFunctionType: return 'Object';
86
+ case idl.IDLBufferType: return 'NativeBuffer';
87
+ }
88
+ return super.convertPrimitiveType(type);
89
+ }
90
+ productType(decl, isTuple, includeFieldNames) {
91
+ if (decl.subkind === idl.IDLInterfaceSubkind.AnonymousInterface) {
92
+ return decl.name;
93
+ }
94
+ return super.productType(decl, isTuple, includeFieldNames);
95
+ }
96
+ processTupleType(idlProperty) {
97
+ if (idlProperty.isOptional) {
98
+ return Object.assign(Object.assign({}, idlProperty), { isOptional: false, type: idl.createUnionType([idlProperty.type, idl.IDLUndefinedType]) });
99
+ }
100
+ return idlProperty;
101
+ }
102
+ mapCallback(decl) {
103
+ const params = decl.parameters.map(it => {
104
+ return `${it.name}${it.isOptional ? "?" : ""}: ${this.convert(it.type)}`;
105
+ });
106
+ return `((${params.join(",")}) => ${this.convert(decl.returnType)})`;
107
+ }
108
+ mapFunctionType(typeArgs) {
109
+ // Fix for "TypeError: Type 'Function<R>' is generic but type argument were not provided."
110
+ // Replace "Function" to "Function<void>"
111
+ // Use "FunctionN" for ts compatibility
112
+ if (typeArgs.length === 0) {
113
+ typeArgs = [this.convert(idl.IDLVoidType)];
114
+ }
115
+ return `Function${typeArgs.length - 1}<${typeArgs.join(",")}>`;
116
+ }
117
+ }
118
+ //# sourceMappingURL=ETSConvertors.js.map
@@ -0,0 +1,32 @@
1
+ import * as idl from '../../idl';
2
+ import { ReferenceResolver } from '../../peer-generation/ReferenceResolver';
3
+ import { IdlNameConvertor, NodeConvertor } from '../nameConvertor';
4
+ export declare class JavaTypeNameConvertor implements NodeConvertor<string>, IdlNameConvertor {
5
+ private resolver;
6
+ constructor(resolver: ReferenceResolver);
7
+ protected solidConvertor: import("../../util").Lazy<JavaIdlNodeToSolidStringConvertor>;
8
+ convert(node: idl.IDLNode): string;
9
+ convertNamespace(node: idl.IDLNamespace): string;
10
+ convertInterface(node: idl.IDLInterface): string;
11
+ convertEnum(node: idl.IDLEnum): string;
12
+ convertTypedef(node: idl.IDLTypedef): string;
13
+ convertOptional(type: idl.IDLOptionalType): string;
14
+ convertUnion(type: idl.IDLUnionType): string;
15
+ convertContainer(type: idl.IDLContainerType): string;
16
+ convertCallback(type: idl.IDLCallback): string;
17
+ convertMethod(type: idl.IDLMethod): string;
18
+ convertConstant(type: idl.IDLConstant): string;
19
+ convertImport(type: idl.IDLReferenceType, importClause: string): string;
20
+ convertTypeReference(type: idl.IDLReferenceType): string;
21
+ convertTypeParameter(type: idl.IDLTypeParameterType): string;
22
+ convertPrimitiveType(type: idl.IDLPrimitiveType): string;
23
+ private readonly javaPrimitiveToReferenceTypeMap;
24
+ protected maybeConvertPrimitiveType(javaType: string): string;
25
+ private mapTypeName;
26
+ }
27
+ declare class JavaIdlNodeToSolidStringConvertor extends JavaTypeNameConvertor {
28
+ protected solidConvertor: import("../../util").Lazy<this>;
29
+ convertContainer(type: idl.IDLContainerType): string;
30
+ }
31
+ export {};
32
+ //# sourceMappingURL=JavaConvertors.d.ts.map
@@ -0,0 +1,175 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import * as idl from '../../idl';
16
+ import { lazy } from '../../util';
17
+ import { convertNode, convertType } from '../nameConvertor';
18
+ function convertJavaOptional(type) {
19
+ switch (type) {
20
+ case 'boolean': return 'Opt_Boolean';
21
+ case 'double': return 'Opt_Number';
22
+ }
23
+ return type;
24
+ }
25
+ export class JavaTypeNameConvertor {
26
+ constructor(resolver) {
27
+ this.resolver = resolver;
28
+ this.solidConvertor = lazy(() => new JavaIdlNodeToSolidStringConvertor(this.resolver));
29
+ this.javaPrimitiveToReferenceTypeMap = new Map([
30
+ ['byte', 'Byte'],
31
+ ['short', 'Short'],
32
+ ['int', 'Integer'],
33
+ ['float', 'Float'],
34
+ ['double', 'Double'],
35
+ ['boolean', 'Boolean'],
36
+ ['char', 'Character'],
37
+ ]);
38
+ }
39
+ convert(node) {
40
+ const typeString = convertNode(this, node);
41
+ return this.mapTypeName(typeString);
42
+ }
43
+ convertNamespace(node) {
44
+ throw new Error('Method not implemented.'); // TODO: namespace-related-to-rework
45
+ }
46
+ convertInterface(node) {
47
+ if (node.subkind === idl.IDLInterfaceSubkind.Tuple) {
48
+ const javaTypeAliases = node.properties.map(it => convertType(this, idl.maybeOptional(it.type, it.isOptional)));
49
+ return `Tuple_${javaTypeAliases.join('_')}`;
50
+ }
51
+ return node.name;
52
+ }
53
+ convertEnum(node) {
54
+ return node.name;
55
+ }
56
+ convertTypedef(node) {
57
+ return node.name;
58
+ }
59
+ convertOptional(type) {
60
+ return convertJavaOptional(this.convert(type.type));
61
+ }
62
+ convertUnion(type) {
63
+ const aliases = type.types.map(it => convertType(this.solidConvertor.value, it));
64
+ return `Union_${aliases.join('_')}`;
65
+ }
66
+ convertContainer(type) {
67
+ if (idl.IDLContainerUtils.isSequence(type)) {
68
+ const javaType = convertType(this, type.elementType[0]);
69
+ return `${javaType}[]`;
70
+ }
71
+ if (idl.IDLContainerUtils.isRecord(type)) {
72
+ const javaTypes = type.elementType.slice(0, 2).map(it => convertType(this, it)).map(this.maybeConvertPrimitiveType, this);
73
+ return `Map<${javaTypes[0]}, ${javaTypes[1]}>`;
74
+ }
75
+ throw new Error(`IDL type ${idl.DebugUtils.debugPrintType(type)} not supported`);
76
+ }
77
+ convertCallback(type) {
78
+ return `Callback`;
79
+ }
80
+ convertMethod(type) {
81
+ throw new Error('Method not implemented.'); // TODO: namespace-related-to-rework
82
+ }
83
+ convertConstant(type) {
84
+ throw new Error('Method not implemented.'); // TODO: namespace-related-to-rework
85
+ }
86
+ convertImport(type, importClause) {
87
+ return type.name;
88
+ }
89
+ convertTypeReference(type) {
90
+ const importAttr = idl.getExtAttribute(type, idl.IDLExtendedAttributes.Import);
91
+ if (importAttr) {
92
+ return this.convertImport(type, importAttr);
93
+ }
94
+ const decl = this.resolver.resolveTypeReference(type);
95
+ if (decl) {
96
+ const declName = this.convert(decl);
97
+ return declName;
98
+ }
99
+ if (type.name === `Optional`) {
100
+ return convertJavaOptional(idl.printType(type.typeArguments[0]));
101
+ }
102
+ return type.name;
103
+ }
104
+ convertTypeParameter(type) {
105
+ // TODO
106
+ return type.name;
107
+ }
108
+ convertPrimitiveType(type) {
109
+ switch (type) {
110
+ case idl.IDLStringType: return 'String';
111
+ case idl.IDLNumberType: return 'double';
112
+ case idl.IDLBooleanType: return 'boolean';
113
+ case idl.IDLUndefinedType: return 'Ark_Undefined';
114
+ case idl.IDLI8Type: return 'byte';
115
+ case idl.IDLU8Type: return 'byte';
116
+ case idl.IDLI16Type: return 'short';
117
+ case idl.IDLU16Type: return 'short';
118
+ case idl.IDLI32Type: return 'int';
119
+ case idl.IDLU32Type: return 'int';
120
+ case idl.IDLI64Type: return 'long';
121
+ case idl.IDLU64Type: return 'long';
122
+ case idl.IDLF32Type: return 'float';
123
+ case idl.IDLF64Type: return 'double';
124
+ case idl.IDLPointerType: return 'long';
125
+ case idl.IDLVoidType: return 'void';
126
+ case idl.IDLDate: return 'Date';
127
+ case idl.IDLBufferType: return 'byte[]';
128
+ }
129
+ throw new Error(`Unsupported IDL primitive ${idl.DebugUtils.debugPrintType(type)}`);
130
+ }
131
+ maybeConvertPrimitiveType(javaType) {
132
+ if (this.javaPrimitiveToReferenceTypeMap.has(javaType)) {
133
+ return this.javaPrimitiveToReferenceTypeMap.get(javaType);
134
+ }
135
+ return javaType;
136
+ }
137
+ mapTypeName(name) {
138
+ switch (name) {
139
+ case 'KPointer': return 'long';
140
+ case 'KBoolean': return 'boolean';
141
+ case 'KUInt': return 'int';
142
+ case 'int32':
143
+ case 'KInt': return 'int';
144
+ case 'int64':
145
+ case 'KLong': return 'long';
146
+ case 'float32':
147
+ case 'KFloat': return 'float';
148
+ case 'KUint8ArrayPtr': return 'byte[]';
149
+ case 'KInt32ArrayPtr': return 'int[]';
150
+ case 'KFloat32ArrayPtr': return 'float[]';
151
+ // case 'ArrayBuffer': return 'byte[]'
152
+ case 'KStringPtr': return 'String';
153
+ case 'string': return 'String';
154
+ }
155
+ return name;
156
+ }
157
+ }
158
+ class JavaIdlNodeToSolidStringConvertor extends JavaTypeNameConvertor {
159
+ constructor() {
160
+ super(...arguments);
161
+ this.solidConvertor = lazy(() => this);
162
+ }
163
+ convertContainer(type) {
164
+ if (idl.IDLContainerUtils.isSequence(type)) {
165
+ const javaTypeSolid = convertType(this, type.elementType[0]);
166
+ return `Array_${javaTypeSolid}`;
167
+ }
168
+ if (idl.IDLContainerUtils.isRecord(type)) {
169
+ const javaTypeSolids = type.elementType.slice(0, 2).map(it => convertType(this, it)).map(this.maybeConvertPrimitiveType, this);
170
+ return `Map_${javaTypeSolids[0]}_${javaTypeSolids[1]}`;
171
+ }
172
+ throw new Error(`IDL type ${idl.DebugUtils.debugPrintType(type)} not supported`);
173
+ }
174
+ }
175
+ //# sourceMappingURL=JavaConvertors.js.map
@@ -0,0 +1,27 @@
1
+ import * as idl from '../../idl';
2
+ import { ReferenceResolver } from '../../peer-generation/ReferenceResolver';
3
+ import { IdlNameConvertor, NodeConvertor } from '../nameConvertor';
4
+ export declare class TSTypeNameConvertor implements NodeConvertor<string>, IdlNameConvertor {
5
+ protected resolver: ReferenceResolver;
6
+ constructor(resolver: ReferenceResolver);
7
+ convert(node: idl.IDLNode): string;
8
+ convertNamespace(node: idl.IDLNamespace): string;
9
+ convertInterface(node: idl.IDLInterface): string;
10
+ convertEnum(node: idl.IDLEnum): string;
11
+ convertTypedef(node: idl.IDLTypedef): string;
12
+ convertCallback(node: idl.IDLCallback): string;
13
+ convertMethod(node: idl.IDLMethod): string;
14
+ convertConstant(node: idl.IDLConstant): string;
15
+ convertOptional(type: idl.IDLOptionalType): string;
16
+ convertUnion(type: idl.IDLUnionType): string;
17
+ convertContainer(type: idl.IDLContainerType): string;
18
+ convertImport(type: idl.IDLReferenceType, importClause: string): string;
19
+ convertTypeReference(type: idl.IDLReferenceType): string;
20
+ convertTypeParameter(type: idl.IDLTypeParameterType): string;
21
+ convertPrimitiveType(type: idl.IDLPrimitiveType): string;
22
+ protected processTupleType(idlProperty: idl.IDLProperty): idl.IDLProperty;
23
+ protected mapCallback(decl: idl.IDLCallback): string;
24
+ protected productType(decl: idl.IDLInterface, isTuple: boolean, includeFieldNames: boolean): string;
25
+ protected mapFunctionType(typeArgs: string[]): string;
26
+ }
27
+ //# sourceMappingURL=TSConvertors.d.ts.map