Skip to content

Commit

Permalink
fix(graph): add decorators that ref types to graph (#137)
Browse files Browse the repository at this point in the history
* fix(graph): add decorators that ref types to graph

---------

Signed-off-by: Dan Selman <[email protected]>
  • Loading branch information
dselman authored Sep 20, 2024
1 parent 7c9ab2b commit cc70fae
Show file tree
Hide file tree
Showing 10 changed files with 928 additions and 309 deletions.
2 changes: 1 addition & 1 deletion lib/codegen/fromcto/odata/odatavisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class ODataVisitor {
default:
argType = 'String';
}
parameters.fileWriter.writeLine(4, `<Annotation Term="${decorator.getName()}${index}" ${argType}="${arg.toString()}" />`);
parameters.fileWriter.writeLine(4, `<Annotation Term="${decorator.getName()}${index}" ${argType}="${typeof arg === 'object' ? arg.name : arg.toString()}" />`);
});
return null;
}
Expand Down
18 changes: 13 additions & 5 deletions lib/common/diagramvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@ class DiagramVisitor {
if(field.isArray()) {
array = '[]';
}
parameters.fileWriter.writeLine(1, '+ ' + field.getType() + array + ' ' + field.getName());
field.getDecorators().forEach(decorator => decorator.accept(this, parameters));
if(parameters.fileWriter) {
parameters.fileWriter.writeLine(1, '+ ' + field.getType() + array + ' ' + field.getName());
}
}

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

/**
Expand All @@ -257,9 +263,11 @@ class DiagramVisitor {
if (parameters.hideBaseModel && isBaseModel){
return;
}
const source = this.escapeString(classDeclaration.getFullyQualifiedName());
const target = this.escapeString(classDeclaration.getSuperType());
parameters.fileWriter.writeLine(0, `${source} ${DiagramVisitor.INHERITANCE} ${target}`);
if(parameters.fileWriter) {
const source = this.escapeString(classDeclaration.getFullyQualifiedName());
const target = this.escapeString(classDeclaration.getSuperType());
parameters.fileWriter.writeLine(0, `${source} ${DiagramVisitor.INHERITANCE} ${target}`);
}
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions lib/common/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,16 @@ class ConcertoGraphVisitor extends DiagramVisitor {
* @protected
*/
visitDecorator(decorator, parameters) {
super.visitDecorator(decorator, parameters);
const parent = decorator.getParent();
const modelFile = parent.getModelFile();
decorator.getArguments()?.forEach(argument => {
const fqn = modelFile.getFullyQualifiedTypeName(argument.name);
if (fqn) {
parameters.graph.addVertex(fqn);
(parent === modelFile) ? parameters.graph.addEdge(parent.getNamespace(), fqn) : parameters.graph.addEdge(parent.getFullyQualifiedName(), fqn);
if(argument.name) {
const fqn = modelFile.getFullyQualifiedTypeName(argument.name);
if (fqn) {
parameters.graph.addVertex(fqn);
(parent === modelFile) ? parameters.graph.addEdge(parent.getNamespace(), fqn) : parameters.graph.addEdge(parent.getFullyQualifiedName(), fqn);
}
}
});
}
Expand Down Expand Up @@ -260,7 +263,7 @@ class ConcertoGraphVisitor extends DiagramVisitor {
* @protected
*/
visitScalarField(scalar, parameters) {
scalar.getDecorators().forEach(decorator => decorator.accept(this, parameters));
super.visitScalarField(scalar, parameters);
parameters.graph.addEdge(parameters.stack.slice(-1), scalar.getFullyQualifiedTypeName());
}

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

Expand All @@ -295,7 +298,7 @@ class ConcertoGraphVisitor extends DiagramVisitor {
* @protected
*/
visitEnumValueDeclaration(enumValueDeclaration, parameters) {
enumValueDeclaration.getDecorators().forEach(decorator => decorator.accept(this, parameters));
super.visitEnumValueDeclaration(enumValueDeclaration, parameters);
return;
}
}
Expand Down
Loading

0 comments on commit cc70fae

Please sign in to comment.