Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 365010

Summary: [change method signature][refactoring] The Change Method Signature refactoring doesn't always get logged correctly.
Product: [Eclipse Project] JDT Reporter: Mohsen Vakilian <reprogrammer>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: deepakazad, nchen, reprogrammer, snegara2
Version: 3.7.1   
Target Milestone: ---   
Hardware: All   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=365233
Whiteboard: stalebug

Description Mohsen Vakilian CLA 2011-11-28 16:59:34 EST
Build Identifier: M20110909-1335

We developed a custom refactoring data collector for Eclipse called CodingSpectator <http://codingspectator.cs.illinois.edu/>. Eclipse records every performed refactoring in ".metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.../refactorings.history". CodingSpectator augments the refactorings in "refactorings.history" with more data. However, we noticed that the Change Method Signature may get recorded incorrectly. For example, the log of a Change Method Signature refactoring does not show the change in the order of method parameters or the names of method parameters.

Reproducible: Always

Steps to Reproduce:
1. Consider the following source code.

----
//C.java
public class C {

	int m(int a, int b) {
		return a / b;
	}

	public static void main(String[] args) {
		System.out.println(new C().m(4, 2));
	}

}
----

2. If you use the Change Method Signature to reorder the parameters of C.m from "int a, int b" to "int b, int a", Eclipse will record the refactoring as the following in ".metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.../refactorings.history".

----
<refactoring comment="Change method 'int C.m(int b, int a)' to 'int m(int b, int a)'
- Original project: 'P'
- Original element: 'C.m(...)'" delegate="false" deprecate="true" description="Change method 'm'" flags="589830" id="org.eclipse.jdt.ui.change.method.signature" input="/src<{C.java[C~m~I~I" name="m" parameter1="int b 1 int b false" parameter2="int a 0 int a false" stamp="1322513797840" version="1.0"/>
----

The problem is that the recorder refactoring descriptor doesn't indicate the change made to the method signature.

3. Similarly, if you use the Change Method Signature refactoring to rename the second parameter of the method C.m from "b" to "c", Eclipse will record the refactoring as the following in ".metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.../refactorings.history".

----
<refactoring comment="Change method 'int C.m(int a, int c)' to 'int m(int a, int c)'
- Original project: 'P'
- Original element: 'C.m(...)'
- Changed parameters:
     int b" delegate="false" deprecate="true" description="Change method 'm'" flags="589830" id="org.eclipse.jdt.ui.change.method.signature" input="/src<{C.java[C~m~I~I" name="m" parameter1="int a 0 int a false" parameter2="int b 1 int c false" stamp="1322514484229" version="1.0"/>
----

Again, the problem is that the "comment" attribute in the above refactoring descriptor doesn't show the rename from "b" to "c". However, one might be able to infer the rename from the values of the two attributes "parameter1" and "parameter2".
Comment 1 Deepak Azad CLA 2011-11-29 04:10:17 EST
(In reply to comment #0)
> 2. If you use the Change Method Signature to reorder the parameters of C.m from
> "int a, int b" to "int b, int a", Eclipse will record the refactoring as the
> following in
>
> <refactoring comment="Change method 'int C.m(int b, int a)' to 'int m(int b,
> int a)'
> 
> 3. Similarly, if you use the Change Method Signature refactoring to rename the
> second parameter of the method C.m from "b" to "c", 
>
> <refactoring comment="Change method 'int C.m(int a, int c)' to 'int m(int a,
> int c)'

The refactoring comments are wrong in both cases, and this is what a user would see in the refactoring history dialog. (The actual refactoring is recorded correctly and you can successfully create and apply a refactoring script)
Comment 2 Deepak Azad CLA 2011-11-29 04:17:49 EST
Fix to go somewhere in 
org.eclipse.jdt.internal.corext.refactoring.structure.ChangeSignatureProcessor.getOldMethodSignature()

This should also fix similar problems in other refactorings, see call hierarchy of above mentioned method.
Comment 3 Mohsen Vakilian CLA 2011-11-29 07:59:59 EST
(In reply to comment #1)
> (In reply to comment #0)
> > 2. If you use the Change Method Signature to reorder the parameters of C.m from
> > "int a, int b" to "int b, int a", Eclipse will record the refactoring as the
> > following in
> >
> > <refactoring comment="Change method 'int C.m(int b, int a)' to 'int m(int b,
> > int a)'
> > 
> > 3. Similarly, if you use the Change Method Signature refactoring to rename the
> > second parameter of the method C.m from "b" to "c", 
> >
> > <refactoring comment="Change method 'int C.m(int a, int c)' to 'int m(int a,
> > int c)'
> 
> The refactoring comments are wrong in both cases, and this is what a user would
> see in the refactoring history dialog. (The actual refactoring is recorded
> correctly and you can successfully create and apply a refactoring script)

Yes, the captured refactoring descriptors can be used to replay the refactorings, but, the comment attributes are misleading to the user.
Comment 4 Eclipse Genie CLA 2019-11-02 19:17:50 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.