Design by Contract in Xtend

Visto 72 veces
Saltar al primer mensaje no leído

Serbest Hammade

no leída,
18 jul 2016, 5:33:1418/7/16
a Xtend Programming Language

Hello,

I'am writing my master thesis about implementing Design by Contract elements in Xtend.
So far i implemented pre- and postcondition for methods and simple ranged invariants for member variable.
An Example:
    def int getSeconds(int hour)
    pre hour range
0 .. 23
    post result range
0 .. 1380
   
{
       
return hour * 60;
   
}  
would be generating following Java code:
    public int getSeconds(final int hour) {
       
assert hour >= 0;
       
assert hour <= 23;
       
int result = getSecondsCall(hour);
       
assert result >= 0;
       
assert result <= 1380;
       
return result;    
   
}
 
   
public int getSecondsCall(final int hour) {
       
return (hour * 60);
   
}
And for class member variable with a numerical type:
    int second range 0 .. 59
to
    private int second;
   
private void invSecond() {
       
assert second >= 0;
       
assert second <= 59;    
   
}
(invSecond is called from the getters and setters)

For that features, I have edited the following files from org.eclipse.xtend.core
  • src/org/eclipse/xtend/core/Xtend.xtext
  • src/org/eclipse/xtend/core/jvmmodel/XtendJvmModelInferrer.java
  • src/org/eclipse/xtend/core/validation/XtendValidator.java
  • model/Xtend.ecore
and added my own rule system to XtendMember. In that way XtendClass, XtendInterface, XtendFunction and XtendField could have rules. (You can find my changes in https://github.com/SHammade/xtext-xtend-dbc/)

So far, so good... Now i want to add inheritance in that way you can add pre- and postconditions on method declaration in interfaces and the classes, which implement these have to implement the pre- and postconditions as well.
But I found no way from Validator or QuickfixProvider to get the declared XtendInterface, only variables from type JvmTypeReference.
Is there a way to get the declared XtendInterface from the JvmTypeReference?

thx,
Serbest
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos