summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristoph Schlosser <christoph@linux.com>2018-03-02 22:21:22 +0100
committerChristoph Schlosser <christophschlosser@users.noreply.github.com>2018-03-02 23:27:10 +0100
commit16452c8e0c644fa979270e99906eb9c34a13ca5f (patch)
tree25173bf8f8b79167193ce36094bf80399b1ea724 /src
parentb837545df65a31ba5dac154644c359c2a55d1531 (diff)
downloaddoxdocgen-16452c8e0c644fa979270e99906eb9c34a13ca5f.tar.gz
Make order of comment tags customizable
Fix #55
Diffstat (limited to 'src')
-rw-r--r--src/Config.ts10
-rw-r--r--src/Lang/Cpp/CppDocGen.ts74
-rw-r--r--src/test/CppTests/Config.test.ts22
3 files changed, 66 insertions, 40 deletions
diff --git a/src/Config.ts b/src/Config.ts
index aed2105..0fcd5a2 100644
--- a/src/Config.ts
+++ b/src/Config.ts
@@ -21,7 +21,6 @@ class Cpp {
return workspace.getConfiguration("doxdocgen.cpp");
}
- public newLineAfterTParams: boolean = false;
public tparamTemplate: string = "@tparam {param} ";
public ctorText: string = "Construct a new {name} object";
public dtorText: string = "Destroy the {name} object";
@@ -33,7 +32,7 @@ class File {
}
public fileTemplate: string = "@file {name}";
- public fileOrder: string[] = ["brief", "file", "author", "date"];
+ public fileOrder: string[] = ["brief", "empty", "file", "author", "date"];
}
class Generic {
@@ -41,8 +40,6 @@ class Generic {
return workspace.getConfiguration("doxdocgen.generic");
}
- public newLineAfterBrief: boolean = true;
- public newLineAfterParams: boolean = false;
public includeTypeAtReturn: boolean = true;
public boolReturnsTrueFalse: boolean = true;
public briefTemplate: string = "@brief ";
@@ -54,6 +51,7 @@ class Generic {
public dateFormat: string = "YYYY-MM-DD";
public generateSmartText: boolean = true;
public splitCasingSmartText: boolean = true;
+ public order: string[] = ["brief", "empty", "tparam", "param", "return"];
}
export class Config {
@@ -68,7 +66,6 @@ export class Config {
values.C.setterText = C.getConfiguration().get<string>("setterText", values.C.setterText);
values.C.factoryMethodText = C.getConfiguration().get<string>("factoryMethodText", values.C.factoryMethodText);
- values.Cpp.newLineAfterTParams = Cpp.getConfiguration().get<boolean>("newLineAfterTParams", values.Cpp.newLineAfterTParams);
values.Cpp.tparamTemplate = Cpp.getConfiguration().get<string>("tparamTemplate", values.Cpp.tparamTemplate);
values.Cpp.ctorText = Cpp.getConfiguration().get<string>("ctorText", values.Cpp.ctorText);
values.Cpp.dtorText = Cpp.getConfiguration().get<string>("dtorText", values.Cpp.dtorText);
@@ -76,8 +73,6 @@ export class Config {
values.File.fileTemplate = File.getConfiguration().get<string>("fileTemplate", values.File.fileTemplate);
values.File.fileOrder = File.getConfiguration().get<string[]>("fileOrder", values.File.fileOrder);
- values.Generic.newLineAfterBrief = Generic.getConfiguration().get<boolean>("newLineAfterBrief", values.Generic.newLineAfterBrief);
- values.Generic.newLineAfterParams = Generic.getConfiguration().get<boolean>("newLineAfterParams", values.Generic.newLineAfterParams);
values.Generic.includeTypeAtReturn = Generic.getConfiguration().get<boolean>("includeTypeAtReturn", values.Generic.includeTypeAtReturn);
values.Generic.boolReturnsTrueFalse = Generic.getConfiguration().get<boolean>("boolReturnsTrueFalse", values.Generic.boolReturnsTrueFalse);
values.Generic.briefTemplate = Generic.getConfiguration().get<string>("briefTemplate", values.Generic.briefTemplate);
@@ -89,6 +84,7 @@ export class Config {
values.Generic.dateFormat = Generic.getConfiguration().get<string>("dateFormat", values.Generic.dateFormat);
values.Generic.generateSmartText = Generic.getConfiguration().get<boolean>("generateSmartText", values.Generic.generateSmartText);
values.Generic.splitCasingSmartText = Generic.getConfiguration().get<boolean>("splitCasingSmartText", values.Generic.splitCasingSmartText);
+ values.Generic.order = Generic.getConfiguration().get<string[]>("order", values.Generic.order);
return values;
}
diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts
index 1a03430..56ce922 100644
--- a/src/Lang/Cpp/CppDocGen.ts
+++ b/src/Lang/Cpp/CppDocGen.ts
@@ -247,9 +247,6 @@ export class CppDocGen implements IDocGen {
protected insertBrief(lines: string[]) {
if (this.cfg.Generic.briefTemplate.trim().length !== 0) {
this.generateBrief(lines);
- if (this.cfg.Generic.newLineAfterBrief === true) {
- lines.push(this.cfg.C.commentPrefix);
- }
}
}
@@ -270,6 +267,10 @@ export class CppDocGen implements IDocGen {
this.insertBrief(lines);
break;
}
+ case "empty": {
+ lines.push(this.cfg.C.commentPrefix);
+ break;
+ }
case "file": {
this.generateFilenameFromTemplate(lines);
break;
@@ -298,33 +299,48 @@ export class CppDocGen implements IDocGen {
this.insertFirstLine(lines);
- this.insertBrief(lines);
-
- if (this.cfg.Cpp.tparamTemplate.trim().length !== 0 && this.templateParams.length > 0) {
- this.generateFromTemplate(
- lines,
- this.cfg.paramTemplateReplace,
- this.cfg.Cpp.tparamTemplate,
- this.templateParams,
- );
- if (this.cfg.Cpp.newLineAfterTParams === true) {
- lines.push(this.cfg.C.commentPrefix);
- }
- }
-
- if (this.cfg.Generic.paramTemplate.trim().length !== 0 && this.params.length > 0) {
- const paramNames: string[] = this.params.map((p) => p.name);
- this.generateFromTemplate(lines, this.cfg.paramTemplateReplace, this.cfg.Generic.paramTemplate, paramNames);
- if (this.cfg.Generic.newLineAfterParams === true) {
- lines.push(this.cfg.C.commentPrefix);
+ this.cfg.Generic.order.forEach((element) => {
+ switch (element) {
+ case "brief": {
+ this.insertBrief(lines);
+ break;
+ }
+ case "empty": {
+ lines.push(this.cfg.C.commentPrefix);
+ break;
+ }
+ case "tparam": {
+ if (this.cfg.Cpp.tparamTemplate.trim().length !== 0 && this.templateParams.length > 0) {
+ this.generateFromTemplate(
+ lines,
+ this.cfg.paramTemplateReplace,
+ this.cfg.Cpp.tparamTemplate,
+ this.templateParams,
+ );
+ }
+ break;
+ }
+ case "param": {
+ if (this.cfg.Generic.paramTemplate.trim().length !== 0 && this.params.length > 0) {
+ const paramNames: string[] = this.params.map((p) => p.name);
+ // tslint:disable-next-line:max-line-length
+ this.generateFromTemplate(lines, this.cfg.paramTemplateReplace, this.cfg.Generic.paramTemplate, paramNames);
+ }
+ break;
+ }
+ case "return": {
+ if (this.cfg.Generic.returnTemplate.trim().length !== 0 && this.func.type !== null) {
+ const returnParams = this.generateReturnParams();
+ // tslint:disable-next-line:max-line-length
+ this.generateFromTemplate(lines, this.cfg.typeTemplateReplace, this.cfg.Generic.returnTemplate, returnParams);
+ }
+ break;
+ }
+ default: {
+ break;
+ }
}
- }
-
- if (this.cfg.Generic.returnTemplate.trim().length !== 0 && this.func.type !== null) {
- const returnParams = this.generateReturnParams();
- // tslint:disable-next-line:max-line-length
- this.generateFromTemplate(lines, this.cfg.typeTemplateReplace, this.cfg.Generic.returnTemplate, returnParams);
- }
+ });
this.insertLastLine(lines);
diff --git a/src/test/CppTests/Config.test.ts b/src/test/CppTests/Config.test.ts
index ee6a90f..69837ce 100644
--- a/src/test/CppTests/Config.test.ts
+++ b/src/test/CppTests/Config.test.ts
@@ -25,6 +25,21 @@ suite("C++ - Configuration Tests", () => {
+ "@return true \n * @return false \n */", result);
});
+ test("Comment order", () => {
+ testSetup.cfg = new Config();
+ testSetup.cfg.Generic.order = ["brief", "param", "tparam", "return"];
+ const result = testSetup.SetLine("template<typename T> bool foo(T a);").GetResult();
+ assert.equal("/**\n * @brief \n * @param a \n * @tparam T \n * "
+ + "@return true \n * @return false \n */", result);
+ });
+
+ test("Non existing order param", () => {
+ testSetup.cfg = new Config();
+ testSetup.cfg.Generic.order = ["breif"];
+ const result = testSetup.SetLine("template<typename T> bool foo(T a);").GetResult();
+ assert.equal("/**\n */", result);
+ });
+
test("Modified template", () => {
testSetup.cfg = new Config();
@@ -61,11 +76,10 @@ suite("C++ - Configuration Tests", () => {
test("Newlines after params and tparams but not after brief", () => {
testSetup.cfg = new Config();
- testSetup.cfg.Generic.newLineAfterBrief = false;
- testSetup.cfg.Generic.newLineAfterParams = true;
- testSetup.cfg.Cpp.newLineAfterTParams = true;
+ testSetup.cfg.Generic.order = ["brief", "tparam", "empty", "param", "empty", "return"];
const result = testSetup.SetLine("template<typename T> bool foo(T a);").GetResult();
+ testSetup.cfg.Generic.order = ["brief", "empty", "tparam", "param", "return"]; // reset to default
assert.equal("/**\n * @brief \n * @tparam T \n * \n * @param a \n * \n"
+ " * @return true \n * @return false \n */", result);
});
@@ -99,7 +113,7 @@ suite("C++ - Configuration Tests", () => {
testSetup.firstLine = 0;
testSetup.cfg.File.fileOrder = ["brief", "author", "date", "file"];
const result = testSetup.SetLine("").GetResult();
- assert.equal("/**\n * @brief \n * \n * @author your name\n" +
+ assert.equal("/**\n * @brief \n * @author your name\n" +
" * @date " + moment().format("YYYY-MM-DD") + "\n * @file MockDocument.h\n */", result);
});