The Artima Developer Community
Sponsored Link

Weblogs Forum
Refactoring 2.0

24 replies on 2 pages. Most recent reply: Mar 28, 2007 8:24 PM by Michael Feathers

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 24 replies on 2 pages [ « | 1 2 ]
Jeff Langr

Posts: 6
Nickname: jlangr
Registered: Oct, 2003

Re: Refactoring 2.0 Posted: Mar 16, 2007 11:31 AM
Reply to this message Reply
Advertisement
split test class--similar to extract class, but retains appropriate setup/teardown behavior based off of which instvars are extracted

Marc Stock

Posts: 17
Nickname: salient1
Registered: Mar, 2007

Re: Refactoring 2.0 Posted: Mar 16, 2007 3:15 PM
Reply to this message Reply
Pretty much all of what you're asking for (including intelligent line moving), Michael, is already available in IntelliJ via built in refactoring or via a purchasable IntelliJ plugin called Refactor-J from Sixth and Red River (they also make a nice thread refactoring plugin called Locksmith).

Eric-Alexander Schaefer

Posts: 2
Nickname: eas
Registered: Sep, 2005

Re: Refactoring 2.0 Posted: Mar 20, 2007 9:54 AM
Reply to this message Reply
Martin, Michael,

for a similar minimal interface refactoring check out intoJ:
http://www.intoj.org/


public class IntoJTest {
private Class1 x;

public void xyz() {
x = new Class1();
float q = x.b(42);
}
}

public class Class1 {
public int a() {
return 1;
}

public float b(int c) {
return (float)c;
}
}


Applying "Infer Type" to IntoJTest.x creates:


public class IntoJTest {
private Class1_x_1IT x;

public void xyz() {
x = new Class1();
float q = x.b(42);
}
}

public class Class1 implements Class1_x_1IT {
public int a() {
return 1;
}

public float b(int c) {
return (float)c;
}
}

public interface Class1_x_1IT {

float b(int arg0);

}


HTH,
Eric

Fermin Ordaz

Posts: 2
Nickname: fordaz
Registered: Jun, 2005

Re: Refactoring 2.0 Posted: Mar 20, 2007 9:36 PM
Reply to this message Reply
Once you decide to remove the static modifier in one method, it would come in handy to have a re-factoring option that converts all the existing calls using the class name, to use a given automatically created instance in a common scope of each piece of code. Of course some additional considerations may apply, like is any default constructor available ?, etc.

Egor Malyshev

Posts: 2
Nickname: rayshade
Registered: Mar, 2007

Re: Refactoring 2.0 Posted: Mar 21, 2007 7:31 AM
Reply to this message Reply
Hi guys, like Marc mentioned above, IntelliJ IDEA covers a lot of these refactorings (it has over 50 refactorings that can be performed automatically). Of course, it's fully interactive as well, letting you preview the changes and roll them back as required, or apply only certain changes you select.

If you're into JavaScript, XML, HTML and other code (Ruby and Ruby on Rails refactorings are coming soon), IDEA has refactorings for all of them.

For more info, check out:
Refactoring features page: http://www.jetbrains.com/idea/features/refactoring.html
Live demos showing how to refactor code: http://www.jetbrains.com/idea/training/refactoring.html
Other useful IntelliJ IDEA features: http://www.jetbrains.com/idea/features/index.html

Michael Feathers

Posts: 448
Nickname: mfeathers
Registered: Jul, 2003

Re: Refactoring 2.0 Posted: Mar 21, 2007 7:48 AM
Reply to this message Reply
I didn't see intelligent statement move there, though. Idea really has that one?

Egor Malyshev

Posts: 2
Nickname: rayshade
Registered: Mar, 2007

Re: Refactoring 2.0 Posted: Mar 22, 2007 7:20 AM
Reply to this message Reply
There are Move refactorings that let you move Classes, Instance Methods and other entities, but the functionality you described is not available as of yet.
May I ask you to give some examples when this refactoring is helpful?

Dave Griffith

Posts: 1
Nickname: dgriffith
Registered: Mar, 2007

Re: Refactoring 2.0 Posted: Mar 26, 2007 6:21 AM
Reply to this message Reply
"Extract Class" and "Introduce Parameter Object" are available in the Refactor-J plugin for IntelliJ IDEA, along with about twenty other odds and sods. It's commercial, but fairly cheap, from a company called Sixth and Red River Software (http://www.sixthandredriver.com). They've got some interesting stuff, including a package of XML "refactorings" and a new set of Java concurrency refactorings. Check 'em out.

Marcos Pereira

Posts: 1
Nickname: jackganzha
Registered: Mar, 2007

Re: Refactoring 2.0 Posted: Mar 26, 2007 10:23 AM
Reply to this message Reply
I know that already exist "extract anonymous class to inner class". But, what about "extract inner class to external class"?

Kind Regards

Michael Feathers

Posts: 448
Nickname: mfeathers
Registered: Jul, 2003

Re: Refactoring 2.0 Posted: Mar 28, 2007 8:24 PM
Reply to this message Reply
> There are Move refactorings that let you move Classes,
> Instance Methods and other entities, but the functionality
> you described is not available as of yet.
> May I ask you to give some examples when this refactoring
> is helpful?

I don't have a real example handy, but here's a made up one:

public int show() {
    int total = 0;
    int fliggle = 0;
    int foogle = getFloogle();
    display.show(getBloop() + getFliggle());
    total += getBloop().getCount() + floogle;
    fliggle = getFliggle();
    ...
    display.show(getBlap() + fliggle + floogle);
    total += getBlap().getCount();
    ...
    display.show(getBlurp());
    total += blurp.getCount();
    return total;
}


Here we have a method which obviously does two things: totaling and display. If we can shift all of the show lines downward and we can extract the logic for totaling and put it someplace else. It's easy enough to do manually, but it would be great if a tool could give us assurance that there are no side effects; that semantics are preserved.

Flat View: This topic has 24 replies on 2 pages [ « | 1  2 ]
Topic: Refactoring 2.0 Previous Topic   Next Topic Topic: Deterministic Software Development

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use