Bug 108103 - [move method] use existing field in target instead of creating a new parameter [refactoring]
Summary: [move method] use existing field in target instead of creating a new paramete...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-26 08:16 EDT by Markus Keller CLA
Modified: 2007-06-14 10:45 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2005-08-26 08:16:40 EDT
I20050823-0800

When moving A#sub() to fB in the example below, it would be nice if I could use
the field B#fA instead of creating an new parameter.

class A {
    B fB;
    void sub() {
        subsub();
    }
    void subsub() {}
}

class B {
    A fA;
    void worker() {
        fA.sub();
    }
}

After the move, the class B should look linke this:
    void worker() {
        sub();
    }
    void sub() {
        fA.subsub();
    }

This is an often encountered problem when splitting a class manually in two
parts by moving methods one at a time.
Comment 1 Tobias Widmer CLA 2005-08-26 09:54:45 EDT
This is a valid request. However, it may be not enough. Consider moving foo() 
to fB:

class A {
 B fB;
 X fX;
 Y fY;
 Z fZ;
 void foo() {
   fX.x(); fY.y(); fZ.z();
 }
}

class B {
 A fA;
 X fX;
 Y fY;
 Z fZ;
}

This is the reason that we did not implement it to use a user-defined mapping, 
but instead create new parameters. Basically, we would have to use type 
constraints to determine whether we have to introduce a new parameter or could 
use the (user-specified) field.
Comment 2 Markus Keller CLA 2005-08-26 12:09:45 EDT
Where's the problem? After the move, B#foo() would look like this:
	void foo() {
		fA.fX.x();
		fA.fY.y();
		fA.fZ.z();
	}

The fA in fA.sub() in worker() can of course only be dropped since fA is the
chosen "origin" field. But even if worker() was left as fA.fB.sub();, the
omission of the new parameter would be helpful.
Comment 3 Tobias Widmer CLA 2005-08-26 12:29:56 EDT
The problem is that using fA instead of a new parameter only partially solves 
the problem (see example above). Additionally, there are malicious cases 
like "fA= something" which would result in "this= something".

I'll have a look into it.