mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-6610 Convert lambda to function: leads to unresolved reference when using local vars in lambda
This commit is contained in:
@@ -237,7 +237,7 @@ public class PyCodeFragmentUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<PsiElement> getInputElements(@NotNull List<Instruction> subGraph, @NotNull List<Instruction> graph) {
|
||||
public static List<PsiElement> getInputElements(@NotNull List<Instruction> subGraph, @NotNull List<Instruction> graph) {
|
||||
final List<PsiElement> result = new ArrayList<PsiElement>();
|
||||
final Set<PsiElement> subGraphElements = getSubGraphElements(subGraph);
|
||||
for (Instruction instruction : getReadInstructions(subGraph)) {
|
||||
|
||||
+13
-1
@@ -1,6 +1,8 @@
|
||||
package com.jetbrains.python.codeInsight.intentions;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.codeInsight.controlflow.ControlFlow;
|
||||
import com.intellij.codeInsight.controlflow.Instruction;
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
@@ -11,10 +13,15 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.codeInsight.codeFragment.PyCodeFragmentUtil;
|
||||
import com.jetbrains.python.codeInsight.controlflow.ControlFlowCache;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyFunctionBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: catherine
|
||||
* Intention to convert lambda to function
|
||||
@@ -34,8 +41,13 @@ public class PyConvertLambdaToFunctionIntention extends BaseIntentionAction {
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
PyLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyLambdaExpression.class);
|
||||
if (lambdaExpression != null) {
|
||||
if (lambdaExpression.getBody() != null)
|
||||
if (lambdaExpression.getBody() != null) {
|
||||
final ControlFlow flow = ControlFlowCache.getControlFlow(lambdaExpression);
|
||||
final List<Instruction> graph = Arrays.asList(flow.getInstructions());
|
||||
final List<PsiElement> elements = PyCodeFragmentUtil.getInputElements(graph, graph);
|
||||
if (elements.size() > 0) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
def transform(n):
|
||||
return lambda <caret>x: x + n
|
||||
@@ -202,6 +202,11 @@ public class PyIntentionTest extends PyTestCase {
|
||||
public void testConvertLambdaToFunction() {
|
||||
doTest(PyBundle.message("INTN.convert.lambda.to.function"));
|
||||
}
|
||||
|
||||
public void testConvertLambdaToFunction1() { //PY-6610
|
||||
doNegativeTest(PyBundle.message("INTN.convert.lambda.to.function"));
|
||||
}
|
||||
|
||||
public void testConvertVariadicParam() { //PY-2264
|
||||
doTest(PyBundle.message("INTN.convert.variadic.param"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user