mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce variable: ensure extracted variable from multiple occurrences put inside lambda body (IDEA-146250)
This commit is contained in:
@@ -56,7 +56,6 @@ import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.siyeh.ipp.types.ExpandOneLineLambda2CodeBlockIntention;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -263,6 +262,7 @@ public class RefactoringUtil {
|
||||
if (parent == null) parent = place;
|
||||
while (true) {
|
||||
if (isExpressionAnchorElement(parent)) return parent;
|
||||
if (parent instanceof PsiExpression && parent.getParent() instanceof PsiLambdaExpression) return parent;
|
||||
parent = parent.getParent();
|
||||
if (parent == null) return null;
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
class X {
|
||||
public void foo(Class<?> cls)
|
||||
{
|
||||
Stream.of(cls.getMethods())
|
||||
.filter(method -> {
|
||||
Class<?> c = method.getReturnType();
|
||||
return Collection.class.isAssignableFrom(c) || Map.class.isAssignableFrom(c);
|
||||
})
|
||||
.collect(Collectors.<Method>toList());
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
class X {
|
||||
public void foo(Class<?> cls)
|
||||
{
|
||||
Stream.of(cls.getMethods())
|
||||
.filter(method ->
|
||||
Collection.class.isAssignableFrom(<selection>method.getReturnType()</selection>) || Map.class.isAssignableFrom(method.getReturnType()))
|
||||
.collect(Collectors.<Method>toList());
|
||||
}
|
||||
}
|
||||
@@ -476,6 +476,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
doTest(new MockIntroduceVariableHandler("c", false, false, false, "int"));
|
||||
}
|
||||
|
||||
public void testPutInLambdaBodyMultipleOccurrences() {
|
||||
doTest(new MockIntroduceVariableHandler("c", true, false, false, "java.lang.Class<?>"));
|
||||
}
|
||||
|
||||
public void testPutInLambdaBodyVoidValueConflict() {
|
||||
doTest(new MockIntroduceVariableHandler("c", false, false, false, "int"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user