Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graph): add edge to map relationship between declarations and decorators on fields #148

Merged
merged 11 commits into from
Nov 1, 2024
2 changes: 2 additions & 0 deletions lib/common/diagramvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class DiagramVisitor {
*/
visitMapDeclaration(mapDeclaration, parameters) {
mapDeclaration.getDecorators().forEach(decorator => decorator.accept(this, parameters));
mapDeclaration.getKey().getDecorators().forEach(decorator => decorator.accept(this, parameters));
mapDeclaration.getValue().getDecorators().forEach(decorator => decorator.accept(this, parameters));
return;
}

Expand Down
44 changes: 24 additions & 20 deletions lib/common/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,12 @@ class ConcertoGraphVisitor extends DiagramVisitor {
* @protected
*/
visitClassDeclaration(classDeclaration, parameters) {
parameters.stack ??= [];
parameters.stack.push(classDeclaration.getFullyQualifiedName());
parameters.graph.addVertex(classDeclaration.getFullyQualifiedName());

if (classDeclaration.getSuperType()){
parameters.graph.addEdge(classDeclaration.getFullyQualifiedName(), classDeclaration.getSuperType());
// this "if" block adds the types that extend the Super type
if(!parameters.createDependencyGraph && classDeclaration.getSuperType() !== '[email protected]') {
parameters.graph.addVertex(classDeclaration.getSuperType());
parameters.graph.addEdge(classDeclaration.getSuperType(), classDeclaration.getFullyQualifiedName());
}
muhabdulkadir marked this conversation as resolved.
Show resolved Hide resolved
}
super.visitClassDeclaration(classDeclaration, parameters);
parameters.stack.pop();
}

/**
Expand All @@ -215,15 +207,27 @@ class ConcertoGraphVisitor extends DiagramVisitor {
super.visitDecorator(decorator, parameters);
const parent = decorator.getParent();
const modelFile = parent.getModelFile();
decorator.getArguments()?.forEach(argument => {
if(argument && argument.name) {
const fqn = modelFile.getFullyQualifiedTypeName(argument.name);
if (fqn) {
parameters.graph.addVertex(fqn);
muhabdulkadir marked this conversation as resolved.
Show resolved Hide resolved
(parent === modelFile) ? parameters.graph.addEdge(parent.getNamespace(), fqn) : parameters.graph.addEdge(parent.getFullyQualifiedName(), fqn);
}
}
});
// Process the decorator name and arguments in a unified way
const namesToProcess = [
decorator.name,
...(decorator.getArguments()?.map(arg => arg?.name).filter(Boolean) || [])
];
namesToProcess.forEach(name => this.addEdgeForDecorator(name, parent, modelFile, parameters));
}

addEdgeForDecorator(name, parent, modelFile, parameters) {
const fqn = modelFile.getFullyQualifiedTypeName(name);
if (fqn) {
parameters.graph.addVertex(fqn);

// Determine parent FQN based on property type
const type = modelFile.getModelManager().getType(fqn);
const isParentPropertyType = parent.isField?.() || parent.isRelationship?.() || parent.isEnumValue?.() || parent.isKey?.() || parent.isValue?.();
let parentFqn = isParentPropertyType ? parent.getParent().getFullyQualifiedName() : parent.getFullyQualifiedName?.();
parentFqn ??= parent.getNamespace(); //parent is a modelfile

parameters.graph.addEdge(parentFqn, type.getFullyQualifiedName());
}
}

/**
Expand Down Expand Up @@ -264,7 +268,7 @@ class ConcertoGraphVisitor extends DiagramVisitor {
*/
visitScalarField(scalar, parameters) {
super.visitScalarField(scalar, parameters);
parameters.graph.addEdge(parameters.stack.slice(-1), scalar.getFullyQualifiedTypeName());
parameters.graph.addEdge(scalar.getParent().getFullyQualifiedName(), scalar.getFullyQualifiedTypeName());
}

/**
Expand All @@ -276,7 +280,7 @@ class ConcertoGraphVisitor extends DiagramVisitor {
visitField(field, parameters) {
super.visitField(field, parameters);
if (!ModelUtil.isPrimitiveType(field.getFullyQualifiedTypeName())) {
parameters.graph.addEdge(parameters.stack.slice(-1), field.getFullyQualifiedTypeName());
parameters.graph.addEdge(field.getParent().getFullyQualifiedName(), field.getFullyQualifiedTypeName());
}
}

Expand All @@ -288,7 +292,7 @@ class ConcertoGraphVisitor extends DiagramVisitor {
*/
visitRelationship(relationship, parameters) {
super.visitRelationship(relationship, parameters);
parameters.graph.addEdge(parameters.stack.slice(-1), relationship.getFullyQualifiedTypeName());
parameters.graph.addEdge(relationship.getParent().getFullyQualifiedName(), relationship.getFullyQualifiedTypeName());
}

/**
Expand Down
Loading
Loading