ripper234
ripper234

Reputation: 230038

'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 correct 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".

Upvotes: 7

Views: 5630

Answers (4)

TimT
TimT

Reputation: 1684

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

Upvotes: 6

Saintali
Saintali

Reputation: 4571

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.

Upvotes: 0

Jonik
Jonik

Reputation: 81761

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.)

Upvotes: 2

Hugo Palma
Hugo Palma

Reputation: 3566

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

Upvotes: 2

Related Questions