Eclipse JDT Refactor method programatically fails in subclass

95 views Asked by At

I am using org.eclipse.jdt.core.IMethod and calling method.rename(newName, true, new NullProgressMonitor()); on an interface.

It refactors interface method, but fails to refactor its implementation classes-methods.

For example:

interface Animal {
    void eat(); // refactors here
}

class Dog implements Animal {

    // fails to refactor this
    void eat() {
    }
}

Kindly help!

2

There are 2 answers

1
JnRouvignac On

It looks correct.

The code should look for implementations of this method (through the Java Search Engine API) and accordingly rename the overriding methods as part of that same refactoring.

0
Shrikanth On

Thanks Gosu!

But this works for me!

RenameMethodProcessor processor = new RenameVirtualMethodProcessor(method);
        processor.setNewElementName(newName);
        processor.setUpdateReferences(true);

        RenameRefactoring refactoring = new RenameRefactoring(processor);


        refactoring.checkAllConditions(new NullProgressMonitor());
        Change res = refactoring.createChange(new NullProgressMonitor());

        res.perform(new NullProgressMonitor());