Bug 44803

Summary: [introduce parameter] does not replace all occurrences of expression [refactoring]
Product: [Eclipse Project] JDT Reporter: Tobias Widmer <tobias_widmer>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P4 CC: akiezun, daniel_megert, david, deepakazad, eclipse, martinae, nikolaymetchev, private
Version: 3.0   
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard: fix candidate

Description Tobias Widmer CLA 2003-10-14 05:42:14 EDT
Build 200310101454:

When using the "Introduce parameters" refactoring on the expression 

"JAVADOC_PARAM_TAGS"

and giving the new parameter the name "tags", the result looks as follows:


	protected final boolean isParameterTag(String[] tags) {

		if (fToken != null) {

			for (int index= 0; index < tags.length; index++) {

				if (fToken.equals(JAVADOC_PARAM_TAGS[index])) {

					fToken= null;
					return true;
				}
			}
		}
		return false;
	}

The second occurrence of "JAVADOC_PARAM_TAGS" was obviously not replaced by 
the new parameter.
Comment 1 Markus Keller CLA 2004-05-27 03:54:10 EDT
Introduce Parameter currently doesn't offer an option to replace all occurrences.
Comment 2 Adam Kiezun CLA 2004-06-18 10:22:07 EDT
+1 here
introduce param that replaced all occurences would be a powerful tool for making
methods more reusable. 
i could even imagine a refactoring that would introduce params until a method
could be turned into a static methods and moved to a reusable util class.
Comment 3 Adam Kiezun CLA 2004-06-18 10:27:45 EDT
ha! 
this is a compination of extract temp + introduce param + inline temp
observe:

class A{
 int fField;
  int doubleIt(){
    return fField + fField;
  }
  void caller(){
     int x= doubleIt();
  }
}

now do extract temp:
class A{
 int fField;
  int doubleIt(){
    int i= fField; 
    return i + i;
  }
  void caller(){
     int x= doubleIt();
  }
}

intro param

class A{
 int fField;
  int doubleIt(int p){
    int i= p; 
    return i + i;
  }
  void caller(){
     int x= doubleIt(fField);
  }
}

inline temp
class A{
 int fField;
  int doubleIt(int p){
    return p + p;
  }
  void caller(){
     int x= doubleIt(fField);
  }
}

now you have a reusable doubling method
kinda slow but works. 
Comment 4 Markus Keller CLA 2004-06-22 05:47:15 EDT
*** Bug 68147 has been marked as a duplicate of this bug. ***
Comment 5 Markus Keller CLA 2004-09-10 09:15:03 EDT
*** Bug 73659 has been marked as a duplicate of this bug. ***
Comment 6 Markus Keller CLA 2005-11-28 06:34:08 EST
*** Bug 118134 has been marked as a duplicate of this bug. ***
Comment 7 David Saff CLA 2005-11-29 14:38:57 EST
See also bug 102125, which handles this problem more generally
Comment 8 Martin Aeschlimann CLA 2007-06-25 04:34:40 EDT
*** Bug 194139 has been marked as a duplicate of this bug. ***