Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pacmak): fix a couple of issues related to java generation #921

Merged
merged 2 commits into from
Oct 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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