6776 - Extract Superclass experience

I just got done doing an "Extract Superclass" refactoring on a
class "Group". The original class was 700 lines of code, which
isn't that big, but the class but the class had about 3000
usages. This is actually the first time I have used "Extract Superclass"
for a very large class. I ran into a number of problems, but most of
them weren't even related to the Extract Superclass.

When you start "Extract Superclass" refactoring, the process
begins fine. A dialog prompts you to tag which methods and
fields you want in the new superclass. (It would be nice if
there was a checkall choice because I wanted to move almost all
methods to the superclass). Also I checked the option "Rename
original class and use superclass where possible." So, in the
end, most of the code should still be using the "Group" class
and only the places using the methods and fields I didn't pull
up to the superclass would use the new subclass "ExplicitGroup".

I then clicked Preview. IDEA then starts finding all the usages
of the fields and methods of the class. Here is where I started
having problems.

Problem #1.
-


Find Usages on class is slow, and appears to do unnecessary work
in some cases. (See below)
-


[/B]
The Find Usages took a long time; About 20 min on an Intel Dual
Core machine. There is a Jira item IDEADEV-12010 "Use compiler
caches to speed up Find Usages" which would potentially be a
huge improvement. But I noticed several places where Find
Usages seemed to be doing unnecessary work:

1.A[/B] This class has a bunch of overloaded static methods like
load() and create() which take different parameters. I must
have seen "Searching for load..." 10 times and each time took
awhile. Seems like it should have searched for all overloaded
usages at one time.

1.B[/B] My project contains server code plus a web module. So, when
I searching for a method getName(), I see "Searching for getName..
" and "Searching for name...". I assume the "Searching for name..
" is searching for it in the Web module, assuming that my class "
Group" is an enterprise java bean? Is there anyway to turn that
behavior off? Does it adhere to dependencies? In my project, the
Web Module depends on the Server module, so that wouldn't help,
but I know that 99% of my server code is not used as enterprise
java beans.

1.C[/B] IDEA says "Searching for getName...", "Searching for name..", "Searching for
setName...", "Searching for name..". It seems like it is searching for "name" twice.

Problem #2.
-


Find Usages doesn't show overall progress. Progress bar keeps
resetting after each "Searcing for xyz..."
-


[/B]
The Find Usages progress window provides no overall measure of
progress. IDEA show the progress for "Searching for load..." and
then when it starts on "Searching for getName..." it starts the
progress over again! This is really poor. If you are doing
Find Usages on a class, IDEA should be showing you the overall
progress on all the methods and fields to be searched for. If
my class has 100 methods and 20 fields, the progress should
shows what % of the 120 searches have been completed.


Problem #3
-


Refactoring Preview doesn't tell you what change will be done
on each usage.
-


[/B]
The refactoring preview just looked like the output from Find
Usages. It doesn't tell me what exactly will be changed for that
usage. This was really confusing in this case because I had
checked "Rename original class and use superclass where possible"
, and I had moved most of the fields and methods to the
superclass, so I was expected most of the usages to require no
change. As it is, I wouldn't even call this "Preview" . What I
would like to see is IDEA give me the option to show me the
before and after for each change.

I realize that for some refactorings, it is obvious what change
will be made, but in this case, on some of them it wasn't clear to
me.

Problem #4
-


Hard to review changes after refactoring done.
-


[/B]
After pressing "Do Refactor", the "Preview" is closed, so I can't
refer back to that, although even if it was there, there is this
issue with lines getting marked INVALID, which means you can no
longer click on them to jump to the file: linenumber. There is
no summary of the changes made. (Related Jira IDEADEV- 13612
"Refactoring result preview")

After I did the refactoring, my code was broken. Something went
wrong with the refactoring. Now, I don't know if this was due to
a real bug that would have happened if I used the IDEA 6.x
version. It could be some bug in the Selena EAP. Two main
problems occurred: In many files the "import com.xyz.Group"
declaration was removed when it was actually necessary still,
and there were far too many usages of the new subclass "
ExplicitGroup" rather than the superclass "Group". (Remember I
choose "Rename original class and use superclass where possible."
)

I thought about removing all the changes, and then trying again
with IDEA 6.0.x production version, but I figured I could manually
fix the errors quicker by hand. So, unfortunately, I can't say
if the bugs were due to EAP or not.

Problem#5
-


Import Popup only appears after Syntax and Inspection parse
-


[/B]
In order to fix the missing import, I had to goto each class.
The class "Group" is not an unambiguous import, so I have to
confirm it when the Import Popup appears. The problem I ran
into is the Auto-Import popup doesn't popup until Mr. Inspector
is done with both Syntax and Inspection parsing. So, as I
jumped to each file that had a compile error due to the missing
import line, I had to wait for Mr. Inspector to finish before I
was prompted to pick the " com.xyz.Group" import. After doing
about 10 of these, I said @# $% it, and I changed my IDE profile
to "None" temporarily, so I could finish my work. I don't know
why the Import Popup has to wait for Mr. Inspector to finish.
Once the java syntax is parse, shouldn't the Import Popup be
able to display? It shouldn't care about the Inspections
parsing.

1 comment

+10 Lots of very good points here, and stuff that's bothered me for a
long time... particularly the note about not having a refactoring
summary available, which would be priceless for major refactoring.

Thanks Alex for bringing all these points up.
N.

Alex wrote:

I just got done doing an "Extract Superclass" refactoring on a
class "Group". The original class was 700 lines of code, which
isn't that big, but the class but the class had about 3000
usages. This is actually the first time I have used "Extract Superclass"
for a very large class. I ran into a number of problems, but most of
them weren't even related to the Extract Superclass.

When you start "Extract Superclass" refactoring, the process
begins fine. A dialog prompts you to tag which methods and
fields you want in the new superclass. (It would be nice if
there was a checkall choice because I wanted to move almost all
methods to the superclass). Also I checked the option "Rename
original class and use superclass where possible." So, in the
end, most of the code should still be using the "Group" class
and only the places using the methods and fields I didn't pull
up to the superclass would use the new subclass "ExplicitGroup".

I then clicked Preview. IDEA then starts finding all the usages
of the fields and methods of the class. Here is where I started
having problems.

Problem #1.
-----------
Find Usages on class is slow, and appears to do unnecessary work
in some cases. (See below)
-----------[/B]
The Find Usages took a long time; About 20 min on an Intel Dual
Core machine. There is a Jira item IDEADEV-12010 "Use compiler
caches to speed up Find Usages" which would potentially be a
huge improvement. But I noticed several places where Find
Usages seemed to be doing unnecessary work:

1.A[/B] This class has a bunch of overloaded static methods like
load() and create() which take different parameters. I must
have seen "Searching for load..." 10 times and each time took
awhile. Seems like it should have searched for all overloaded
usages at one time.

1.B[/B] My project contains server code plus a web module. So, when
I searching for a method getName(), I see "Searching for getName..
" and "Searching for name...". I assume the "Searching for name..
" is searching for it in the Web module, assuming that my class "
Group" is an enterprise java bean? Is there anyway to turn that
behavior off? Does it adhere to dependencies? In my project, the
Web Module depends on the Server module, so that wouldn't help,
but I know that 99% of my server code is not used as enterprise
java beans.

1.C[/B] IDEA says "Searching for getName...", "Searching for name..", "Searching for
setName...", "Searching for name..". It seems like it is searching for "name" twice.

Problem #2.
-----------
Find Usages doesn't show overall progress. Progress bar keeps
resetting after each "Searcing for xyz..."
-----------[/B]
The Find Usages progress window provides no overall measure of
progress. IDEA show the progress for "Searching for load..." and
then when it starts on "Searching for getName..." it starts the
progress over again! This is really poor. If you are doing
Find Usages on a class, IDEA should be showing you the overall
progress on all the methods and fields to be searched for. If
my class has 100 methods and 20 fields, the progress should
shows what % of the 120 searches have been completed.


Problem #3
-----------
Refactoring Preview doesn't tell you what change will be done
on each usage.
-----------[/B]
The refactoring preview just looked like the output from Find
Usages. It doesn't tell me what exactly will be changed for that
usage. This was really confusing in this case because I had
checked "Rename original class and use superclass where possible"
, and I had moved most of the fields and methods to the
superclass, so I was expected most of the usages to require no
change. As it is, I wouldn't even call this "Preview" . What I
would like to see is IDEA give me the option to show me the
before and after for each change.

I realize that for some refactorings, it is obvious what change
will be made, but in this case, on some of them it wasn't clear to
me.

Problem #4
----------
Hard to review changes after refactoring done.
----------[/B]
After pressing "Do Refactor", the "Preview" is closed, so I can't
refer back to that, although even if it was there, there is this
issue with lines getting marked INVALID, which means you can no
longer click on them to jump to the file: linenumber. There is
no summary of the changes made. (Related Jira IDEADEV- 13612
"Refactoring result preview")

After I did the refactoring, my code was broken. Something went
wrong with the refactoring. Now, I don't know if this was due to
a real bug that would have happened if I used the IDEA 6.x
version. It could be some bug in the Selena EAP. Two main
problems occurred: In many files the "import com.xyz.Group"
declaration was removed when it was actually necessary still,
and there were far too many usages of the new subclass "
ExplicitGroup" rather than the superclass "Group". (Remember I
choose "Rename original class and use superclass where possible."
)

I thought about removing all the changes, and then trying again
with IDEA 6.0.x production version, but I figured I could manually
fix the errors quicker by hand. So, unfortunately, I can't say
if the bugs were due to EAP or not.

Problem#5
----------
Import Popup only appears after Syntax and Inspection parse
----------[/B]
In order to fix the missing import, I had to goto each class.
The class "Group" is not an unambiguous import, so I have to
confirm it when the Import Popup appears. The problem I ran
into is the Auto-Import popup doesn't popup until Mr. Inspector
is done with both Syntax and Inspection parsing. So, as I
jumped to each file that had a compile error due to the missing
import line, I had to wait for Mr. Inspector to finish before I
was prompted to pick the " com.xyz.Group" import. After doing
about 10 of these, I said @# $% it, and I changed my IDE profile
to "None" temporarily, so I could finish my work. I don't know
why the Import Popup has to wait for Mr. Inspector to finish.
Once the java syntax is parse, shouldn't the Import Popup be
able to display? It shouldn't care about the Inspections
parsing.

0

Please sign in to leave a comment.