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

Conversation

muhabdulkadir
Copy link
Contributor

@muhabdulkadir muhabdulkadir commented Oct 29, 2024

Closes #

Changes

In creating a connected graph, we observe that the relationship between declarations and fields are not reflected as expected. Specifically, when a field has a decorator, the associated decorator is not included in the filtered model manager, leading to an error due to failed decorator validation.

This change add the edge to reflect the relationship between the parent declaration and it's fields.

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

@coveralls
Copy link

coveralls commented Oct 29, 2024

Coverage Status

coverage: 98.771% (-0.02%) from 98.794%
when pulling 2c40067 on muhabdulkadir:main
into 02644a1 on accordproject:main.

lib/common/graph.js Outdated Show resolved Hide resolved
test/common/__snapshots__/graph.js.snap Outdated Show resolved Hide resolved
test/common/__snapshots__/graph.js.snap Outdated Show resolved Hide resolved
Signed-off-by: muhammed-abdulkadir <[email protected]>
lib/common/graph.js Show resolved Hide resolved
test/common/__snapshots__/graph.js.snap Show resolved Hide resolved
lib/common/graph.js Outdated Show resolved Hide resolved
@dselman
Copy link
Contributor

dselman commented Oct 31, 2024

I think we can divide this into a couple of sub-tasks:

  1. Function that gets the set of types for a decorator (decorator declaration, if present, as well as all types references from decorator arguments that exist)
  2. Unit tests for this function, checking its behaviour when decorator declaration is present/absent and when decorator argument types are present/absent.

Create the edges from the elements that can have decorators applied:

  • Namespace
  • Declarations (Enum, Concept, Scalar, Map)
  • Enum Values
  • Concept Properties
  • Map Keys and Values

We don't currently represent properties as nodes in the graph, so I think that decorators applied on Enum Values, Concept Properties, Map Keys and Values will need to be "hoisted" onto their parent declaration (taking care to remove duplicates!). This can be a second function, to get the node name for a model element (which could be based on the FQN of the element, or the FQN of the parent of the element).

I.e. if I have something like:

concept pii extends Decorator {}

concept Person {
   @pii
   o String name
}

We will create a graph with 2 nodes, one for the Person concept and one for the declaration of the pii decorator, with a single edge from Person to pii.

If we have this, however:

concept Category {}

concept Person {
   @pii(Category)
   o String name
}

I would expect a graph with 2 nodes, one for Person and one for Category, with an edge from Person to Category. The pii decorator does not appear in the graph because it was not declared.

With this:

concept pii extends Decorator {
   o Category category
}

concept Category {}

concept Person {
   @pii(Category)
   o String name
}

I would expect a graph with 3 nodes, one for Person, one for pii and one for Category, with an edge from Person to pii and an edge from pii to Category, and an edge from Person to Category.

I would start by creating some test model files for these scenarios and making sure that the tests fail given the current code. I'd then start to refine the code until the tests pass.

We will want to create test files for all the model elements that can have decorators applied.

muhammed-abdulkadir added 2 commits October 31, 2024 14:21
Copy link
Contributor

@dselman dselman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking very nice. One comment on the snap...

More generally.

I don't understand how the functionality is split between ConcertoGraphVisitor and its base class DiagramVisitor. If I've understood this correctly the DiagramVisitor is writing PlantUML output to the FileWriter and then we specialise that to build a graph.

Those two operations don't appear to be related, or at least graph building is not a specialisation of PlantUML output. Why don't we just have two separate visitors, one for building a graph, one for PlantUML output?

I'm also not convinced that we need parameters.stack in ConcertoGraphVisitor - where we read the stack it seems to be to determine the parent ClassDeclaration of a field, relationship etc. We can get that by calling getParent on the field, relationship.

@mttrbrts
Copy link
Member

I don't understand how the functionality is split between ConcertoGraphVisitor and its base class DiagramVisitor. If I've understood this correctly the DiagramVisitor is writing PlantUML output to the FileWriter and then we specialise that to build a graph.

I take responsibility for this one. ...

DiagramVisitor was originally less diagram specific, and was a helpful default visitor implementation so that the specialized visitors could avoid duplicating the tree navigation logic. I agree that it would make sense to further hoist the navigation logic, and specialise the Diagram visitor from it.

muhammed-abdulkadir added 2 commits October 31, 2024 19:02
Signed-off-by: muhammed-abdulkadir <[email protected]>
Signed-off-by: muhammed-abdulkadir <[email protected]>
lib/common/graph.js Outdated Show resolved Hide resolved
@mttrbrts mttrbrts requested a review from dselman November 1, 2024 12:49
lib/common/graph.js Outdated Show resolved Hide resolved
Copy link
Contributor

@dselman dselman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great. Just doc updates...

@muhabdulkadir muhabdulkadir changed the title fix(graph): add edge to map relationship between declarations and fields fix(graph): add edge to map relationship between declarations and decorators on fields Nov 1, 2024
Copy link
Contributor

@dselman dselman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@dselman dselman merged commit c0dd873 into accordproject:main Nov 1, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants