Search code examples
supereclipse-emfemfeclipse-emf-ecorexcore

Call super method from Xcore operation


I have the following declarations in Xcore:

class ValueBase { ... }

class ValueArray extends ValueBase
{
  int size
  double [] values
  String valueUnit

  op boolean isValueEqual(Value v) 
  {
    if (!(v instanceof IValueArray))
    {
      return false
    }
    val other = v as IValueArray;
    return Iterables.elementsEqual(this.values, other.values);
  }

  op boolean equals(Value v)
  {
    return super.equals(v) && isValueEqual(v) && 
      (v instanceof IValueArray) &&
      Objects.equals(valueUnit, (v as IValueArray).valueUnit)
  }
}

ValueBase implements its own equals() method. In the concrete class ValueArray, I want to call super.equals() to compare the base class' common fields and then do comparisons specific to the concrete class.

But Xcore complains about that code that it "Couldn't resolve reference to JvmIdentifiableElement super".

How can I call the equals()-method from the super class?


Solution

  • I had to make some assumptions about the code that you don't show here, but the short answer is that it works. You're calling super.equals correctly. But as I said, I had to make some assumptions. So here is what I have that seems to be fine with Xcore.

    package soxcore
    
    import com.google.common.base.Objects
    import com.google.common.collect.Iterables
    
    class ValueBase {
        op boolean equals(Value v)
        {
            return true;
        }
    }
    
    class ValueArray extends ValueBase, IValueArray
    {
      int size
    
      op boolean isValueEqual(Value v) 
      {
        if (!(v instanceof IValueArray))
        {
          return false
        }
        val other = v as IValueArray;
        return Iterables.elementsEqual(this.values, other.values);
      }
    
      op boolean equals(Value v)
      {
        return super.equals(v) && isValueEqual(v) && 
          (v instanceof IValueArray) &&
          Objects.equal(valueUnit, (v as IValueArray).valueUnit)
      }
    }
    
    class Value extends ValueBase
    {
    
    }
    
    interface IValueArray {
        double[] values
        String valueUnit
    }
    

    No complaints from Xcore. So am I missing something?