From 5ad58c0d3937e4a5fa5f5dfbb84f4be089727cba Mon Sep 17 00:00:00 2001 From: Romain Marcadier-Muller Date: Wed, 30 Oct 2019 19:52:12 +0100 Subject: [PATCH] fix(pacmak): fix a couple of issues related to java generation (#921) * fix(pacmak): don't aggregate package single-packages & builder generation Generating the aggregate POM could result in building a cyclic POM module tree, as the aggregate POM file would then be replacing the module's own POM. This stops aggregate-packaging single modules. Also addresses an issue with the builder method names being generated inconsistently across the Struct & Class builders, resulting in invalid call forwaring being attempted. * generate correct overloads for type unions --- packages/jsii-pacmak/lib/targets/java.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/jsii-pacmak/lib/targets/java.ts b/packages/jsii-pacmak/lib/targets/java.ts index df1de6e11d..62df1231a4 100644 --- a/packages/jsii-pacmak/lib/targets/java.ts +++ b/packages/jsii-pacmak/lib/targets/java.ts @@ -49,7 +49,9 @@ export class JavaBuilder implements TargetBuilder { if (!options.codeOnly && modules.length > 0) { // Need a module to get a target - const pomDirectory = await this.generateAggregatePom(moduleDirectories); + const pomDirectory = modules.length > 1 + ? await this.generateAggregatePom(moduleDirectories) + : moduleDirectories[0].directory; const target = this.makeTarget(modules[0], options); await target.build(pomDirectory, singleOutputDir); @@ -1089,11 +1091,10 @@ class JavaGenerator extends Generator { // Fields for (const prop of structType.allProperties) { - const methodName = JavaGenerator.safeJavaMethodName(prop.name); const fieldName = this.code.toCamelCase(JavaGenerator.safeJavaPropertyName(prop.name)); this.code.line(); const setter: spec.Method = { - name: methodName, + name: fieldName, docs: { stability: prop.spec.docs && prop.spec.docs.stability, returns: '{@code this}', @@ -1104,12 +1105,14 @@ class JavaGenerator extends Generator { docs: prop.spec.docs, }], }; - this.addJavaDocs(setter); - this.emitStabilityAnnotations(prop.spec); - this.code.openBlock(`public ${BUILDER_CLASS_NAME} ${methodName}(final ${this.toJavaType(prop.type.spec!)} ${fieldName})`); - this.code.line(`this.${structParamName}${firstStruct.optional ? '()' : ''}.${methodName}(${fieldName});`); - this.code.line('return this;'); - this.code.closeBlock(); + for (const javaType of this.toJavaTypes(prop.type.spec!)) { + this.addJavaDocs(setter); + this.emitStabilityAnnotations(prop.spec); + this.code.openBlock(`public ${BUILDER_CLASS_NAME} ${fieldName}(final ${javaType} ${fieldName})`); + this.code.line(`this.${structParamName}${firstStruct.optional ? '()' : ''}.${fieldName}(${fieldName});`); + this.code.line('return this;'); + this.code.closeBlock(); + } } // Final build method