Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Refactoring: extract nested class
Refactoring: extract nested class [message #658098] Sun, 06 March 2011 12:02 Go to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Is there a way to extract an inner class (a class fully declared inside
another, not an anonymous one) to make it an external, public one (in
it's own .java file)?
I would have thought it an obvious thing, but I couldn't find a way to
do it (aside from the usual copy & paste, obviously).
I see "Convert anonymous class to nested", but not a "Convert nested to
top level".
There are several commands sounding promising (e.g.: "Extract Class" or
"Move Type to new file"), but they do not do what I need.
Where did You hide this command? ;)

TiA
Mauro
Re: Refactoring: extract nested class [message #658108 is a reply to message #658098] Sun, 06 March 2011 14:57 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
On Sun, 2011-03-06 at 13:02 +0100, Mauro Condarelli wrote:
> Is there a way to extract an inner class (a class fully declared inside
> another, not an anonymous one) to make it an external, public one (in
> it's own .java file)?
> I would have thought it an obvious thing, but I couldn't find a way to
> do it (aside from the usual copy & paste, obviously).
> I see "Convert anonymous class to nested", but not a "Convert nested to
> top level".
> There are several commands sounding promising (e.g.: "Extract Class" or
> "Move Type to new file"), but they do not do what I need.
> Where did You hide this command? ;)
>
> TiA
> Mauro

The Move Type to new file refactoring provides this function. You say
that it doesn't do what you need. Could you provide an example of
exactly what you are trying to do and why Move Type doesn't match your
needs?
Re: Refactoring: extract nested class [message #658111 is a reply to message #658108] Sun, 06 March 2011 16:18 Go to previous message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Il 06/03/2011 15:57, David Wegener ha scritto:
> On Sun, 2011-03-06 at 13:02 +0100, Mauro Condarelli wrote:
>> Is there a way to extract an inner class (a class fully declared inside
>> another, not an anonymous one) to make it an external, public one (in
>> it's own .java file)?
>> I would have thought it an obvious thing, but I couldn't find a way to
>> do it (aside from the usual copy & paste, obviously).
>> I see "Convert anonymous class to nested", but not a "Convert nested to
>> top level".
>> There are several commands sounding promising (e.g.: "Extract Class" or
>> "Move Type to new file"), but they do not do what I need.
>> Where did You hide this command? ;)
>>
>> TiA
>> Mauro
>
> The Move Type to new file refactoring provides this function. You say
> that it doesn't do what you need. Could you provide an example of
> exactly what you are trying to do and why Move Type doesn't match your
> needs?
>
In an Editor generated automatically by EMF ("Generate editor") I have the following:


public class WorldEditor
extends MultiPageEditorPart
implements IEditingDomainProvider, ISelectionProvider, IMenuListener, IViewerProvider {

...

public IContentOutlinePage getContentOutlinePage() {
if (contentOutlinePage == null) {
// The content outline is just a tree.
//
class MyContentOutlinePage extends ContentOutlinePage {
@Override
public void createControl(Composite parent) {
super.createControl(parent);
contentOutlineViewer = getTreeViewer();
contentOutlineViewer.addSelectionChangedListener(this);
....

I want to extract MyContentOutlinePage to its own file.

if I select it (I tried moving cursor on it, selecting the name and selecting the whole class) and then do Refactor->Move Type to New File... I get:

Operation Unavailable
To activate this refactoring, please select the name of a member type or a secondary type.

What am I doing wrong?

TiA
Mauro
Previous Topic:Building eclipse 3.6.2 for win64
Next Topic:Content of http://download.eclipse.org/eclipse/updates/3.6 ?
Goto Forum:
  


Current Time: Thu Apr 25 10:46:07 GMT 2024

Powered by FUDForum. Page generated in 0.02889 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top