2015-06-12 17 views
0

我正在使用org.eclipse.jdt.core.IMethod並在接口上調用method.rename(newName, true, new NullProgressMonitor());Eclipse JDT重構方法在子類中編程失敗

它重構了接口方法,但未能重構其實現類方法。

例如:

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

class Dog implements Animal { 

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

請幫助!

回答

0

看起來正確。

代碼應查找此方法的實現(通過Java Search Engine API),並相應地將重寫方法重命名爲同一重構的一部分。

+0

謝謝。但沒有:(但發現一個備用(請參閱我的答案) – Shrikanth

0

謝謝Gosu!

但是這對我有用!

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());