mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: do not suggest object when multiple returns are used without output variable
This commit is contained in:
+15
-5
@@ -68,10 +68,8 @@ import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
import com.intellij.refactoring.util.*;
|
||||
import com.intellij.refactoring.util.classMembers.ElementNeedsThis;
|
||||
import com.intellij.refactoring.util.duplicates.*;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -566,7 +564,19 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
: PsiTreeUtil.findCommonParent(myElements);
|
||||
return CodeInsightUtil.findReferenceExpressions(scope, myOutputVariable);
|
||||
}
|
||||
return PsiExpression.EMPTY_ARRAY;
|
||||
final List<PsiStatement> filter = ContainerUtil.filter(myExitStatements, new Condition<PsiStatement>() {
|
||||
@Override
|
||||
public boolean value(PsiStatement statement) {
|
||||
return statement instanceof PsiReturnStatement;
|
||||
}
|
||||
});
|
||||
final List<PsiExpression> map = ContainerUtil.map(filter, new Function<PsiStatement, PsiExpression>() {
|
||||
@Override
|
||||
public PsiExpression fun(PsiStatement statement) {
|
||||
return ((PsiReturnStatement) statement).getReturnValue();
|
||||
}
|
||||
});
|
||||
return map.toArray(new PsiExpression[map.size()]);
|
||||
}
|
||||
|
||||
private Nullness initNullness() {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class Test {
|
||||
String foo(boolean b) {
|
||||
<selection>
|
||||
if (b) {
|
||||
return "a";
|
||||
}
|
||||
if (!b) {
|
||||
return "b";
|
||||
}
|
||||
</selection>
|
||||
return "42";
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,10 @@ public class SuggestedReturnTypesTest extends LightCodeInsightTestCase {
|
||||
doTest("Integer", "int");
|
||||
}
|
||||
|
||||
public void testOutputUsedInReturn() throws Exception {
|
||||
doTest("String");
|
||||
}
|
||||
|
||||
private void doTest(String... types) throws Exception {
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".java");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user