Make ConvenienceRenderer know about comments
This commit is contained in:
Родитель
2274c44cc3
Коммит
1ce6233328
|
@ -651,11 +651,15 @@ export abstract class ConvenienceRenderer extends Renderer {
|
|||
return serializeRenderResult(sourcelikeToSource(src), this.names, "").lines.join("\n");
|
||||
};
|
||||
|
||||
protected emitCommentLines = (commentStart: string, lines: string[]): void => {
|
||||
protected get commentLineStart(): string {
|
||||
return "// ";
|
||||
}
|
||||
|
||||
protected emitCommentLines(lines: string[]): void {
|
||||
for (const line of lines) {
|
||||
this.emitLine(trimEnd(commentStart + line));
|
||||
this.emitLine(trimEnd(this.commentLineStart + line));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private processGraph(): void {
|
||||
this._declarationIR = declarationsForGraph(
|
||||
|
@ -764,7 +768,7 @@ export abstract class ConvenienceRenderer extends Renderer {
|
|||
protected registerHandlebarsHelpers(context: StringMap): void {
|
||||
super.registerHandlebarsHelpers(context);
|
||||
|
||||
handlebars.registerHelper("with_type", function (t: any, options: any): any {
|
||||
handlebars.registerHelper("with_type", function(t: any, options: any): any {
|
||||
return options.fn(context.allTypes[t.index]);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -719,9 +719,9 @@ inline ${optionalType}<T> get_optional(const json &j, const char *property) {
|
|||
|
||||
protected emitSourceStructure(): void {
|
||||
if (this.leadingComments !== undefined) {
|
||||
this.emitCommentLines("// ", this.leadingComments);
|
||||
this.emitCommentLines(this.leadingComments);
|
||||
} else if (!this._justTypes) {
|
||||
this.emitCommentLines("// ", [
|
||||
this.emitCommentLines([
|
||||
" To parse this JSON data, first install",
|
||||
"",
|
||||
" Boost http://www.boost.org",
|
||||
|
|
|
@ -363,7 +363,7 @@ class CSharpRenderer extends ConvenienceRenderer {
|
|||
|
||||
protected emitSourceStructure(): void {
|
||||
if (this.leadingComments !== undefined) {
|
||||
this.emitCommentLines("// ", this.leadingComments);
|
||||
this.emitCommentLines(this.leadingComments);
|
||||
} else if (this.needHelpers) {
|
||||
this.emitDefaultLeadingComments();
|
||||
}
|
||||
|
|
|
@ -225,6 +225,10 @@ class ElmRenderer extends ConvenienceRenderer {
|
|||
return `${fieldName}_in_${lookup(unionName)}`;
|
||||
}
|
||||
|
||||
protected get commentLineStart(): string {
|
||||
return "-- ";
|
||||
}
|
||||
|
||||
private get arrayType(): string {
|
||||
return this._useList ? "List" : "Array";
|
||||
}
|
||||
|
@ -542,9 +546,9 @@ class ElmRenderer extends ConvenienceRenderer {
|
|||
});
|
||||
|
||||
if (this.leadingComments !== undefined) {
|
||||
this.emitCommentLines("-- ", this.leadingComments);
|
||||
this.emitCommentLines(this.leadingComments);
|
||||
} else if (!this._justTypes) {
|
||||
this.emitCommentLines("-- ", [
|
||||
this.emitCommentLines([
|
||||
"To decode the JSON data, add this file to your project, run",
|
||||
"",
|
||||
" elm-package install NoRedInk/elm-decode-pipeline",
|
||||
|
|
|
@ -319,7 +319,7 @@ class GoRenderer extends ConvenienceRenderer {
|
|||
|
||||
protected emitSourceStructure(): void {
|
||||
if (this.leadingComments !== undefined) {
|
||||
this.emitCommentLines("// ", this.leadingComments);
|
||||
this.emitCommentLines(this.leadingComments);
|
||||
} else if (!this._justTypes) {
|
||||
this.emitLine("// To parse and unparse this JSON data, add this code to your project and do:");
|
||||
this.forEachTopLevel("none", (_: Type, name: Name) => {
|
||||
|
|
|
@ -557,9 +557,9 @@ export class JavaRenderer extends ConvenienceRenderer {
|
|||
this.startFile("Converter");
|
||||
this.ensureBlankLine();
|
||||
if (this.leadingComments !== undefined) {
|
||||
this.emitCommentLines("// ", this.leadingComments);
|
||||
this.emitCommentLines(this.leadingComments);
|
||||
} else {
|
||||
this.emitCommentLines("// ", [
|
||||
this.emitCommentLines([
|
||||
"To use this code, add the following Maven dependency to your project:",
|
||||
"",
|
||||
" com.fasterxml.jackson.core : jackson-databind : 2.9.0",
|
||||
|
|
|
@ -927,9 +927,9 @@ class ObjectiveCRenderer extends ConvenienceRenderer {
|
|||
this.startFile(filename, "h");
|
||||
|
||||
if (this.leadingComments !== undefined) {
|
||||
this.emitCommentLines("// ", this.leadingComments);
|
||||
this.emitCommentLines(this.leadingComments);
|
||||
} else if (!this._justTypes) {
|
||||
this.emitCommentLines("// ", ["To parse this JSON:", ""]);
|
||||
this.emitCommentLines(["To parse this JSON:", ""]);
|
||||
this.emitLine("// NSError *error;");
|
||||
this.forEachTopLevel("none", (t, topLevelName) => {
|
||||
const fromJsonExpression =
|
||||
|
|
|
@ -203,6 +203,10 @@ class RustRenderer extends ConvenienceRenderer {
|
|||
return rustStyle(rawName, false);
|
||||
}
|
||||
|
||||
protected get commentLineStart(): string {
|
||||
return "/// ";
|
||||
}
|
||||
|
||||
private nullableRustType = (t: Type, withIssues: boolean): Sourcelike => {
|
||||
return ["Option<", this.breakCycle(t, withIssues), ">"];
|
||||
};
|
||||
|
@ -262,7 +266,7 @@ class RustRenderer extends ConvenienceRenderer {
|
|||
const comments = this.descriptionForClassProperty(t, jsonName);
|
||||
|
||||
if (comments !== undefined) {
|
||||
this.emitCommentLines("/// ", comments);
|
||||
this.emitCommentLines(comments);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ class SimpleTypesRenderer extends ConvenienceRenderer {
|
|||
|
||||
protected emitSourceStructure() {
|
||||
if (this.leadingComments !== undefined) {
|
||||
this.emitCommentLines("// ", this.leadingComments);
|
||||
this.emitCommentLines(this.leadingComments);
|
||||
}
|
||||
this.forEachClass("leading-and-interposing", this.emitClass);
|
||||
this.forEachEnum("leading-and-interposing", this.emitEnum);
|
||||
|
|
|
@ -340,7 +340,7 @@ class SwiftRenderer extends ConvenienceRenderer {
|
|||
|
||||
private renderHeader = (): void => {
|
||||
if (this.leadingComments !== undefined) {
|
||||
this.emitCommentLines("// ", this.leadingComments);
|
||||
this.emitCommentLines(this.leadingComments);
|
||||
} else if (!this._justTypes) {
|
||||
this.emitLine("// To parse the JSON, add this file to your project and do:");
|
||||
this.emitLine("//");
|
||||
|
|
|
@ -372,7 +372,7 @@ function O(className: string) {
|
|||
|
||||
protected emitSourceStructure() {
|
||||
if (this.leadingComments !== undefined) {
|
||||
this.emitCommentLines("// ", this.leadingComments);
|
||||
this.emitCommentLines(this.leadingComments);
|
||||
} else if (!this._justTypes) {
|
||||
this.emitMultiline(`// To parse this data:
|
||||
//`);
|
||||
|
|
Загрузка…
Ссылка в новой задаче