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

Rename `FamixTParametricEntity >> rootGenericEntity` as `genericEntity` #707

Closed Gabriel-Darbord closed 4 months ago

Gabriel-Darbord commented 5 months ago

The rootGenericEntity method was added with the misconception that concretizations form a recursive tree structure. In practice, every ParametricEntity except the root generic entity is a leaf, so the tree has a height of at most two. So the current implementation, which does an iteration, and the name rootGenericEntity make little sense. I would like to just call it genericEntity, but there is currently a relation with that name so this change depends on #706. This method always returns the generic entity, which usually contains the relevant information, such as the source anchor.

genericEntity

    ^ self genericization
          ifNil: [ self ]
          ifNotNil: [ :concretization | concretization genericEntity ]
NicolasAnquetil commented 4 months ago

May be I misunderstood the issue, but concretization can be a tree (even if it is rare):

If you have a generic with 2 type parameters (like Map<K,V>), then you can have a partial concretization where you specify only type (ex: MapStrings<V> extends MAP<String,V>), and then a complete concretization of this one.

Gabriel-Darbord commented 4 months ago

In the scenario you describe, there is an inheritance relationship between two concretizations: image

A concretization tree always has a height of at most two, because an entity that is concrete can never also be generic in another concretization relation. The following never happens: image

There is always a single generic entity, and possibly several concrete entities: image

The genericEntity method will always return the generic entity (the root) in a concretization relation. This is what this method was intended to do, so this closes the issue.

Finding the root entity through multiple relations is more complicated, and most convenience methods don't take concretizations into account, see #718.