Search in sources :

Example 16 with PyFileImpl

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

the class PyStubsTest method testImportFeatures.

public void testImportFeatures() {
    final PyFileImpl file = (PyFileImpl) getTestFile();
    assertTrue(file.hasImportFromFuture(FutureFeature.DIVISION));
    assertTrue(file.hasImportFromFuture(FutureFeature.UNICODE_LITERALS));
    assertNotParsed(file);
}
Also used : PyFileImpl(com.jetbrains.python.psi.impl.PyFileImpl)

Example 17 with PyFileImpl

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

the class PyStubsTest method testRenamingUpdatesTheStub.

public void testRenamingUpdatesTheStub() {
    final PyFile file = getTestFile("LoadingTreeRetainsKnownPsiElement.py");
    final List<PyClass> classes = file.getTopLevelClasses();
    assertEquals(1, classes.size());
    final PyClass pyClass = classes.get(0);
    assertEquals("SomeClass", pyClass.getName());
    // Ensure we haven't loaded the tree yet.
    final PyFileImpl fileImpl = (PyFileImpl) file;
    assertNull(fileImpl.getTreeElement());
    // Load the tree
    final PsiElement[] children = file.getChildren();
    assertNotNull(fileImpl.getTreeElement());
    assertEquals(1, children.length);
    assertSame(pyClass, children[0]);
    new WriteCommandAction(myFixture.getProject(), fileImpl) {

        @Override
        protected void run(@NotNull final Result result) throws Throwable {
            pyClass.setName("RenamedClass");
            assertEquals("RenamedClass", pyClass.getName());
        }
    }.execute();
    StubElement fileStub = fileImpl.getStub();
    assertNull("There should be no stub if file holds tree element", fileStub);
    new WriteCommandAction(myFixture.getProject(), fileImpl) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            ((SingleRootFileViewProvider) fileImpl.getViewProvider()).onContentReload();
        }
    }.execute();
    // Test unload succeeded.
    assertNull(fileImpl.getTreeElement());
    assertEquals("RenamedClass", fileImpl.getTopLevelClasses().get(0).getName());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) PyFileImpl(com.jetbrains.python.psi.impl.PyFileImpl) StubElement(com.intellij.psi.stubs.StubElement) Result(com.intellij.openapi.application.Result)

Aggregations

PyFileImpl (com.jetbrains.python.psi.impl.PyFileImpl)17 PyImportStatementBase (com.jetbrains.python.psi.PyImportStatementBase)2 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)1 InspectionProfile (com.intellij.codeInspection.InspectionProfile)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)1 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)1 StubElement (com.intellij.psi.stubs.StubElement)1 QualifiedName (com.intellij.psi.util.QualifiedName)1 PyCodeStyleSettings (com.jetbrains.python.formatter.PyCodeStyleSettings)1 PyPep8Inspection (com.jetbrains.python.inspections.PyPep8Inspection)1 Nullable (org.jetbrains.annotations.Nullable)1