diff options
| author | Rowan Goemans <RB.Goemans@student.han.nl> | 2017-12-31 02:03:08 +0100 |
|---|---|---|
| committer | Christoph Schlosser <christophschlosser@users.noreply.github.com> | 2018-02-20 22:02:22 +0100 |
| commit | 1746f21bc3720585d2fe877db8d69aae301ff02c (patch) | |
| tree | 7f0d081fd8fc3e0b54c7bb478cb8724a4cf3b798 /src/DocGen | |
| parent | b446b9e596fc0487b88597d8e818dae61512f309 (diff) | |
| download | doxdocgen-1746f21bc3720585d2fe877db8d69aae301ff02c.tar.gz | |
-- Added many unit tests for the C parser. Almost complete now
-- Refactored project structure to allow for more overview once we add more languages.
-- Renamed a lot of types in the CParser to be more explicit.
-- Made configuration injectable into the classes that need them. This allows to unit test configuration variables.
-- Added 2 new config params that allows to customize what gets returned for a bool return type.
-- Small changes to the logic to make it more concise.
Diffstat (limited to 'src/DocGen')
| -rw-r--r-- | src/DocGen/CGen.ts | 185 | ||||
| -rw-r--r-- | src/DocGen/CppGen.ts | 6 | ||||
| -rw-r--r-- | src/DocGen/DocGen.ts | 9 |
3 files changed, 0 insertions, 200 deletions
diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts deleted file mode 100644 index 13ecbf1..0000000 --- a/src/DocGen/CGen.ts +++ /dev/null @@ -1,185 +0,0 @@ -import { Position, Range, Selection, TextEditor, TextLine, workspace, WorkspaceEdit } from "vscode"; -import { Config, ConfigType } from "../Config"; -import { IDocGen } from "./DocGen"; - -export default class CGen implements IDocGen { - protected firstLine: string; - protected commentPrefix: string; - protected lastLine: string; - protected newLineAfterBrief: boolean; - protected newLineAfterParams: boolean; - protected newLineAfterTParams: boolean; - protected includeTypeAtReturn: boolean; - protected briefTemplate: string; - protected paramTemplate: string; - protected tparamTemplate: string; - protected returnTemplate: string; - - protected templateParamReplace: string; - protected templateTypeReplace: string; - - protected activeEditor: TextEditor; - - protected retVals: string[]; - protected params: string[]; - protected tparams: string[]; - - /** - * @param {TextEditor} actEdit Active editor window - * @param {Position} cursorPosition Where the cursor of the user currently is - * @param {string[]} params The parameter names of the method extracted by the parser - * @param {string[]} tparam The template parameter names of the method extracted by the parser. - * @param {string[]} returnVals The return values extracted by the parser - */ - public constructor( - actEdit: TextEditor, - cursorPosition: Position, - params: string[], - tparam: string[], - returnVals: string[], - ) { - this.activeEditor = actEdit; - this.templateParamReplace = "{param}"; - this.templateTypeReplace = "{type}"; - this.params = params; - this.tparams = tparam; - this.retVals = returnVals; - } - - /** - * @inheritdoc - */ - public GenerateDoc(rangeToReplace: Range) { - this.readConfig(); - const comment: string = this.generateComment(); - - this.activeEditor.edit((editBuilder) => { - editBuilder.replace(rangeToReplace, comment); // Insert the comment - }); - - // Set cursor to first DoxyGen command. - this.moveCursurToFirstDoxyCommand(comment, rangeToReplace.start.line, rangeToReplace.start.character); - } - - /*************************************************************************** - Implementation - ***************************************************************************/ - - protected readConfig() { - const getCfg = workspace.getConfiguration; - - this.firstLine = getCfg(ConfigType.generic).get<string>(Config.firstLine, "/**"); - this.commentPrefix = getCfg(ConfigType.generic).get<string>(Config.commentPrefix, " * "); - this.lastLine = getCfg(ConfigType.generic).get<string>(Config.lastLine, " */"); - this.newLineAfterBrief = getCfg(ConfigType.generic).get<boolean>(Config.newLineAfterBrief, true); - this.newLineAfterParams = getCfg(ConfigType.generic).get<boolean>(Config.newLineAfterParams, false); - this.newLineAfterTParams = getCfg(ConfigType.generic).get<boolean>(Config.newLineAfterTParams, false); - this.includeTypeAtReturn = getCfg(ConfigType.generic).get<boolean>(Config.includeTypeAtReturn, false); - this.briefTemplate = getCfg(ConfigType.generic).get<string>(Config.briefTemplate, "@brief "); - this.paramTemplate = getCfg(ConfigType.generic).get<string>(Config.paramTemplate, "@param {param} "); - this.tparamTemplate = getCfg(ConfigType.generic).get<string>(Config.tparamTemplate, "@tparam {param} "); - this.returnTemplate = getCfg(ConfigType.generic).get<string>(Config.returnTemplate, "@return {type} "); - } - - protected getIndentation(): string { - const line: TextLine = this.activeEditor.document.lineAt(this.activeEditor.selection.start.line); - const lineTxt: string = line.text; - let stringToIndent: string = ""; - // Find indentation from previous line - for (let i = 0; i < line.firstNonWhitespaceCharacterIndex; i++) { - if (lineTxt.charAt(i) === "\t") { - stringToIndent = stringToIndent + "\t"; - } else if (lineTxt.charAt(i) === " ") { - stringToIndent = stringToIndent + " "; - } - } - return stringToIndent; - } - - protected getTemplatedString(replace: string, template: string, param: string): string { - return template.replace(replace, param); - } - - protected generateBrief(lines: string[]) { - lines.push(this.commentPrefix + this.briefTemplate); - } - - protected generateFromTemplate(lines: string[], replace: string, template: string, templateWith: string[]) { - let line: string = ""; - - templateWith.forEach((element: string) => { - // Ignore null values - if (element !== null) { - line = this.commentPrefix; - line += this.getTemplatedString(replace, template, element); - lines.push(line); - } - }); - } - - protected generateComment(): string { - const lines: string[] = []; - - if (this.firstLine.trim().length !== 0) { - lines.push(this.firstLine); - } - - if (this.briefTemplate.trim().length !== 0) { - this.generateBrief(lines); - if (this.newLineAfterBrief === true) { - lines.push(this.commentPrefix); - } - } - - if (this.tparamTemplate.trim().length !== 0 && this.tparams.length > 0) { - this.generateFromTemplate(lines, this.templateParamReplace, this.tparamTemplate, this.tparams); - if (this.newLineAfterTParams === true) { - lines.push(this.commentPrefix); - } - } - - if (this.paramTemplate.trim().length !== 0 && this.params.length > 0) { - this.generateFromTemplate(lines, this.templateParamReplace, this.paramTemplate, this.params); - if (this.newLineAfterParams === true) { - lines.push(this.commentPrefix); - } - } - - if (this.returnTemplate.trim().length !== 0 && this.retVals.length > 0) { - if (this.includeTypeAtReturn === false) { - this.retVals = this.retVals.map((t) => t === "true" || t === "false" || t === "null" ? t : ""); - } - - this.generateFromTemplate(lines, this.templateTypeReplace, this.returnTemplate, this.retVals); - } - - if (this.lastLine.trim().length !== 0) { - lines.push(this.lastLine); - } - - const comment: string = lines.join("\n" + this.getIndentation()); - return comment; - } - - protected moveCursurToFirstDoxyCommand(comment: string, baseLine: number, baseCharacter) { - // Find first offset of a new line in the comment. Since that's when the line where the first param starts. - let line: number = baseLine; - let character: number = comment.indexOf("\n"); - - // If a first line is included find the 2nd line with a newline. - if (this.firstLine.trim().length !== 0) { - line++; - const oldCharacter: number = character; - character = comment.indexOf("\n", oldCharacter + 1) - oldCharacter; - } - - // If newline is not found means no first param was found so Set to base line before the newline. - if (character < 0) { - line = baseLine; - character = baseCharacter; - } - - const moveTo: Position = new Position(line, character); - this.activeEditor.selection = new Selection(moveTo, moveTo); - } -} diff --git a/src/DocGen/CppGen.ts b/src/DocGen/CppGen.ts deleted file mode 100644 index c13d194..0000000 --- a/src/DocGen/CppGen.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Position, Range, Selection, TextEditor, TextLine, WorkspaceEdit } from "vscode"; -import CGen from "./CGen"; - -export default class CppGen extends CGen { - // For now C++ is the same as C -} diff --git a/src/DocGen/DocGen.ts b/src/DocGen/DocGen.ts deleted file mode 100644 index 1b5b1e1..0000000 --- a/src/DocGen/DocGen.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Range } from "vscode"; - -export interface IDocGen { - /** - * @brief Generate documentation string and write it to the active editor - * @param {Range} rangeToReplace Range to replace with the generated comment. - */ - GenerateDoc(rangeToReplace: Range); -} |