Search in sources :

Example 6 with PyStatementList

use of com.jetbrains.python.psi.PyStatementList in project intellij-community by JetBrains.

the class PyStatementListTest method testOneLineList.

public void testOneLineList() {
    PyElementGenerator generator = PyElementGenerator.getInstance(myFixture.getProject());
    PyFunction function = generator.createPhysicalFromText(LanguageLevel.PYTHON27, PyFunction.class, "def foo(): print 1");
    PyFunction function2 = generator.createPhysicalFromText(LanguageLevel.PYTHON27, PyFunction.class, "def foo(): print 2");
    final PyStatementList list1 = function.getStatementList();
    final PyStatementList list2 = function2.getStatementList();
    new WriteCommandAction.Simple(myFixture.getProject()) {

        @Override
        protected void run() throws Throwable {
            list1.add(list2.getStatements()[0]);
        }
    }.execute();
    assertEquals("def foo():\n    print 1\n    print 2", function.getText());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) PyFunction(com.jetbrains.python.psi.PyFunction) PyElementGenerator(com.jetbrains.python.psi.PyElementGenerator) PyStatementList(com.jetbrains.python.psi.PyStatementList)

Aggregations

PyStatementList (com.jetbrains.python.psi.PyStatementList)6 PsiElement (com.intellij.psi.PsiElement)4 Nullable (org.jetbrains.annotations.Nullable)3 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)2 PyIfStatement (com.jetbrains.python.psi.PyIfStatement)2 PyStatement (com.jetbrains.python.psi.PyStatement)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Editor (com.intellij.openapi.editor.Editor)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 PyElementGenerator (com.jetbrains.python.psi.PyElementGenerator)1 PyFile (com.jetbrains.python.psi.PyFile)1 PyFinallyPart (com.jetbrains.python.psi.PyFinallyPart)1 PyFunction (com.jetbrains.python.psi.PyFunction)1 PyStatementSurrounder (com.jetbrains.python.refactoring.surround.surrounders.statements.PyStatementSurrounder)1 NotNull (org.jetbrains.annotations.NotNull)1