Skip to content

Commit 5ad58c0

Browse files
RomainMullermergify[bot]
authored andcommitted
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
1 parent c0f338e commit 5ad58c0

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

  • packages/jsii-pacmak/lib/targets

packages/jsii-pacmak/lib/targets/java.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export class JavaBuilder implements TargetBuilder {
4949

5050
if (!options.codeOnly && modules.length > 0) {
5151
// Need a module to get a target
52-
const pomDirectory = await this.generateAggregatePom(moduleDirectories);
52+
const pomDirectory = modules.length > 1
53+
? await this.generateAggregatePom(moduleDirectories)
54+
: moduleDirectories[0].directory;
5355
const target = this.makeTarget(modules[0], options);
5456

5557
await target.build(pomDirectory, singleOutputDir);
@@ -1089,11 +1091,10 @@ class JavaGenerator extends Generator {
10891091

10901092
// Fields
10911093
for (const prop of structType.allProperties) {
1092-
const methodName = JavaGenerator.safeJavaMethodName(prop.name);
10931094
const fieldName = this.code.toCamelCase(JavaGenerator.safeJavaPropertyName(prop.name));
10941095
this.code.line();
10951096
const setter: spec.Method = {
1096-
name: methodName,
1097+
name: fieldName,
10971098
docs: {
10981099
stability: prop.spec.docs && prop.spec.docs.stability,
10991100
returns: '{@code this}',
@@ -1104,12 +1105,14 @@ class JavaGenerator extends Generator {
11041105
docs: prop.spec.docs,
11051106
}],
11061107
};
1107-
this.addJavaDocs(setter);
1108-
this.emitStabilityAnnotations(prop.spec);
1109-
this.code.openBlock(`public ${BUILDER_CLASS_NAME} ${methodName}(final ${this.toJavaType(prop.type.spec!)} ${fieldName})`);
1110-
this.code.line(`this.${structParamName}${firstStruct.optional ? '()' : ''}.${methodName}(${fieldName});`);
1111-
this.code.line('return this;');
1112-
this.code.closeBlock();
1108+
for (const javaType of this.toJavaTypes(prop.type.spec!)) {
1109+
this.addJavaDocs(setter);
1110+
this.emitStabilityAnnotations(prop.spec);
1111+
this.code.openBlock(`public ${BUILDER_CLASS_NAME} ${fieldName}(final ${javaType} ${fieldName})`);
1112+
this.code.line(`this.${structParamName}${firstStruct.optional ? '()' : ''}.${fieldName}(${fieldName});`);
1113+
this.code.line('return this;');
1114+
this.code.closeBlock();
1115+
}
11131116
}
11141117

11151118
// Final build method

0 commit comments

Comments
 (0)