moosetechnology / Famix

An abstract representation of source code. Famix is generic and can describe applications in multiple programming languages.
MIT License
12 stars 22 forks source link

Asking if an entity is a child or a parent of another entity #739

Closed badetitou closed 2 months ago

badetitou commented 3 months ago

It would be nice if we can be able to assess if an entity is the children of an entity, or its parent. We can rely on the Moose Query infrastructure.

It would be something like:

"entity is java class"
"another entity can be package"
entity query is parentOf: anotherEntity

It would allow to perform check such as, is my class in the package fr.inria.xxx without computing allParentsPackages or allChildren of the package.

@jecisc do you think it is easily feasible with the current infrastructure of MooseQuery? During a Moose dojo @ClotildeToullec?

Or maybe the idea is useless..

Gabriel-Darbord commented 3 months ago

Using a query seems overkill for a 1-step check (going up or down only once). This can be done with: childEntity parents includes: parentEntity. To lazily compute parents, we could have a method in TEntityMetaLevelDependency like:

parentsInclude: anEntity

    self parentsDo: [ :parent | parent == anEntity ifTrue: [ ^ true ] ].
    ^ false

There is currently no childrenDo: for the reverse operation, but this can also be addressed.

NicolasAnquetil commented 3 months ago

not convinced

Maybe a query #allAncestors would be a nice alternative to this ?

jecisc commented 3 months ago

Using a query seems overkill for a 1-step check (going up or down only once). This can be done with: childEntity parents includes: parentEntity. To lazily compute parents, we could have a method in TEntityMetaLevelDependency like:

parentsInclude: anEntity

  self parentsDo: [ :parent | parent == anEntity ifTrue: [ ^ true ] ].
  ^ false

There is currently no childrenDo: for the reverse operation, but this can also be addressed.

The advantage of using a query would be the performances. But I don't know if Benoit need better performances on this for now?

badetitou commented 3 months ago

In fact, I do not need this right now. But I thought about it because of the performance aspect. I also can understand if you think it is overkill and do not want to address this issue :) I know it takes time and there are other projects

badetitou commented 2 months ago

Ok, until real use case, let's close this