EA-41762 rename method overridden by groovy method with optional params

This commit is contained in:
Max Medvedev
2012-12-13 19:20:52 +04:00
parent 653c9ed0c0
commit 4b13c2f1af
2 changed files with 57 additions and 1 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -263,6 +263,15 @@ public class RenameJavaMethodProcessor extends RenameJavaMemberProcessor {
final PsiMethod method = (PsiMethod) element;
OverridingMethodsSearch.search(method, scope, true).forEach(new Processor<PsiMethod>() {
public boolean process(PsiMethod overrider) {
if (overrider instanceof PsiMirrorElement) {
final PsiElement prototype = ((PsiMirrorElement)overrider).getPrototype();
if (prototype instanceof PsiMethod) {
overrider = (PsiMethod)prototype;
}
}
if (overrider instanceof SyntheticElement) return true;
final String overriderName = overrider.getName();
final String baseName = method.getName();
final String newOverriderName = RefactoringUtil.suggestNewOverriderName(overriderName, baseName, newName);
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.refactoring.rename
import com.intellij.openapi.util.text.StringUtil
@@ -639,6 +654,38 @@ class Inheritor extends Bassse {
super()
}
}
''')
}
}
void testOverridenMethodWithOptionalParams() {
myFixture.with {
configureByText(GroovyFileType.GROOVY_FILE_TYPE, '''\
class Base {
void fo<caret>o(){}
}
class Inheritor extends Base {
void foo(int x = 5) {}
}
new Base().foo()
new Inheritor().foo()
new Inheritor().foo(2)
''')
renameElementAtCaret('bar')
checkResult('''\
class Base {
void ba<caret>r(){}
}
class Inheritor extends Base {
void bar(int x = 5) {}
}
new Base().bar()
new Inheritor().bar()
new Inheritor().bar(2)
''')
}
}