开发者

'Remove middleman' IntelliJ refactoring on an empty interface

I have an interface which is now empty, and extends another interface. I'd like to remove the empty interface and use the base interface, and am trying to find the correc开发者_开发知识库t refactoring in IntelliJ.

I've tried "remove middleman" but got "cannot perform the refactoring. The caret should be positioned at the name of the field to be refactored".


I think what you want to do is the "inline" refactor on the unwanted interface, e.g.

If

 
class Thing implements ThingA

and

interface ThingA extends ThingB

To get rid of ThingA

you do and inline (ctrl + alt + n) when the caret is on ThingA, you end up with:

class Thing implements ThingB


I think that what you're looking for is the "Type Migration" refactoring.


Looking at a blog post explaining the "Remove Middleman" refactoring in IDEA, I'd think you simply cannot use it for this. It's just for "replacing all calls to delegating methods with the equivalent direct calls".

(For a moment I thought another refactoring, "Use Interface Where Possible", might be of help, but I couldn't get that working either in my simple test case.)


The best way to remove uses of an empty interface is through "Use interface where possible", go to the definition of the interface you want to remove and select "Use interface where possible" from the "Refactor" menu. You should then end up with an unused interface which you can safely delete.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜