Search in sources :

Example 26 with PyElementGenerator

use of com.jetbrains.python.psi.PyElementGenerator 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

PyElementGenerator (com.jetbrains.python.psi.PyElementGenerator)26 PsiElement (com.intellij.psi.PsiElement)18 PyExpression (com.jetbrains.python.psi.PyExpression)9 PyBinaryExpression (com.jetbrains.python.psi.PyBinaryExpression)5 ASTNode (com.intellij.lang.ASTNode)4 PyStringLiteralExpression (com.jetbrains.python.psi.PyStringLiteralExpression)4 PyNumericLiteralExpression (com.jetbrains.python.psi.PyNumericLiteralExpression)3 Editor (com.intellij.openapi.editor.Editor)2 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)2 LanguageLevel (com.jetbrains.python.psi.LanguageLevel)2 PyFunction (com.jetbrains.python.psi.PyFunction)2 TemplateBuilder (com.intellij.codeInsight.template.TemplateBuilder)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Document (com.intellij.openapi.editor.Document)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiComment (com.intellij.psi.PsiComment)1