Skip to content

Commit

Permalink
Merge pull request #41 from bafolts/abstract-properties
Browse files Browse the repository at this point in the history
Add support for abstract properties
  • Loading branch information
bafolts authored Jun 16, 2019
2 parents b8ddd11 + 7d30860 commit 0a2b84e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tplant",
"version": "2.3.0",
"version": "2.3.1",
"description": "Typescript to PlantUML",
"keywords": [
"class diagram",
Expand Down
9 changes: 7 additions & 2 deletions src/Components/Property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class Property implements IComponentComposite {
public readonly name: string;
public modifier: Modifier = 'public';
public returnType: string = 'any';
public isAbstract: boolean = false;
public isOptional: boolean = false;
public isStatic: boolean = false;

Expand All @@ -18,7 +19,11 @@ export class Property implements IComponentComposite {
}

public toPUML(): string {
return `${{ public: '+', private: '-', protected: '#' }[this.modifier]}${(this.isStatic ? '{static} ' : '')
}${this.name}${(this.isOptional ? '?' : '')}: ${this.returnType}`;
let result: string = { public: '+', private: '-', protected: '#' }[this.modifier];
result += (this.isAbstract ? '{abstract} ' : '');
result += (this.isStatic ? '{static} ' : '');
result += `${this.name}${(this.isOptional ? '?' : '')}: ${this.returnType}`;

return result;
}
}
1 change: 1 addition & 0 deletions src/Factories/PropertyFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export namespace PropertyFactory {
export function create(signature: ts.Symbol, namedDeclaration: ts.NamedDeclaration, checker: ts.TypeChecker): Property {
const result: Property = new Property(signature.getName());
result.modifier = ComponentFactory.getMemberModifier(namedDeclaration);
result.isAbstract = ComponentFactory.isAbstract(namedDeclaration);
result.isOptional = ComponentFactory.isOptional(<ts.PropertyDeclaration>namedDeclaration);
result.isStatic = ComponentFactory.isStatic(namedDeclaration);
result.returnType = checker.typeToString(checker.getTypeOfSymbolAtLocation(signature, signature.valueDeclaration));
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { tplant } from './tplant';
const AVAILABLE_PLANTUML_EXTENSIONS: string[] = ['svg', 'png', 'txt'];

commander
.version('2.3.0')
.version('2.3.1')
.option('-i, --input <path>', 'Define the path of the Typescript file')
.option('-o, --output <path>', 'Define the path of the output file. If not defined, it\'ll output on the STDOUT')
.option(
Expand Down
3 changes: 2 additions & 1 deletion test/Playground/Abstract/AbstractClass.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
abstract class AbstractClass {
abstract ToTest();
}
abstract PropTest: number;
}
3 changes: 2 additions & 1 deletion test/playground.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('Parse Playground codes', () => {
['@startuml',
'abstract class AbstractClass {',
' +{abstract} ToTest(): any',
' +{abstract} PropTest: number',
'}',
'@enduml'].join(os.EOL)
);
Expand Down Expand Up @@ -250,4 +251,4 @@ describe('Parse Playground codes', () => {
'}',
'@enduml'].join(os.EOL));
});
});
});

0 comments on commit 0a2b84e

Please sign in to comment.