mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: suggested names for folded params should be unique (IDEA-120974)
This commit is contained in:
+12
-5
@@ -140,7 +140,7 @@ public class ParametersFolder {
|
||||
if (nameInfo.names.length > 0) {
|
||||
data.name = nameInfo.names[0];
|
||||
}
|
||||
setUniqueName(data);
|
||||
setUniqueName(data, scope, mostRanked);
|
||||
}
|
||||
|
||||
return mostRanked != null;
|
||||
@@ -165,12 +165,19 @@ public class ParametersFolder {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setUniqueName(VariableData data) {
|
||||
private void setUniqueName(VariableData data, LocalSearchScope scope, PsiExpression expr) {
|
||||
String name = data.name;
|
||||
int idx = 1;
|
||||
while (myUsedNames.contains(data.name)) {
|
||||
data.name += idx;
|
||||
while (true) {
|
||||
if (myUsedNames.add(name)) {
|
||||
final PsiVariable definedVariable = PsiResolveHelper.SERVICE.getInstance(expr.getProject()).resolveReferencedVariable(name, expr);
|
||||
if (definedVariable == null || !scope.containsRange(expr.getContainingFile(), definedVariable.getTextRange())) {
|
||||
data.name = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
name = data.name + idx++;
|
||||
}
|
||||
myUsedNames.add(data.name);
|
||||
}
|
||||
|
||||
private static Set<PsiVariable> findUsedVariables(VariableData data, final List<? extends PsiVariable> inputVariables,
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class Test {
|
||||
String get(String[] args) {
|
||||
<selection>String arg = args[0];
|
||||
return arg;</selection>
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
String get(String[] args) {
|
||||
return newMethod(args[0]);
|
||||
}
|
||||
|
||||
private String newMethod(String arg1) {
|
||||
String arg = arg1;
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
@@ -523,6 +523,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFoldedParamNameSuggestion() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNonFoldInIfBody() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user