jsii-pacmak 1.121.0 → 1.123.0
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.
- package/lib/targets/dotnet/nameutils.js +8 -0
- package/lib/targets/java.d.ts +32 -4
- package/lib/targets/java.js +189 -84
- package/lib/util.d.ts +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +3 -3
- package/package.json +10 -10
|
@@ -77,6 +77,14 @@ class DotNetNameUtils {
|
|
|
77
77
|
throw new Error(`Invalid parameter name: ${original}`);
|
|
78
78
|
}
|
|
79
79
|
const name = (0, codemaker_1.toCamelCase)(original);
|
|
80
|
+
if (!name) {
|
|
81
|
+
// toCamelCase will return an empty string from a string like `_(_+)`. Confirm that
|
|
82
|
+
// that is what is happening, then return the original string.
|
|
83
|
+
if (original.match(/^__+$/)) {
|
|
84
|
+
return original;
|
|
85
|
+
}
|
|
86
|
+
throw new Error(`toCamelCase returns an empty string from: ${JSON.stringify(original)}`);
|
|
87
|
+
}
|
|
80
88
|
return this.escapeParameterName(name);
|
|
81
89
|
}
|
|
82
90
|
capitalizeWord(original) {
|
package/lib/targets/java.d.ts
CHANGED
|
@@ -107,16 +107,16 @@ declare class JavaGenerator extends Generator {
|
|
|
107
107
|
protected onInterfaceMethodOverload(ifc: spec.InterfaceType, overload: spec.Method, _originalMethod: spec.Method): void;
|
|
108
108
|
protected onInterfaceProperty(ifc: spec.InterfaceType, prop: spec.Property): void;
|
|
109
109
|
/**
|
|
110
|
-
* Emits a local default implementation for
|
|
111
|
-
*
|
|
112
|
-
*
|
|
110
|
+
* Emits a local default implementation for properties inherited from multiple
|
|
111
|
+
* distinct parent types. This removes the default method dispatch ambiguity
|
|
112
|
+
* that would otherwise exist.
|
|
113
113
|
*
|
|
114
114
|
* @param ifc the interface to be processed.
|
|
115
115
|
|
|
116
116
|
*
|
|
117
117
|
* @see https://github.com/aws/jsii/issues/2256
|
|
118
118
|
*/
|
|
119
|
-
private
|
|
119
|
+
private emitMultiplyInheritedProperties;
|
|
120
120
|
private emitAssemblyPackageInfo;
|
|
121
121
|
private emitSubmodulePackageInfo;
|
|
122
122
|
private emitMavenPom;
|
|
@@ -215,6 +215,34 @@ declare class JavaGenerator extends Generator {
|
|
|
215
215
|
private renderAccessLevel;
|
|
216
216
|
private makeModuleClass;
|
|
217
217
|
private emitModuleFile;
|
|
218
|
+
/**
|
|
219
|
+
* Given a method, return the methods that we should generate implementations for on the $Default interface
|
|
220
|
+
*
|
|
221
|
+
* This can be 0..N:
|
|
222
|
+
*
|
|
223
|
+
* - 0: if the method can be inherited from a parent $Default implementation
|
|
224
|
+
* - 1: if the method cannot be inherited from a parent $Default implementation
|
|
225
|
+
* - N: ah-ha, wait! There can be overloads! And because of a historical bug,
|
|
226
|
+
* we didn't use to generate overloads onto $Default interfaces. So it's possible
|
|
227
|
+
* that we don't generate the "main" implementation, but we do generate its overloads.
|
|
228
|
+
*
|
|
229
|
+
* Technically speaking we only have to account for the bug if the type is from a different
|
|
230
|
+
* assembly (because we know all types from the current assembly will be generated ✨ bugless ✨,
|
|
231
|
+
* but just to keep it simple we'll always do the same thing).
|
|
232
|
+
*
|
|
233
|
+
* We can only get rid of this bug once the oldest dependency package a Java
|
|
234
|
+
* package can be used with definitely has overloaded $Default impls. So that will be a while.
|
|
235
|
+
*/
|
|
236
|
+
private makeDefaultImpls;
|
|
237
|
+
/**
|
|
238
|
+
* Given a method, return the methods that we should generate implementations for on the $Proxy class
|
|
239
|
+
*
|
|
240
|
+
* See `makeDefaultImpls` for the main rationale behind this. The $Proxy class inherits from $Default
|
|
241
|
+
* so technically this could have usually been empty, but we need to account for the possibility that
|
|
242
|
+
* we implement a $Default interface from another assembly that has been generated with a buggy version
|
|
243
|
+
* of pacmak.
|
|
244
|
+
*/
|
|
245
|
+
private makeProxyImpls;
|
|
218
246
|
private emitJsiiInitializers;
|
|
219
247
|
/**
|
|
220
248
|
* Computes the java FQN for a JSII FQN:
|
package/lib/targets/java.js
CHANGED
|
@@ -7,6 +7,7 @@ const clone = require("clone");
|
|
|
7
7
|
const case_utils_1 = require("codemaker/lib/case-utils");
|
|
8
8
|
const crypto_1 = require("crypto");
|
|
9
9
|
const fs = require("fs-extra");
|
|
10
|
+
const reflect = require("jsii-reflect");
|
|
10
11
|
const jsii_rosetta_1 = require("jsii-rosetta");
|
|
11
12
|
const path = require("path");
|
|
12
13
|
const xmlbuilder = require("xmlbuilder");
|
|
@@ -29,6 +30,14 @@ const BUILDER_CLASS_NAME = 'Builder';
|
|
|
29
30
|
const ANN_NOT_NULL = '@org.jetbrains.annotations.NotNull';
|
|
30
31
|
const ANN_NULLABLE = '@org.jetbrains.annotations.Nullable';
|
|
31
32
|
const ANN_INTERNAL = '@software.amazon.jsii.Internal';
|
|
33
|
+
/**
|
|
34
|
+
* Because of a historical bug, $Default interfaces we inherit from might not
|
|
35
|
+
* have all method overloads generated correctly.
|
|
36
|
+
*
|
|
37
|
+
* So when inheriting these, we might need to generate the overloads in
|
|
38
|
+
* subinterfaces/subclasses.
|
|
39
|
+
*/
|
|
40
|
+
const GENERATE_POTENTIALLY_MISING_DEFAULT_OVERLOADS = true;
|
|
32
41
|
/**
|
|
33
42
|
* Build Java packages all together, by generating an aggregate POM
|
|
34
43
|
*
|
|
@@ -58,6 +67,7 @@ class JavaBuilder {
|
|
|
58
67
|
try {
|
|
59
68
|
const tempSourceDir = await this.generateAggregateSourceDir(this.modules, this.options);
|
|
60
69
|
scratchDirs.push(tempSourceDir);
|
|
70
|
+
await resolveMavenVersions(tempSourceDir.directory);
|
|
61
71
|
// Need any old module object to make a target to be able to invoke build, though none of its settings
|
|
62
72
|
// will be used.
|
|
63
73
|
const target = this.makeTarget(this.modules[0], this.options);
|
|
@@ -345,8 +355,22 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
345
355
|
return propertyName;
|
|
346
356
|
}
|
|
347
357
|
if (propertyName === '_') {
|
|
348
|
-
// Slightly different pattern for this one
|
|
349
|
-
|
|
358
|
+
// Slightly different pattern for this one. We used to generate `__` here
|
|
359
|
+
// but it's somewhat likely that people will use `_, __, ___` as multiple
|
|
360
|
+
// indifferent arguments, so we pick a different name.
|
|
361
|
+
//
|
|
362
|
+
// Ideally we would look at the alternative argument names and pick
|
|
363
|
+
// something guaranteed to be unique, but unfortunately the code isn't
|
|
364
|
+
// quite structured that way so we'll pick something unlikely to collide
|
|
365
|
+
// instead.
|
|
366
|
+
//
|
|
367
|
+
// Changing from `__` -> `_under` would be a breaking change if applied to
|
|
368
|
+
// public property names, but most likely this will be used for function
|
|
369
|
+
// parameters (unfortunately the code has been structured in such a way
|
|
370
|
+
// that property and parameter names are strongly tied together, in a way
|
|
371
|
+
// that would take more time to unwind than I care to invest right now),
|
|
372
|
+
// where it doesn't matter.
|
|
373
|
+
return '_under_';
|
|
350
374
|
}
|
|
351
375
|
if (JavaGenerator.RESERVED_KEYWORDS.includes(propertyName)) {
|
|
352
376
|
return `${propertyName}Value`;
|
|
@@ -444,9 +468,9 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
444
468
|
throw new Error('Cannot have generic type arguments to a constructor');
|
|
445
469
|
}
|
|
446
470
|
// NOTE: even though a constructor is technically final and we COULD render covariant types, historically we didn't and I'm not changing it.
|
|
447
|
-
this.code.openBlock(`${initializerAccessLevel} ${cls.name}(${this.renderParameters(method.parameters, types, '
|
|
471
|
+
this.code.openBlock(`${initializerAccessLevel} ${cls.name}(${this.renderParameters(method.parameters, types, 'exact-types')})`);
|
|
448
472
|
this.code.line('super(software.amazon.jsii.JsiiObject.InitializationMode.JSII);');
|
|
449
|
-
this.emitUnionParameterValidation(method.parameters);
|
|
473
|
+
this.emitUnionParameterValidation(method.parameters, 'exact-types');
|
|
450
474
|
this.code.line(`software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this${this.renderMethodCallArguments(method)});`);
|
|
451
475
|
this.code.closeBlock();
|
|
452
476
|
}
|
|
@@ -542,7 +566,7 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
542
566
|
this.code.openBlock(`public${inner} interface ${ifc.name} extends ${bases}`);
|
|
543
567
|
}
|
|
544
568
|
onEndInterface(ifc) {
|
|
545
|
-
this.
|
|
569
|
+
this.emitMultiplyInheritedProperties(ifc);
|
|
546
570
|
if (ifc.datatype) {
|
|
547
571
|
this.emitDataType(ifc);
|
|
548
572
|
}
|
|
@@ -573,7 +597,7 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
573
597
|
});
|
|
574
598
|
this.emitStabilityAnnotations(method);
|
|
575
599
|
const types = this.convertTypes(method.parameters);
|
|
576
|
-
this.code.line(`${typeVarDeclarations(types)}${displayStatic(returnType)} ${methodName}(${this.renderParameters(method.parameters, types, '
|
|
600
|
+
this.code.line(`${typeVarDeclarations(types)}${displayStatic(returnType)} ${methodName}(${this.renderParameters(method.parameters, types, 'exact-types')});`);
|
|
577
601
|
}
|
|
578
602
|
onInterfaceMethodOverload(ifc, overload, _originalMethod) {
|
|
579
603
|
this.onInterfaceMethod(ifc, overload);
|
|
@@ -636,53 +660,37 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
636
660
|
}
|
|
637
661
|
}
|
|
638
662
|
/**
|
|
639
|
-
* Emits a local default implementation for
|
|
640
|
-
*
|
|
641
|
-
*
|
|
663
|
+
* Emits a local default implementation for properties inherited from multiple
|
|
664
|
+
* distinct parent types. This removes the default method dispatch ambiguity
|
|
665
|
+
* that would otherwise exist.
|
|
642
666
|
*
|
|
643
667
|
* @param ifc the interface to be processed.
|
|
644
668
|
|
|
645
669
|
*
|
|
646
670
|
* @see https://github.com/aws/jsii/issues/2256
|
|
647
671
|
*/
|
|
648
|
-
|
|
672
|
+
emitMultiplyInheritedProperties(ifc) {
|
|
649
673
|
if (ifc.interfaces == null || ifc.interfaces.length <= 1) {
|
|
650
674
|
// Nothing to do if we don't have parent interfaces, or if we have exactly one
|
|
651
675
|
return;
|
|
652
676
|
}
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
histogram[name].count += 1;
|
|
660
|
-
}
|
|
661
|
-
return histogram;
|
|
662
|
-
}, {});
|
|
663
|
-
const localProps = new Set(ifc.properties?.map((prop) => prop.name) ?? []);
|
|
664
|
-
for (const { spec, count } of Object.values(inheritedOptionalProps)) {
|
|
665
|
-
if (count < 2 || localProps.has(spec.name)) {
|
|
666
|
-
continue;
|
|
667
|
-
}
|
|
668
|
-
this.onInterfaceProperty(ifc, spec);
|
|
669
|
-
}
|
|
670
|
-
function allOptionalProps(fqn) {
|
|
671
|
-
const type = this.findType(fqn);
|
|
672
|
-
const result = {};
|
|
673
|
-
for (const prop of type.properties ?? []) {
|
|
674
|
-
// Adding artifical "overrides" here for code-gen quality's sake.
|
|
675
|
-
result[prop.name] = { ...prop, overrides: type.fqn };
|
|
676
|
-
}
|
|
677
|
-
// Include optional properties of all super interfaces in the result
|
|
678
|
-
for (const base of type.interfaces ?? []) {
|
|
679
|
-
for (const [name, prop] of Object.entries(allOptionalProps.call(this, base))) {
|
|
680
|
-
if (!(name in result)) {
|
|
681
|
-
result[name] = prop;
|
|
682
|
-
}
|
|
677
|
+
const memberSources = {};
|
|
678
|
+
for (const parent of ifc.interfaces) {
|
|
679
|
+
const type = this.reflectAssembly.system.findInterface(parent);
|
|
680
|
+
for (const prop of type.allProperties) {
|
|
681
|
+
if (!(prop.name in memberSources)) {
|
|
682
|
+
memberSources[prop.name] = {};
|
|
683
683
|
}
|
|
684
|
+
memberSources[prop.name][prop.definingType.fqn] = prop.spec;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
for (const defininingTypes of Object.values(memberSources)) {
|
|
688
|
+
// Ignore our own type
|
|
689
|
+
delete defininingTypes[ifc.fqn];
|
|
690
|
+
const keys = Object.keys(defininingTypes);
|
|
691
|
+
if (keys.length > 1) {
|
|
692
|
+
this.onInterfaceProperty(ifc, defininingTypes[keys[0]]);
|
|
684
693
|
}
|
|
685
|
-
return result;
|
|
686
694
|
}
|
|
687
695
|
}
|
|
688
696
|
emitAssemblyPackageInfo(mod) {
|
|
@@ -1072,7 +1080,7 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1072
1080
|
name: 'value',
|
|
1073
1081
|
type: this.filterType(prop, type),
|
|
1074
1082
|
},
|
|
1075
|
-
]);
|
|
1083
|
+
], 'exact-types');
|
|
1076
1084
|
}
|
|
1077
1085
|
if (prop.static) {
|
|
1078
1086
|
statement += `software.amazon.jsii.JsiiObject.jsiiStaticSet(${displayStatic(javaClass)}.class, `;
|
|
@@ -1126,7 +1134,8 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1126
1134
|
const async = !!method.async;
|
|
1127
1135
|
const methodName = JavaGenerator.safeJavaMethodName(method.name);
|
|
1128
1136
|
const types = this.convertTypes(method.parameters);
|
|
1129
|
-
const
|
|
1137
|
+
const covariance = covarianceFromOverridability(overridabilityFromMethod(method));
|
|
1138
|
+
const signature = `${typeVarDeclarations(types)}${displayStatic(returnType)} ${methodName}(${this.renderParameters(method.parameters, types, covariance)})`;
|
|
1130
1139
|
this.code.line();
|
|
1131
1140
|
this.addJavaDocs(method, {
|
|
1132
1141
|
api: 'member',
|
|
@@ -1144,7 +1153,7 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1144
1153
|
}
|
|
1145
1154
|
else {
|
|
1146
1155
|
this.code.openBlock(`${modifiers.join(' ')} ${signature}`);
|
|
1147
|
-
this.emitUnionParameterValidation(method.parameters);
|
|
1156
|
+
this.emitUnionParameterValidation(method.parameters, covariance);
|
|
1148
1157
|
this.code.line(this.renderMethodCall(cls, method, async));
|
|
1149
1158
|
this.code.closeBlock();
|
|
1150
1159
|
}
|
|
@@ -1154,7 +1163,7 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1154
1163
|
*
|
|
1155
1164
|
* @param parameters the list of parameters received by the function.
|
|
1156
1165
|
*/
|
|
1157
|
-
emitUnionParameterValidation(parameters) {
|
|
1166
|
+
emitUnionParameterValidation(parameters, covariance) {
|
|
1158
1167
|
if (!this.runtimeTypeChecking) {
|
|
1159
1168
|
// We were configured not to emit those, so bail out now.
|
|
1160
1169
|
return;
|
|
@@ -1168,7 +1177,7 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1168
1177
|
if (param.variadic) {
|
|
1169
1178
|
const javaType = this.toSingleJavaType(param.type);
|
|
1170
1179
|
const asListName = `__${param.name}__asList`;
|
|
1171
|
-
this.code.line(`final java.util.List<${displayStatic(javaType)}> ${asListName} = java.util.Arrays.asList(${param.name});`);
|
|
1180
|
+
this.code.line(`final java.util.List<${displayStatic(javaType, covariance)}> ${asListName} = java.util.Arrays.asList(${param.name});`);
|
|
1172
1181
|
validate.call(this, asListName, `.append("${param.name}")`, {
|
|
1173
1182
|
collection: {
|
|
1174
1183
|
kind: spec.CollectionKind.Array,
|
|
@@ -1177,7 +1186,7 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1177
1186
|
}, param.name, true);
|
|
1178
1187
|
}
|
|
1179
1188
|
else {
|
|
1180
|
-
validate.call(this, param.name, `.append("${param.name}")`, param.type, param.name);
|
|
1189
|
+
validate.call(this, param.name, `.append("${param.name}")`, param.type, param.name, false);
|
|
1181
1190
|
}
|
|
1182
1191
|
}
|
|
1183
1192
|
this.code.closeBlock();
|
|
@@ -1196,7 +1205,7 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1196
1205
|
}
|
|
1197
1206
|
}
|
|
1198
1207
|
}
|
|
1199
|
-
function validateArray(value, descr, elementType, parameterName, isRawArray
|
|
1208
|
+
function validateArray(value, descr, elementType, parameterName, isRawArray) {
|
|
1200
1209
|
const suffix = (0, crypto_1.createHash)('sha256')
|
|
1201
1210
|
.update(descr)
|
|
1202
1211
|
.digest('hex')
|
|
@@ -1208,7 +1217,7 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1208
1217
|
this.code.line(`final ${displayStatic(eltType)} ${valName} = ${value}.get(${idxName});`);
|
|
1209
1218
|
validate.call(this, valName, isRawArray
|
|
1210
1219
|
? `${descr}.append("[").append(${idxName}).append("]")`
|
|
1211
|
-
: `${descr}.append(".get(").append(${idxName}).append(")")`, elementType, parameterName);
|
|
1220
|
+
: `${descr}.append(".get(").append(${idxName}).append(")")`, elementType, parameterName, false);
|
|
1212
1221
|
this.code.closeBlock();
|
|
1213
1222
|
}
|
|
1214
1223
|
function validateMap(value, descr, elementType, parameterName) {
|
|
@@ -1231,8 +1240,12 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1231
1240
|
const varName = `__item_${suffix}`;
|
|
1232
1241
|
const valName = `__val_${suffix}`;
|
|
1233
1242
|
const javaElemType = this.toSingleJavaType(elementType);
|
|
1234
|
-
|
|
1235
|
-
|
|
1243
|
+
const entryType = mkStatic('java.util.Map.Entry', [
|
|
1244
|
+
mkStatic('java.lang.String'),
|
|
1245
|
+
javaElemType,
|
|
1246
|
+
]);
|
|
1247
|
+
this.code.openBlock(`for (final ${displayStatic(entryType, covariance)} ${varName}: ${value}.entrySet())`);
|
|
1248
|
+
this.code.line(`final ${displayStatic(javaElemType, covariance)} ${valName} = ${varName}.getValue();`);
|
|
1236
1249
|
validate.call(this, valName, `${descr}.append(".get(\\"").append((${varName}.getKey())).append("\\")")`, elementType, parameterName);
|
|
1237
1250
|
this.code.closeBlock();
|
|
1238
1251
|
}
|
|
@@ -1320,9 +1333,11 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1320
1333
|
this.code.line('/**');
|
|
1321
1334
|
this.code.line(' * A proxy class which represents a concrete javascript instance of this type.');
|
|
1322
1335
|
this.code.line(' */');
|
|
1336
|
+
// Get the list of $Default interfaces
|
|
1323
1337
|
const baseInterfaces = this.defaultInterfacesFor(type, {
|
|
1324
1338
|
includeThisType: true,
|
|
1325
1339
|
});
|
|
1340
|
+
// Add ourselves if we don't have a $Default interface
|
|
1326
1341
|
if (type.isInterfaceType() && !hasDefaultInterfaces(type.assembly)) {
|
|
1327
1342
|
// Extend this interface directly since this module does not have the Jsii$Default
|
|
1328
1343
|
baseInterfaces.push(this.toNativeFqn(type.fqn));
|
|
@@ -1339,10 +1354,7 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1339
1354
|
this.code.line('super(objRef);');
|
|
1340
1355
|
this.code.closeBlock();
|
|
1341
1356
|
// emit all properties
|
|
1342
|
-
for (const reflectProp of type.allProperties.filter(
|
|
1343
|
-
(prop.parentType.fqn === type.fqn ||
|
|
1344
|
-
prop.parentType.isClassType() ||
|
|
1345
|
-
!hasDefaultInterfaces(prop.assembly)))) {
|
|
1357
|
+
for (const reflectProp of type.allProperties.filter(needsProxyImpl)) {
|
|
1346
1358
|
const prop = clone(reflectProp.spec);
|
|
1347
1359
|
prop.abstract = false;
|
|
1348
1360
|
// Emitting "final" since this is a proxy and nothing will/should override this
|
|
@@ -1352,21 +1364,11 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1352
1364
|
});
|
|
1353
1365
|
}
|
|
1354
1366
|
// emit all the methods
|
|
1355
|
-
for (const reflectMethod of type.allMethods.
|
|
1356
|
-
|
|
1357
|
-
method.parentType.isClassType() ||
|
|
1358
|
-
!hasDefaultInterfaces(method.assembly)))) {
|
|
1359
|
-
const method = clone(reflectMethod.spec);
|
|
1360
|
-
method.abstract = false;
|
|
1367
|
+
for (const reflectMethod of type.allMethods.flatMap(this.makeProxyImpls.bind(this))) {
|
|
1368
|
+
const method = clone(reflectMethod);
|
|
1361
1369
|
// Emitting "final" since this is a proxy and nothing will/should override this
|
|
1370
|
+
method.abstract = false;
|
|
1362
1371
|
this.emitMethod(type.spec, method, { final: true, overrides: true });
|
|
1363
|
-
for (const overloadedMethod of this.createOverloadsForOptionals(method)) {
|
|
1364
|
-
overloadedMethod.abstract = false;
|
|
1365
|
-
this.emitMethod(type.spec, overloadedMethod, {
|
|
1366
|
-
final: true,
|
|
1367
|
-
overrides: true,
|
|
1368
|
-
});
|
|
1369
|
-
}
|
|
1370
1372
|
}
|
|
1371
1373
|
this.code.closeBlock();
|
|
1372
1374
|
}
|
|
@@ -1380,23 +1382,16 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
1380
1382
|
this.code.openBlock(`interface ${INTERFACE_DEFAULT_CLASS_NAME} extends ${baseInterfaces
|
|
1381
1383
|
.sort()
|
|
1382
1384
|
.join(', ')}`);
|
|
1383
|
-
for (const property of type.allProperties.filter(
|
|
1384
|
-
// Only checking the getter - java.lang.Object has no setters.
|
|
1385
|
-
!isJavaLangObjectMethodName(`get${(0, naming_util_1.jsiiToPascalCase)(prop.name)}`) &&
|
|
1386
|
-
(prop.parentType.fqn === type.fqn ||
|
|
1387
|
-
!hasDefaultInterfaces(prop.assembly)))) {
|
|
1385
|
+
for (const property of type.allProperties.filter(needsDefaultImpl)) {
|
|
1388
1386
|
this.emitProperty(type.spec, property.spec, property.definingType.spec, {
|
|
1389
1387
|
defaultImpl: true,
|
|
1390
1388
|
overrides: type.isInterfaceType(),
|
|
1391
1389
|
});
|
|
1392
1390
|
}
|
|
1393
|
-
for (const method of type.allMethods.
|
|
1394
|
-
|
|
1395
|
-
(method.parentType.fqn === type.fqn ||
|
|
1396
|
-
!hasDefaultInterfaces(method.assembly)))) {
|
|
1397
|
-
this.emitMethod(type.spec, method.spec, {
|
|
1391
|
+
for (const method of type.allMethods.flatMap(this.makeDefaultImpls.bind(this))) {
|
|
1392
|
+
this.emitMethod(type.spec, method, {
|
|
1398
1393
|
defaultImpl: true,
|
|
1399
|
-
overrides:
|
|
1394
|
+
overrides: true,
|
|
1400
1395
|
});
|
|
1401
1396
|
}
|
|
1402
1397
|
this.code.closeBlock();
|
|
@@ -2185,15 +2180,11 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
2185
2180
|
return forceSingleType(this.toDecoratedJavaTypes(p));
|
|
2186
2181
|
});
|
|
2187
2182
|
}
|
|
2188
|
-
renderParameters(parameters, types,
|
|
2183
|
+
renderParameters(parameters, types, cov) {
|
|
2189
2184
|
parameters = parameters ?? [];
|
|
2190
2185
|
if (parameters.length !== types.length) {
|
|
2191
2186
|
throw new Error(`Arrays not same length: ${parameters.length} !== ${types.length}`);
|
|
2192
2187
|
}
|
|
2193
|
-
// We can render covariant parameters only for methods that aren't overridable... so only for static methods currently.
|
|
2194
|
-
// (There are some more places where we could do this, like properties and constructors, but historically we didn't
|
|
2195
|
-
// and I don't want to mess with this too much because the risk/reward isn't there.)
|
|
2196
|
-
const cov = overridable === 'final' ? 'covariant' : undefined;
|
|
2197
2188
|
const params = [];
|
|
2198
2189
|
for (const [p, type] of (0, util_1.zip)(parameters, types)) {
|
|
2199
2190
|
params.push(`final ${displayType(type, cov)}${p.variadic ? '...' : ''} ${JavaGenerator.safeJavaPropertyName(p.name)}`);
|
|
@@ -2313,6 +2304,54 @@ class JavaGenerator extends generator_1.Generator {
|
|
|
2313
2304
|
this.code.closeFile(moduleFile);
|
|
2314
2305
|
return moduleClass;
|
|
2315
2306
|
}
|
|
2307
|
+
/**
|
|
2308
|
+
* Given a method, return the methods that we should generate implementations for on the $Default interface
|
|
2309
|
+
*
|
|
2310
|
+
* This can be 0..N:
|
|
2311
|
+
*
|
|
2312
|
+
* - 0: if the method can be inherited from a parent $Default implementation
|
|
2313
|
+
* - 1: if the method cannot be inherited from a parent $Default implementation
|
|
2314
|
+
* - N: ah-ha, wait! There can be overloads! And because of a historical bug,
|
|
2315
|
+
* we didn't use to generate overloads onto $Default interfaces. So it's possible
|
|
2316
|
+
* that we don't generate the "main" implementation, but we do generate its overloads.
|
|
2317
|
+
*
|
|
2318
|
+
* Technically speaking we only have to account for the bug if the type is from a different
|
|
2319
|
+
* assembly (because we know all types from the current assembly will be generated ✨ bugless ✨,
|
|
2320
|
+
* but just to keep it simple we'll always do the same thing).
|
|
2321
|
+
*
|
|
2322
|
+
* We can only get rid of this bug once the oldest dependency package a Java
|
|
2323
|
+
* package can be used with definitely has overloaded $Default impls. So that will be a while.
|
|
2324
|
+
*/
|
|
2325
|
+
makeDefaultImpls(m) {
|
|
2326
|
+
const ret = [];
|
|
2327
|
+
if (needsDefaultImpl(m)) {
|
|
2328
|
+
ret.push(m.spec);
|
|
2329
|
+
}
|
|
2330
|
+
// Account for a past bug
|
|
2331
|
+
if (needsDefaultImpl(m) || GENERATE_POTENTIALLY_MISING_DEFAULT_OVERLOADS) {
|
|
2332
|
+
ret.push(...this.createOverloadsForOptionals(m.spec));
|
|
2333
|
+
}
|
|
2334
|
+
return ret;
|
|
2335
|
+
}
|
|
2336
|
+
/**
|
|
2337
|
+
* Given a method, return the methods that we should generate implementations for on the $Proxy class
|
|
2338
|
+
*
|
|
2339
|
+
* See `makeDefaultImpls` for the main rationale behind this. The $Proxy class inherits from $Default
|
|
2340
|
+
* so technically this could have usually been empty, but we need to account for the possibility that
|
|
2341
|
+
* we implement a $Default interface from another assembly that has been generated with a buggy version
|
|
2342
|
+
* of pacmak.
|
|
2343
|
+
*/
|
|
2344
|
+
makeProxyImpls(m) {
|
|
2345
|
+
const ret = [];
|
|
2346
|
+
if (needsProxyImpl(m)) {
|
|
2347
|
+
ret.push(m.spec);
|
|
2348
|
+
}
|
|
2349
|
+
// Account for a past bug
|
|
2350
|
+
if (needsProxyImpl(m) || GENERATE_POTENTIALLY_MISING_DEFAULT_OVERLOADS) {
|
|
2351
|
+
ret.push(...this.createOverloadsForOptionals(m.spec));
|
|
2352
|
+
}
|
|
2353
|
+
return ret;
|
|
2354
|
+
}
|
|
2316
2355
|
emitJsiiInitializers(cls) {
|
|
2317
2356
|
this.code.line();
|
|
2318
2357
|
this.code.openBlock(`protected ${cls.name}(final software.amazon.jsii.JsiiObjectRef objRef)`);
|
|
@@ -2816,4 +2855,70 @@ function removeIntersections(x) {
|
|
|
2816
2855
|
}
|
|
2817
2856
|
return x;
|
|
2818
2857
|
}
|
|
2858
|
+
/**
|
|
2859
|
+
* Run the maven 'versions:resolve-ranges' plugin
|
|
2860
|
+
*
|
|
2861
|
+
* Initially, we generate version ranges into the pom file based on the NPM
|
|
2862
|
+
* version ranges.
|
|
2863
|
+
*
|
|
2864
|
+
* At build time, given a dependency version range, Maven will download metadata
|
|
2865
|
+
* for all possible versions before every (uncached) build. This takes a long
|
|
2866
|
+
* time, before finally resolving to the latest version anyway.
|
|
2867
|
+
*
|
|
2868
|
+
* Instead, we use the Maven 'versions' plugin to resolve our wide ranges to
|
|
2869
|
+
* point versions. We want the "latest matching" version anyway, and if we don't
|
|
2870
|
+
* the resolution now (which downloads the .poms of all possible versions) it
|
|
2871
|
+
* will happen during every single build.
|
|
2872
|
+
*/
|
|
2873
|
+
async function resolveMavenVersions(directory) {
|
|
2874
|
+
const versionsPluginVersion = '2.20.1';
|
|
2875
|
+
await (0, util_1.subprocess)('mvn', [
|
|
2876
|
+
`org.codehaus.mojo:versions-maven-plugin:${versionsPluginVersion}:resolve-ranges`,
|
|
2877
|
+
], {
|
|
2878
|
+
cwd: directory,
|
|
2879
|
+
retry: { maxAttempts: 1 },
|
|
2880
|
+
});
|
|
2881
|
+
}
|
|
2882
|
+
/**
|
|
2883
|
+
* Whether the given property or method needs to be implemented on a $Proxy class
|
|
2884
|
+
*
|
|
2885
|
+
* Proxies extend the class they're for (if for a class), and the $Default interfaces
|
|
2886
|
+
* of all the base interfaces, so implementations need to be present for everything
|
|
2887
|
+
* that is not abstract and can be inherited from a $Default interface.
|
|
2888
|
+
*/
|
|
2889
|
+
function needsProxyImpl(x) {
|
|
2890
|
+
// Interface members are always marked 'abstract', but we only need to
|
|
2891
|
+
// implement them if they come from a class (because interface members
|
|
2892
|
+
// will have a $Default impl that calls out to jsii already).
|
|
2893
|
+
const isAbstractClassMember = x.definingType.isClassType() && x.abstract;
|
|
2894
|
+
return (isAbstractClassMember || !hasDefaultInterfaces(x.definingType.assembly));
|
|
2895
|
+
}
|
|
2896
|
+
/**
|
|
2897
|
+
* Whether the given property or method needs to be implemented on a $Default interface
|
|
2898
|
+
*
|
|
2899
|
+
* $Default interfaces extend the interface they're for, and the $Default interfaces
|
|
2900
|
+
* of all the base interfaces, so implementations need to be present for everything
|
|
2901
|
+
* that is defined on the current interface or cannot be inherited from a $Default interface.
|
|
2902
|
+
*/
|
|
2903
|
+
function needsDefaultImpl(x) {
|
|
2904
|
+
const isBuiltinMethod = x instanceof reflect.Property
|
|
2905
|
+
? // Only checking the getter - java.lang.Object has no setters.
|
|
2906
|
+
isJavaLangObjectMethodName(`get${(0, naming_util_1.jsiiToPascalCase)(x.name)}`)
|
|
2907
|
+
: isJavaLangObjectMethodName(x.name);
|
|
2908
|
+
return ((!hasDefaultInterfaces(x.definingType.assembly) ||
|
|
2909
|
+
x.definingType.fqn === x.parentType.fqn) &&
|
|
2910
|
+
!isBuiltinMethod);
|
|
2911
|
+
}
|
|
2912
|
+
/**
|
|
2913
|
+
* Return the appropriate covariance rendering for the overridability of a given method
|
|
2914
|
+
*/
|
|
2915
|
+
function covarianceFromOverridability(overridable) {
|
|
2916
|
+
// We can render covariant parameters only for methods that aren't overridable... so only for static methods currently.
|
|
2917
|
+
// (There are some more places where we could do this, like properties and constructors, but historically we didn't
|
|
2918
|
+
// and I don't want to mess with this too much because the risk/reward isn't there.)
|
|
2919
|
+
return overridable === 'final' ? 'covariant' : 'exact-types';
|
|
2920
|
+
}
|
|
2921
|
+
function overridabilityFromMethod(method) {
|
|
2922
|
+
return method.static ? 'final' : 'overridable';
|
|
2923
|
+
}
|
|
2819
2924
|
//# sourceMappingURL=java.js.map
|
package/lib/util.d.ts
CHANGED
|
@@ -131,6 +131,6 @@ export declare function setExtend<A>(xs: Set<A>, els: Iterable<A>): void;
|
|
|
131
131
|
export declare function filterAsync<A>(xs: A[], pred: (x: A) => Promise<boolean>): Promise<A[]>;
|
|
132
132
|
export declare function wait(ms: number): Promise<void>;
|
|
133
133
|
export declare function flatten<A>(xs: readonly A[][]): A[];
|
|
134
|
-
export declare function zip<A, B>(xs: A[], ys: B[]): Array<[A, B]>;
|
|
134
|
+
export declare function zip<A, B>(xs: readonly A[], ys: readonly B[]): Array<[A, B]>;
|
|
135
135
|
export declare function setAdd<T>(setA: Set<T>, setB: Iterable<T>): void;
|
|
136
136
|
//# sourceMappingURL=util.d.ts.map
|
package/lib/version.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The short version number for this jsii-pacmak release (e.g: `X.Y.Z`) */
|
|
2
2
|
export declare const VERSION: string;
|
|
3
3
|
/** The qualified version number for this jsii-pacmak release (e.g: `X.Y.Z (build #######)`) */
|
|
4
|
-
export declare const VERSION_DESC = "1.
|
|
4
|
+
export declare const VERSION_DESC = "1.123.0 (build 432bf02)";
|
|
5
5
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/version.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Generated at 2025-12-
|
|
2
|
+
// Generated at 2025-12-29T21:07:34Z by generate.sh
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.VERSION_DESC = exports.VERSION = void 0;
|
|
5
5
|
/** The short version number for this jsii-pacmak release (e.g: `X.Y.Z`) */
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
7
|
-
exports.VERSION = '1.
|
|
7
|
+
exports.VERSION = '1.123.0';
|
|
8
8
|
/** The qualified version number for this jsii-pacmak release (e.g: `X.Y.Z (build #######)`) */
|
|
9
|
-
exports.VERSION_DESC = '1.
|
|
9
|
+
exports.VERSION_DESC = '1.123.0 (build 432bf02)';
|
|
10
10
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsii-pacmak",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.123.0",
|
|
4
4
|
"description": "A code generation framework for jsii backend languages",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -37,24 +37,24 @@
|
|
|
37
37
|
"package": "package-js"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@jsii/check-node": "1.
|
|
41
|
-
"@jsii/spec": "1.
|
|
40
|
+
"@jsii/check-node": "1.123.0",
|
|
41
|
+
"@jsii/spec": "1.123.0",
|
|
42
42
|
"clone": "^2.1.2",
|
|
43
|
-
"codemaker": "^1.
|
|
43
|
+
"codemaker": "^1.123.0",
|
|
44
44
|
"commonmark": "^0.31.2",
|
|
45
45
|
"escape-string-regexp": "^4.0.0",
|
|
46
46
|
"fs-extra": "^10.1.0",
|
|
47
|
-
"jsii-reflect": "^1.
|
|
47
|
+
"jsii-reflect": "^1.123.0",
|
|
48
48
|
"semver": "^7.7.2",
|
|
49
49
|
"spdx-license-list": "^6.10.0",
|
|
50
50
|
"xmlbuilder": "^15.1.1",
|
|
51
51
|
"yargs": "^17.7.2"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@jsii/dotnet-runtime": "^1.
|
|
55
|
-
"@jsii/go-runtime": "^1.
|
|
56
|
-
"@jsii/java-runtime": "^1.
|
|
57
|
-
"@scope/jsii-calc-lib": "^1.
|
|
54
|
+
"@jsii/dotnet-runtime": "^1.123.0",
|
|
55
|
+
"@jsii/go-runtime": "^1.123.0",
|
|
56
|
+
"@jsii/java-runtime": "^1.123.0",
|
|
57
|
+
"@scope/jsii-calc-lib": "^1.123.0",
|
|
58
58
|
"@types/clone": "^2.1.4",
|
|
59
59
|
"@types/commonmark": "^0.27.10",
|
|
60
60
|
"@types/diff": "^5.2.3",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@types/yargs": "^17.0.33",
|
|
64
64
|
"diff": "^5.2.0",
|
|
65
65
|
"jsii": "^5.9.10",
|
|
66
|
-
"jsii-build-tools": "^1.
|
|
66
|
+
"jsii-build-tools": "^1.123.0",
|
|
67
67
|
"jsii-calc": "^3.20.120",
|
|
68
68
|
"jsii-rosetta": "~5.9.10",
|
|
69
69
|
"pyright": "^1.1.403"
|