mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
inline: tweak search scope for conflicts replacement
This commit is contained in:
@@ -33,6 +33,7 @@ import com.intellij.psi.controlFlow.*;
|
||||
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -592,7 +593,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
if (!name.equals(parmName)) {
|
||||
name = myJavaCodeStyle.suggestUniqueVariableName(name, block.getFirstChild(), true);
|
||||
}
|
||||
RefactoringUtil.renameVariableReferences(parm, name, GlobalSearchScope.projectScope(myProject));
|
||||
RefactoringUtil.renameVariableReferences(parm, name, new LocalSearchScope(myMethodCopy.getBody()), true);
|
||||
PsiType paramType = parm.getType();
|
||||
@NonNls String defaultValue;
|
||||
if (paramType instanceof PsiEllipsisType) {
|
||||
@@ -687,7 +688,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
name = newName;
|
||||
}
|
||||
if (!name.equals(oldName)) {
|
||||
RefactoringUtil.renameVariableReferences(var, name, GlobalSearchScope.projectScope(myProject));
|
||||
RefactoringUtil.renameVariableReferences(var, name, new LocalSearchScope(myMethodCopy.getBody()), true);
|
||||
var.getNameIdentifier().replace(myFactory.createIdentifier(name));
|
||||
}
|
||||
}
|
||||
@@ -1313,4 +1314,4 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
return myReference == null ? Collections.singletonList(myMethod) : Arrays.asList(myReference, myMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,7 +402,14 @@ public class RefactoringUtil {
|
||||
}
|
||||
|
||||
public static void renameVariableReferences(PsiVariable variable, String newName, SearchScope scope) throws IncorrectOperationException {
|
||||
for (PsiReference reference : ReferencesSearch.search(variable, scope)) {
|
||||
renameVariableReferences(variable, newName, scope, false);
|
||||
}
|
||||
|
||||
public static void renameVariableReferences(PsiVariable variable,
|
||||
String newName,
|
||||
SearchScope scope,
|
||||
final boolean ignoreAccessScope) throws IncorrectOperationException {
|
||||
for (PsiReference reference : ReferencesSearch.search(variable, scope, ignoreAccessScope)) {
|
||||
reference.handleElementRename(newName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
public class ABl {
|
||||
void foo(int fe) {
|
||||
System.out.println(fe);
|
||||
}
|
||||
|
||||
void bar(boolean br) {
|
||||
int fe = 0;
|
||||
if (br) {
|
||||
foo(fe);
|
||||
} else {
|
||||
f<caret>oo(11);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
public class ABl {
|
||||
|
||||
void bar(boolean br) {
|
||||
int fe = 0;
|
||||
if (br) {
|
||||
System.out.println(fe);
|
||||
} else {
|
||||
System.out.println(11);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,6 +157,10 @@ public class InlineMethodTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testParamNameConflictsWithLocalVar() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return JavaSdkImpl.getMockJdk17("java 1.5");
|
||||
|
||||
Reference in New Issue
Block a user