Eclipse style quick fix to create new construct

In Eclipse 3, if I've the following class definition

and some place I write code to create a new Foo instance, using a constructor that doesn't exist, for example

the IDE will provide a quick fix that can be selected to automatically create a matching constructor in the Foo class. In other words, it'll change the Foo class definition to

The Eclipse quick fix feature provides similar solutions when invoking methods that don't yet exist, and when referencing a class that doesn't yet exist.

Does IDEA 4 have a similar feature? If so, how do I make use of it?

Thank you

Comment actions Permalink

Since the constructor/method doesn't exist, IDEA will flag it in red as an error. If your cursor is positioned at the error, you will see an intention at the left margin. Clicking that or, alternatively, hitting ALT-ENTER will create the missing constructor/method. Its pretty neat and something I use every day.

Comment actions Permalink

What you've described is more or less what I'd hoped for.

What I was doing was positioning the cursor within the apparent error area - the part with the red squiggly line under it. But no intentions would appear, and pressing Alt+Enter did nothing - not even show "no suggestions" as I'd at least expected.

At your insistence that the feature I want is present, I played around a bit more and discovered that I have to move the cursor over to the left of the red squiggly area, where the name of the missing Constructor or method appears. Then I have the intentions available.

That's a little inconvenient. I'd prefer to just hit Alt+Enter while at the end of the line to get the suggested fixes.

Thanks for the reply.

Comment actions Permalink

I just did a quick test with your example. When the cursor is at the end of the line, the intention appears and pressing ALT-ENTER does in fact bring up a suggestion for creating a constructor.

However, the intention disappears when the cursor is within the error (underlined) area as you said. IDEA at this point is telling you that you are misusing the constructor and I think it is doing the correct thing.

Of course, it would be more helpful, or intelligent, if you'd excuse the pun, if IDEA could also suggest the create constructor intention.

Comment actions Permalink

I re-tested my example and my experience is not as you've stated yours to be. I'm using IDEA 4.0.3 build 1182.

For me, the intentions menu and/or any suggestions definitely do not present themselves when the cursor is at the end of the line - even if pressing Alt+Enter, which does nothing.

As I stated, I have to move the cursor to the characters left of the squiggly area - this is where the name of the Constructor or method appears.

With Eclipse 3, the quick fix icon is always present, left of the line with the error. It's very convenient. I wish the intentions menu were like this.


Please sign in to leave a comment.