How to Add unimplemented methods from Interfaces with Xtend

336 Views Asked by At

Does anyone know, how to do the quickfix to add unimplemented methods from an Interface with Xtend code ?

1

There are 1 best solutions below

0
On

I assume you have an interface MyInterface that declares a method void aMethod() and a class ImplementingClass implements MyInterface and you want to know the syntax to implement aMethod().

Using Xtend's ProposalProvider in Eclipse provides either to implement the unimplemented methods or to make ImplementingClass abstract.

Xtend's ProposalPRovider in Eclipse.

Using the Add unimplemented methods proposal the overriding method will be automatically generated for you. ImplementingClass then looks like this:

class ImplementingClass implements MyInterface {

    override aMethod() {
        throw new UnsupportedOperationException("TODO: auto-generated method stub")
    }

}

As you can see, Xtend has a special keyword overrides to define a method that override an other method. It is used instead of the regular def keyword to define methods.

Simply remove the throw ... expression and implement the moethod.