Extending a class

IDEA doesn't have any quick way to extend a class at the moment. There are three requests in the tracker for this functionality. There may be others.

http://www.intellij.net/tracker/idea/viewSCR?publicId=3108
http://www.intellij.net/tracker/idea/viewSCR?publicId=29189
http://www.intellij.net/tracker/idea/viewSCR?publicId=37728

The first is over 2 years old.

I have needed this many times. Jetbrains - please add this soon.

Thank you,
Rick

8 comments

I wonder if we really need such a function. idea does it in a better way, without dialog, without mouse, just keyboard. Did tried the ctrl+u /ctrl +i. what you need is to manually add extends/implements keyword and press these 2 keys.

0

http://www.intellij.net/tracker/idea/viewSCR?publicId=3108


This seems to be really counterproductive. When you have selected what
class to extend, you already written extends <class-name> implements
<interface-name>. -5

http://www.intellij.net/tracker/idea/viewSCR?publicId=29189


This seems to be the best choice. Convenient, smoothly integrated as the
other intentions. +1

http://www.intellij.net/tracker/idea/viewSCR?publicId=37728


Seems to be a little bit related to the first RFE. -3

Tom

0

It really doesn't have to be an either/or choice. I have found myself
searching for both options at different points in my development.

I think that the "Extend Class" and "Implement Interface" intentions
probably fit in with the IDEA way of doing things better. Plus it would
make it easier to change an existing class so that it extends a class or
implements an interface.

Since IDEA already has a "new Class" dialog it wouldn't be a big deal to
add optional fields for a class to extend and/or interfaces to
implement. I wouldn't take it any further than that though. It doesn't
need to be a full blown wizard. The existing intentions work fine for
defining constructors, implementing and overriding methods, and adding
properties.

Tim

0

Since IDEA already has a "new Class" dialog


Do you mean the simple one, where one can just enter the Class' name?
Sorry, but adding more input fields (or even tables) to add extends and
implements clauses seems not that cool.

IMHO it would be better to have these actions:

- Select a non-final class in the project window and invoke "Subclass"
to create a new class in the same package using the existing simple "New
Class" dialog.

- Select a interface in the project window and invoke "Implement" to
create a new class in the same package using the existing simple "New
Class" dialog.

- If a non-final class is open and the focus is at the
class-declaration, you can hit +, select "Subclass" to create a new class in the same package using the existing simple "New Class" dialog. - If a class is open, you always can invoke an action "Implement" to get a +]]>-like dialog, where you can select an interface, which
automatically will be added to the "implements" clause. Maybe another
"Implement methods" dialog is shown to pick the methods to implement.

This would be IDEA-ish. The suggested enhanced "New Class" dialog
looks to me like yet another JBuilder/Eclipse feature for
point-and-click-developers.

Tom

0

I agree with your descriptions of the required intention actions. As I
said previously, that would definitely be more "IDEA-ish" and probably
what I would use most of the time.

There is one use case that I think you overlooked. What if you want to
create a new class that extends a class that is not in your project
(packages) window? You would have to click on the "Show Library
Contents" button, or switch to the project tab, so that it is displayed,
navigate to the class to extend and then invoke "Subclass"? I guess
that you could Ctrl-N to open up the class in the editor, Alt-F1 to
navigate to it in the project window and then invoke "Subclass". Either
way it seems a little involved to me.

I don't like to see all of my library contents in my project (packages)
window. So I would have to create the class using the current "new
Class" dialog and subsequently invoke the "Subclass" intention while the
focus is at the class-declaration.

Also, I still don't think that IDEA should ignore the
"point-and-click-developers" just because adding a couple of fields
"seems not that cool".

IDEA is about enhancing productivity and improving the development
experience. I don't think that adding a couple of fields to the "new
Class" dialog, which some would find useful, detracts in any way from
the experience of those who would not use them.

If you work entirely with intentions, you probably would never even
invoke the current "new Class" dialog other than the very first class
that you create in a brand new project. Maybe not even then if it
extends a class in one of your libraries. You would either use one of
your new intentions or just type the (non-existent) class name in your
code and invoke the "Create Class" intention, so you wouldn't even see
any potential changes to the "new Class" dialog.

BTW, the "Create Class" intention will include the implements clause if
you type something like this:

AccessibleAction action = new AccessibleActionImpl();

where AccessibleAction is an interface. And the extends clause if you
type something like this:

AccessibleActionImpl action2 = new AccessibleActionImpl2();

where AccessibleActionImpl is a class.

- Tim

0

There needs to be several places for extending an existing class.

1) If I want to extend the class currently in the editor I should get an "extend" intention if the cursor is on the class declaration.

2) There should be an "extend" menu added to the refactor context menu of a class. This, of course, shows up when right clicking in an editor or in a class in one of the various package/class trees.

3) The New Class and New Interface dialogs should have optional selectors for picking an extends and implements.

Options 1 and 2 should prompt for the package of the new class - don't just assume the same package as the base class - this would rarely be the right place. Basically this would be the same as the current "Create Class" intention that exists when the cursor is on an unknown class reference.

No fancy wizards are needed. All the above fits quite well into the current IDEA model. Once the new class is created I can use all the other wonderful features to add constructors and methods.

Thanks,
Rick

0

Thomas Singer (MoTJ) wrote:

- If a non-final class is open and the focus is at the
class-declaration, you can hit <Alt>+<Enter>, select "Subclass" to
create a new class in the same package using the existing simple "New
Class" dialog.


This is the method I would use the most. My suggestion: Alt-Enter,
select Subclass action press Enter, type the name of the new class,
press Enter, select the package (defaults to current package), press
Enter. Done.

For same-package case, it's as easy as: Alt-Enter, Subclass, Enter,
name, Enter, Enter.

--
Rob Harwood
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0

Tim Haley wrote:

There is one use case that I think you overlooked. What if you want to
create a new class that extends a class that is not in your project
(packages) window? You would have to click on the "Show Library
Contents" button, or switch to the project tab, so that it is displayed,
navigate to the class to extend and then invoke "Subclass"? I guess
that you could Ctrl-N to open up the class in the editor, Alt-F1 to
navigate to it in the project window and then invoke "Subclass". Either
way it seems a little involved to me.


This would be covered by the intention method. Ctrl-N, base class name,
Enter, Alt-Enter, Subclass action, ... etc.

--
Rob Harwood
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0

Please sign in to leave a comment.