Menu

#107 ExtractMethod produces wrong code on anonymous inner classes

open
9
2003-11-25
2003-02-20
No

The extract method refactoring fails when applied on
methods of anonymous inner classes having
syntactically equal regions:

BEFORE: (> indicates extract method region)

public class Test {
public void f() {
A a1 = new A() {
public void g() {
> callSomethingMember1();
> callSomethingMember2();
}
};
A a2 = new A() {
public void g() {
callSomethingMember1();
callSomethingMember2();
}
};
}
}

AFTER: (/* comments stripped */)

public class Test {
public void f() {
A a1 =
new A() {
public void g() {
extractedMethod();
}
private void extractedMethod() {
callSomethingMember1();
callSomethingMember2();
}
};
A a2 =
new A() {
public void g() {
extractedMethod();
}
};
}
}

BUG: The second classe misses the extractMethod()
definition

Discussion

  • Mike Atkinson

    Mike Atkinson - 2003-07-20
    • assigned_to: seguin --> mikeatkinson
     
  • Mike Atkinson

    Mike Atkinson - 2003-11-25

    Logged In: YES
    user_id=476481

    I am actively looking at this problem now. Upped priority.

     
  • Mike Atkinson

    Mike Atkinson - 2003-11-25
    • priority: 5 --> 9
     

Log in to post a comment.

Auth0 Logo