Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.5.2.Release
-
Fix Version/s: 2.6.1.M1
-
Component/s: Parser, Refactoring, Search
-
Labels:None
-
Environment:HideWindows 7
Eclipse vIndigo Service Release 1, Build id: 20110916-0149
SpringSource Tool Suite Version: 2.8.0.SNAPSHOT Build Id: 201110310726
SpringIDE Version: 2.8.0.201110302204-CI-B1319
Groovy-Eclipse plugin Version: 2.6.0.xx-20111028-1400-e37ShowWindows 7 Eclipse vIndigo Service Release 1, Build id: 20110916-0149 SpringSource Tool Suite Version: 2.8.0.SNAPSHOT Build Id: 201110310726 SpringIDE Version: 2.8.0.201110302204-CI-B1319 Groovy-Eclipse plugin Version: 2.6.0.xx-20111028-1400-e37
-
Number of attachments :
Description
When attempting to rename a method with a parameter that has a default value, the rename does not work correctly. Here is the before and after code:
Before
class Summer {
def sumWithDefaults(a, b, d=0){
return a + b + d
}
}
def summer = new Summer()
assert 2 == summer.sumWithDefaults(1,1)
assert 3 == summer.sumWithDefaults(1,1,1)
After
refactoredSumlass Summer {
def sumWithDefaults(a, b, d=0){
return a + b + d
}
}
def summer = new Summer()
assert 2 == summer.refactoredSum(1,1)
assert 3 == summer.sumWithDefaults(1,1,1)
This is the expected result:
Expected
class Summer {
def refactoredSum(a, b, d=0){
return a + b + d
}
}
def summer = new Summer()
assert 2 == summer.refactoredSum(1,1)
assert 3 == summer.refactoredSum(1,1,1)
These are the specific problems observed:
- The new method name replaces the first character in the file
- The new method name does not actually replace the old method name in the method declaration
- Not all method calls with the old name and a matching signature are refactored
- Only method calls who's call signature matches the parameters with no default value are updated
Issue Links
- is related to
-
GRECLIPSE-1256
Use a classfile attribute in the classfile to help determine the original method declaration of a method that uses default parameters
-
This problem happens because of the way that we represent methods with default values internally. Each variant of the method is represented as a new method, but with a source location of [0,1]. It looks like the rename is attempting to change the name of the declaration of the default method, but since it doesn't exist, it winds up replacing the first char of the file with the new name.