mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: exclude return statements without value from occurrence analyzing; do not suggest artificial return type if return statements break control flow
This commit is contained in:
+2
-2
@@ -344,7 +344,7 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
|
||||
@Nullable
|
||||
private PsiVariable getArtificialOutputVariable() {
|
||||
if (myOutputVariables.length == 0) {
|
||||
if (myOutputVariables.length == 0 && myExitStatements.isEmpty()) {
|
||||
if (myCanBeChainedConstructor) {
|
||||
final Set<PsiField> fields = new HashSet<PsiField>();
|
||||
for (PsiElement element : myElements) {
|
||||
@@ -616,7 +616,7 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
final List<PsiStatement> filter = ContainerUtil.filter(myExitStatements, new Condition<PsiStatement>() {
|
||||
@Override
|
||||
public boolean value(PsiStatement statement) {
|
||||
return statement instanceof PsiReturnStatement;
|
||||
return statement instanceof PsiReturnStatement && ((PsiReturnStatement)statement).getReturnValue() != null;
|
||||
}
|
||||
});
|
||||
final List<PsiExpression> map = ContainerUtil.map(filter, new Function<PsiStatement, PsiExpression>() {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class X {
|
||||
void foo() {
|
||||
<selection>if (true) return;
|
||||
System.out.println();
|
||||
</selection>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class X {
|
||||
void foo() {
|
||||
newMethod();
|
||||
|
||||
}
|
||||
|
||||
private int newMethod() {
|
||||
if (true) return;
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -666,6 +666,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doTestReturnTypeChanged(PsiType.INT);
|
||||
}
|
||||
|
||||
public void testNoReturnTypesSuggested() throws Exception {
|
||||
doTestReturnTypeChanged(PsiType.INT);
|
||||
}
|
||||
|
||||
public void testMultipleVarsInMethodNoReturnStatementAndAssignment() throws Exception {
|
||||
//return type should not be suggested but still
|
||||
doTestReturnTypeChanged(PsiType.INT);
|
||||
|
||||
Reference in New Issue
Block a user