Skip to content

Commit

Permalink
fix(filewriter): disable visitor from calling the file writer
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammed Abdulkadir <[email protected]>
  • Loading branch information
Muhammed Abdulkadir committed Sep 20, 2024
1 parent 1023ba9 commit fdcadd3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
3 changes: 0 additions & 3 deletions lib/common/diagramvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ class DiagramVisitor {
*/
visitScalarField(field, parameters) {
this.visitField(field.getScalarField(), parameters);
field.getDecorators().forEach(decorator => decorator.accept(this, parameters));
}

/**
Expand All @@ -222,7 +221,6 @@ class DiagramVisitor {
if(field.isArray()) {
array = '[]';
}
field.getDecorators().forEach(decorator => decorator.accept(this, parameters));
parameters.fileWriter.writeLine(1, '+ ' + field.getType() + array + ' ' + field.getName());
}

Expand All @@ -233,7 +231,6 @@ class DiagramVisitor {
* @protected
*/
visitEnumValueDeclaration(enumValueDeclaration, parameters) {
enumValueDeclaration.getDecorators().forEach(decorator => decorator.accept(this, parameters));
parameters.fileWriter.writeLine(1, '+ ' + enumValueDeclaration.getName());
}

Expand Down
8 changes: 4 additions & 4 deletions lib/common/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class ConcertoGraphVisitor extends DiagramVisitor {
* @protected
*/
visitScalarField(scalar, parameters) {
super.visitScalarField(scalar, parameters);
scalar.getDecorators().forEach(decorator => decorator.accept(this, parameters));
parameters.graph.addEdge(parameters.stack.slice(-1), scalar.getFullyQualifiedTypeName());
}

Expand All @@ -271,7 +271,7 @@ class ConcertoGraphVisitor extends DiagramVisitor {
* @protected
*/
visitField(field, parameters) {
super.visitField(field, parameters);
field.getDecorators().forEach(decorator => decorator.accept(this, parameters));
if (!ModelUtil.isPrimitiveType(field.getFullyQualifiedTypeName())) {
parameters.graph.addEdge(parameters.stack.slice(-1), field.getFullyQualifiedTypeName());
}
Expand All @@ -284,7 +284,7 @@ class ConcertoGraphVisitor extends DiagramVisitor {
* @protected
*/
visitRelationship(relationship, parameters) {
super.visitRelationship(relationship, parameters);
relationship.getDecorators().forEach(decorator => decorator.accept(this, parameters));
parameters.graph.addEdge(parameters.stack.slice(-1), relationship.getFullyQualifiedTypeName());
}

Expand All @@ -295,7 +295,7 @@ class ConcertoGraphVisitor extends DiagramVisitor {
* @protected
*/
visitEnumValueDeclaration(enumValueDeclaration, parameters) {
super.visitEnumValueDeclaration(enumValueDeclaration, parameters);
enumValueDeclaration.getDecorators().forEach(decorator => decorator.accept(this, parameters));
return;
}
}
Expand Down
3 changes: 0 additions & 3 deletions test/codegen/fromcto/plantuml/plantumlvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ describe('PlantUMLVisitor', function () {
let mockField = sinon.createStubInstance(Field);
mockField.isField.returns(true);
mockField.getType.returns('string');
mockField.getDecorators.returns([]);
mockField.getName.returns('Bob');
mockField.getParent.returns({
getFullyQualifiedName: () => { return 'org.acme.Human'; },
Expand All @@ -562,7 +561,6 @@ describe('PlantUMLVisitor', function () {
let mockField = sinon.createStubInstance(Field);
mockField.isField.returns(true);
mockField.getType.returns('string');
mockField.getDecorators.returns([]);
mockField.getName.returns('Bob');
mockField.isArray.returns(true);
mockField.getParent.returns({
Expand All @@ -583,7 +581,6 @@ describe('PlantUMLVisitor', function () {

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

plantUMLvisitor.visitEnumValueDeclaration(mockEnumValueDecl, param);
Expand Down
10 changes: 3 additions & 7 deletions test/common/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const {
const { ModelManager } = require('@accordproject/concerto-core');
const fs = require('fs');
const { expect } = require('expect');
const sinon = require('sinon');

const chai = require('chai');
const { InMemoryWriter } = require('@accordproject/concerto-util');
Expand All @@ -32,7 +31,6 @@ chai.use(require('chai-things'));

describe('graph', function() {
let modelManager = null;
let mockFileWriter;

before(function() {
process.env.ENABLE_MAP_TYPE = 'true'; // TODO Remove on release of MapType
Expand All @@ -50,7 +48,6 @@ describe('graph', function() {
'utf-8'
);
modelManager.addCTOModel(hr, 'hr.cto');
mockFileWriter = sinon.createStubInstance(InMemoryWriter);
});

describe('#visitor', function() {
Expand All @@ -60,7 +57,7 @@ describe('graph', function() {
const writer = new InMemoryWriter();

const graph = new DirectedGraph();
modelManager.accept(visitor, { graph, fileWriter: mockFileWriter });
modelManager.accept(visitor, { graph });

writer.openFile('graph.mmd');
graph.print(writer);
Expand Down Expand Up @@ -157,7 +154,7 @@ describe('graph', function() {
const writer = new InMemoryWriter();

const graph = new DirectedGraph();
modelManager.accept(visitor, { graph, fileWriter: mockFileWriter });
modelManager.accept(visitor, { graph });

const connectedGraph = graph.findConnectedGraph(
'[email protected]'
Expand Down Expand Up @@ -261,8 +258,7 @@ describe('graph', function() {
const graph = new DirectedGraph();
modelManager.accept(visitor, {
graph,
createDependencyGraph: true,
fileWriter: mockFileWriter
createDependencyGraph: true
});

writer.openFile('graph.mmd');
Expand Down

0 comments on commit fdcadd3

Please sign in to comment.