Skip to content

Commit

Permalink
feat(visitor): add test and refactor build
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammed-abdulkadir committed Nov 1, 2024
1 parent 236baee commit db152e3
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 129 deletions.
4 changes: 1 addition & 3 deletions lib/common/basevisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ if (global === undefined) {
/* eslint-enable no-unused-vars */

/**
* Convert the contents of a ModelManager a diagram format (such as PlantUML or Mermaid)
* Set a fileWriter property (instance of FileWriter) on the parameters
* object to control where the generated code is written to disk.
* Visitor class that traverses various model elements
*
* @protected
* @class
Expand Down
3 changes: 1 addition & 2 deletions lib/common/diagramvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const BaseVisitor = require('./basevisitor');
/* eslint-disable no-unused-vars */
/* istanbul ignore next */
if (global === undefined) {
const { ModelManager, ModelFile, ClassDeclaration, ScalarDeclaration, Field, EnumValueDeclaration, RelationshipDeclaration, Decorator} = require('@accordproject/concerto-core');
const { ClassDeclaration, Field, EnumValueDeclaration} = require('@accordproject/concerto-core');
}
/* eslint-enable no-unused-vars */

Expand All @@ -35,7 +35,6 @@ if (global === undefined) {
*/
class DiagramVisitor extends BaseVisitor {


/**
* Visitor design pattern
* @param {Field} field - the object being visited
Expand Down
13 changes: 13 additions & 0 deletions test/codegen/fromcto/plantuml/plantumlvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,19 @@ describe('PlantUMLVisitor', function () {

param.fileWriter.writeLine.withArgs(1, '+ Bob').calledOnce.should.be.ok;
});

it('should not write a line for enum value if writer is undefined', () => {
let param = {};


let mockEnumValueDecl = sinon.createStubInstance(EnumValueDeclaration);
mockEnumValueDecl.isEnumValue.returns(true);
mockEnumValueDecl.getName.returns('Bob');
mockEnumValueDecl.getDecorators.returns([]);

plantUMLvisitor.visitField(mockEnumValueDecl, param);
mockEnumValueDecl.getName().never;
});
});

describe('visitDecorator', () => {
Expand Down
131 changes: 131 additions & 0 deletions types/lib/common/basevisitor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
export = BaseVisitor;
/**
* Visitor class that traverses various model elements
*
* @protected
* @class
*/
declare class BaseVisitor {
/**
* Visitor design pattern
* @param {Object} thing - the object being visited
* @param {Object} parameters - the parameter
* @return {Object} the result of visiting or null
* @protected
*/
protected visit(thing: any, parameters: any): any;
/**
* Visitor design pattern
* @param {ModelManager} modelManager - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitModelManager(modelManager: ModelManager, parameters: any): void;
/**
* Visitor design pattern
* @param {ModelFile} modelFile - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitModelFile(modelFile: ModelFile, parameters: any): void;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitAssetDeclaration(classDeclaration: ClassDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitEnumDeclaration(classDeclaration: ClassDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitEventDeclaration(classDeclaration: ClassDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitParticipantDeclaration(classDeclaration: ClassDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitTransactionDeclaration(classDeclaration: ClassDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @param {string} type - the type of the declaration
* @protected
*/
protected visitClassDeclaration(classDeclaration: ClassDeclaration, parameters: any, type?: string): void;
/**
* Visitor design pattern
* @param {ScalarDeclaration} scalarDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitScalarDeclaration(scalarDeclaration: ScalarDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {MapDeclaration} mapDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitMapDeclaration(mapDeclaration: MapDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {Field} field - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitScalarField(field: Field, parameters: any): void;
/**
* Visitor design pattern
* @param {RelationshipDeclaration} relationship - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitRelationship(relationship: RelationshipDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {Field} field - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitField(field: Field, parameters: any): void;
/**
* Visitor design pattern
* @param {EnumValueDeclaration} enumValueDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitEnumValueDeclaration(enumValueDeclaration: EnumValueDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {Decorator} decorator - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitDecorator(decorator: Decorator, parameters: any): void;
}
import { ModelManager } from "@accordproject/concerto-core";
import { ModelFile } from "@accordproject/concerto-core";
import { ClassDeclaration } from "@accordproject/concerto-core";
import { ScalarDeclaration } from "@accordproject/concerto-core";
import { Field } from "@accordproject/concerto-core";
import { RelationshipDeclaration } from "@accordproject/concerto-core";
import { EnumValueDeclaration } from "@accordproject/concerto-core";
import { Decorator } from "@accordproject/concerto-core";
124 changes: 2 additions & 122 deletions types/lib/common/diagramvisitor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,121 +7,7 @@ export = DiagramVisitor;
* @protected
* @class
*/
declare class DiagramVisitor {
/**
* Visitor design pattern
* @param {Object} thing - the object being visited
* @param {Object} parameters - the parameter
* @return {Object} the result of visiting or null
* @protected
*/
protected visit(thing: any, parameters: any): any;
/**
* Visitor design pattern
* @param {ModelManager} modelManager - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitModelManager(modelManager: ModelManager, parameters: any): void;
/**
* Visitor design pattern
* @param {ModelFile} modelFile - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitModelFile(modelFile: ModelFile, parameters: any): void;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitAssetDeclaration(classDeclaration: ClassDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitEnumDeclaration(classDeclaration: ClassDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitEventDeclaration(classDeclaration: ClassDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitParticipantDeclaration(classDeclaration: ClassDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitTransactionDeclaration(classDeclaration: ClassDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @param {string} type - the type of the declaration
* @protected
*/
protected visitClassDeclaration(classDeclaration: ClassDeclaration, parameters: any, type?: string): void;
/**
* Visitor design pattern
* @param {ScalarDeclaration} scalarDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitScalarDeclaration(scalarDeclaration: ScalarDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {MapDeclaration} mapDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitMapDeclaration(mapDeclaration: MapDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {Field} field - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitScalarField(field: Field, parameters: any): void;
/**
* Visitor design pattern
* @param {RelationshipDeclaration} relationship - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitRelationship(relationship: RelationshipDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {Field} field - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitField(field: Field, parameters: any): void;
/**
* Visitor design pattern
* @param {EnumValueDeclaration} enumValueDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitEnumValueDeclaration(enumValueDeclaration: EnumValueDeclaration, parameters: any): void;
/**
* Visitor design pattern
* @param {Decorator} decorator - the object being visited
* @param {Object} parameters - the parameter
* @protected
*/
protected visitDecorator(decorator: Decorator, parameters: any): void;
declare class DiagramVisitor extends BaseVisitor {
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
Expand All @@ -135,11 +21,5 @@ declare namespace DiagramVisitor {
let AGGREGATION: string;
let INHERITANCE: string;
}
import { ModelManager } from "@accordproject/concerto-core";
import { ModelFile } from "@accordproject/concerto-core";
import BaseVisitor = require("./basevisitor");
import { ClassDeclaration } from "@accordproject/concerto-core";
import { ScalarDeclaration } from "@accordproject/concerto-core";
import { Field } from "@accordproject/concerto-core";
import { RelationshipDeclaration } from "@accordproject/concerto-core";
import { EnumValueDeclaration } from "@accordproject/concerto-core";
import { Decorator } from "@accordproject/concerto-core";
4 changes: 2 additions & 2 deletions types/lib/common/graph.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @class
* @memberof module:concerto-util
*/
export class ConcertoGraphVisitor extends DiagramVisitor {
export class ConcertoGraphVisitor extends BaseVisitor {
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
Expand Down Expand Up @@ -85,7 +85,7 @@ export class DirectedGraph {
*/
print(writer: Writer): void;
}
import DiagramVisitor = require("./diagramvisitor");
import BaseVisitor = require("./basevisitor");
import { ClassDeclaration } from "@accordproject/concerto-core";
import { MapDeclaration } from "@accordproject/concerto-core";
import { Writer } from "@accordproject/concerto-util";

0 comments on commit db152e3

Please sign in to comment.