Type of an Expression: how to set it, how to inherit from the parent type?


First of all, sorry if my question will not be really easy to understand, I will try to do my best to explain it clearly.

In my DSL, I have the concept OccurrenceExpression which extends Expression (from the BaseLanguage). The purpose of this concept is to be quite similar to the "this" keyword of Java: in a "OnDeclaration" context, I want to have the occurrence keyword to refer to an Event object.

Basically, it will be used like this:

event MyEvent { // The user declare an event

  public int myAttribute;


on MyEvent {

  if(occurrence.myAttribute == 0) {  // occurrence is a reference to a MyEvent object because the context is on MyEvent




The OccurrenceExpression concept is storing a reference to an event: ClassifierType[1].

So, I want to have OccurrenceExpression of the type of the event object in order to be able to access to the attributes of the event. To do this, in the typesystem I have :

Firstly, is this the right way to do it? By doing it, I have access to the attribute of the event using the occurrence keyword, so it seems good?

As you can see, I have also access to the method of the Object class, which is nice. However, the supertype of Event is the Java class io.sarl.core.Event, and I do not have access to the attributes and methods of the io.sarl.core.Event. I don't really understand why.

I tried to do some things like this:

But it does not work, I have either access to the attributes of the io.sarl.core.Event class (in the quotation here) or the attributes to Event concept, but never both and I don't understand why.

It's like having the autocompletion of the this keyword showing the attributes of the current class, but not the attributes of the superclass.

Thank you in advance for any suggestion.

1 comment
Comment actions Permalink

I wouldn't store the reference to the event in the OccurrenceExpression (how do you set it initially? how do you keep it up to date if the event changes or if the code gets copied and pasted?). I'd prefer to use a behavior method to find it from context.

The type of the OccurrenceExpression should be a ClassifierType whose classifier points to the event.

You can check the resulting type of the expression by pressing Ctrl+Shift+T on it. Then a dialog will appear and on the right-hand side you can see the supertypes hierarchy. You can check that to make sure it looks as intended. If not, post the screenshot of what it looks like.


Please sign in to leave a comment.