Trait Groups

The fundamental component of the Famix is a trait group. A trait group always describes a fragment of meta-model and can consist of one, two or more entities and relations between them. We can demonstrate it on an example of the *access*. In some meta-model, we have two kinds of entities: local variables and methods. Methods contain a code that reads some local variables or writes data to them. Let's have a program that contains a method named `aMethod` with a local variable named `foo`. It writes data to it and then uses it in a method call.

public void aMethod() { int foo = 5; someMethod(foo); }

Now we will try to model our little program using the meta-model. We will create an object for the method `aMethod`, an object that models the variable `foo` that contains information, wherein the code the instance variable was declared. But one crucial information is missing. We would like where in the code the variable was accessed and what kind of access was that. Was the variable written or read? With such information, we can do a straightforward but useful analysis of the program models and decide, what local variables were not used or just written and never read. To model the association between the variable and method, we will introduce a new kind of entity in our metamodel: the access. For every access to a local variable, we will create an object that describes is. It will contain information what the accessed local variable was, what method accessed it, wherein the code this concrete access is placed and what kind of access is it (read or write). The Famix provides a meta-model fragment exactly for this use-case. It contains a trait group named Access that describes three entities: access itself (Access), the element that is being accessed (Accessible, in our case, it is the local variable) and an entity that contains accesses (WithAccesses, in case of our meta-model it is the method).

Access trait group

This trait group describes relations between these three entities. So WithAccesses has accesses, Accessible has incomming accesses, and the Access stores information aoubt its accessor and variable. The entities that Famix provides are not real meta-model entities. They cannot be instantiated directly. They are provided in form of traits. That means that you need to apply them on your custom meta-model. That's why in following text they will have a prefix T (meaning trait). The concrete language meta-model will contain three real entities: JavaLocalVariable, JavaMethod and JavaAccess. What we will do is to apply the traits provided by the Famix trait group on them. So JavaAccess will use the trait TAccess, JavaMethod will use the trait TWithAccesses and