mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cython and Python parsers should never create functions with out of statements even if code is bad
This commit is contained in:
@@ -16,10 +16,15 @@
|
||||
package com.jetbrains.python;
|
||||
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.ParsingTestCase;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -220,7 +225,7 @@ public class PythonParsingTest extends ParsingTestCase {
|
||||
}
|
||||
|
||||
public void testTrailingSemicolon() { // PY-363
|
||||
doTest();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testStarExpression() { // PEP-3132
|
||||
@@ -322,7 +327,7 @@ public class PythonParsingTest extends ParsingTestCase {
|
||||
public void testIncompleteFor() { // PY-3792
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
public void testCallInAssignment() { // PY-5062
|
||||
doTest();
|
||||
}
|
||||
@@ -451,6 +456,7 @@ public class PythonParsingTest extends ParsingTestCase {
|
||||
finally {
|
||||
myLanguageLevel = prev;
|
||||
}
|
||||
ensureEachFunctionHasStatementList(myFile, PyFunction.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -459,4 +465,13 @@ public class PythonParsingTest extends ParsingTestCase {
|
||||
file.getVirtualFile().putUserData(LanguageLevel.KEY, myLanguageLevel);
|
||||
return file;
|
||||
}
|
||||
|
||||
public static <T extends PyFunction> void ensureEachFunctionHasStatementList(
|
||||
@NotNull PsiFile parentFile,
|
||||
@NotNull Class<T> functionType) {
|
||||
Collection<T> functions = PsiTreeUtil.findChildrenOfType(parentFile, functionType);
|
||||
for (T functionToCheck : functions) {
|
||||
functionToCheck.getStatementList(); //To make sure each function has statement list (does not throw exception)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user