Skip to content

Commit

Permalink
fix(pacmak): fix a couple of issues related to java generation (#921)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
RomainMuller authored and mergify[bot] committed Oct 30, 2019
1 parent c0f338e commit 5ad58c0
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/jsii-pacmak/lib/targets/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}',
Expand All @@ -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
Expand Down

0 comments on commit 5ad58c0

Please sign in to comment.