IDEA-67376 Groovy: Renaming does not rename usages of private java field/methods in groovy files

This commit is contained in:
Maxim Medvedev
2011-04-03 11:07:10 +04:00
parent da98caef35
commit 79f57ee993
3 changed files with 58 additions and 0 deletions
+2
View File
@@ -214,6 +214,8 @@
<debuggerClassFilterProvider implementation="org.jetbrains.plugins.groovy.debugger.filters.GroovyDebuggerClassFilterProvider"/>
<stackFrameFilter implementation="org.jetbrains.plugins.groovy.debugger.filters.GroovyDebuggerClassFilterProvider"/>
<useScopeEnlarger implementation="org.jetbrains.plugins.groovy.lang.psi.impl.search.GrPrivateFieldScopeEnlarger"/>
<debuggerEditorTextProvider language="Groovy" implementationClass="org.jetbrains.plugins.groovy.debugger.GroovyEditorTextProvider"/>
<xdebugger.settings implementation="org.jetbrains.plugins.groovy.debugger.filters.GroovyDebuggerSettings"/>
@@ -0,0 +1,41 @@
/*
* Copyright 2000-2011 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.lang.psi.impl.search;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.impl.PsiManagerEx;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.UseScopeEnlarger;
import org.jetbrains.annotations.NotNull;
/**
* @author Maxim.Medvedev
*/
public class GrPrivateFieldScopeEnlarger extends UseScopeEnlarger {
@Override
public SearchScope getAdditionalUseScope(@NotNull PsiElement element) {
if (element instanceof PsiField && ((PsiField)element).hasModifierProperty(PsiModifier.PRIVATE)) {
final PsiManagerEx psiManager = (PsiManagerEx)element.getManager();
final GlobalSearchScope maximalUseScope = psiManager.getFileManager().getUseScope(element);
return new GrSourceFilterScope(maximalUseScope);
}
return null;
}
}
@@ -425,6 +425,21 @@ class Foo {
assertTrue false
}
public void testRenameJavaPrivateField() {
myFixture.addFileToProject "Foo.java", """
public class Foo {
private int field;
}"""
myFixture.configureByText "Bar.groovy", """
print new Foo(field: 2)
"""
myFixture.renameElement myFixture.findClass("Foo").fields[0], "anotherOneName"
myFixture.checkResult """
print new Foo(anotherOneName: 2)
"""
}
private def doInplaceRenameTest() {
String prefix = TestUtils.getTestDataPath() + "groovy/refactoring/rename/" + getTestName(false)
myFixture.configureByFile prefix + ".groovy";