Search in sources :

Example 6 with PyFile

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

the class MoveFromFutureImportQuickFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final PsiElement problemElement = descriptor.getPsiElement();
    final PsiFile psiFile = problemElement.getContainingFile();
    if (psiFile instanceof PyFile) {
        AddImportHelper.addFromImportStatement(psiFile, (PyFromImportStatement) problemElement, AddImportHelper.ImportPriority.FUTURE, null);
        problemElement.delete();
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) PyFile(com.jetbrains.python.psi.PyFile) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PyFile

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

the class PyDeprecationTest method testFunctionStub.

public void testFunctionStub() {
    myFixture.configureByFile("deprecation/functionStub.py");
    PyFile file = (PyFile) myFixture.getFile();
    assertEquals("commands.getstatus() is deprecated", file.findTopLevelFunction("getstatus").getDeprecationMessage());
    PlatformTestUtil.tryGcSoftlyReachableObjects();
    assertNotParsed(file);
    assertEquals("commands.getstatus() is deprecated", file.findTopLevelFunction("getstatus").getDeprecationMessage());
    assertNotParsed(file);
}
Also used : PyFile(com.jetbrains.python.psi.PyFile)

Example 8 with PyFile

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

the class PyDeprecationTest method testFunction.

public void testFunction() {
    myFixture.configureByText(PythonFileType.INSTANCE, "def getstatus(file):\n" + "    \"\"\"Return output of \"ls -ld <file>\" in a string.\"\"\"\n" + "    import warnings\n" + "    warnings.warn(\"commands.getstatus() is deprecated\", DeprecationWarning, 2)\n" + "    return getoutput('ls -ld' + mkarg(file))");
    PyFunction getstatus = ((PyFile) myFixture.getFile()).findTopLevelFunction("getstatus");
    assertEquals("commands.getstatus() is deprecated", getstatus.getDeprecationMessage());
}
Also used : PyFunction(com.jetbrains.python.psi.PyFunction) PyFile(com.jetbrains.python.psi.PyFile)

Example 9 with PyFile

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

the class PyBlockEvaluatorTest method doEvaluate.

private PyBlockEvaluator doEvaluate(String text, boolean skipEvaluatingCollectionItems) {
    PyBlockEvaluator eval = new PyBlockEvaluator();
    if (skipEvaluatingCollectionItems) {
        eval.setEvaluateCollectionItems(false);
    }
    PyFile file = (PyFile) PsiFileFactory.getInstance(myFixture.getProject()).createFileFromText("a.py", PythonFileType.INSTANCE, text);
    eval.evaluate(file);
    return eval;
}
Also used : PyBlockEvaluator(com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator) PyFile(com.jetbrains.python.psi.PyFile)

Example 10 with PyFile

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

the class PyBlockEvaluatorTest method testFunction.

public void testFunction() {
    PyBlockEvaluator eval = new PyBlockEvaluator();
    PyFile file = (PyFile) PsiFileFactory.getInstance(myFixture.getProject()).createFileFromText("a.py", PythonFileType.INSTANCE, "def foo(): return 'a'");
    PyFunction foo = file.findTopLevelFunction("foo");
    eval.evaluate(foo);
    assertEquals("a", eval.getReturnValue());
}
Also used : PyFunction(com.jetbrains.python.psi.PyFunction) PyBlockEvaluator(com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator) PyFile(com.jetbrains.python.psi.PyFile)

Aggregations

PyFile (com.jetbrains.python.psi.PyFile)42 PsiElement (com.intellij.psi.PsiElement)15 PsiFile (com.intellij.psi.PsiFile)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 Project (com.intellij.openapi.project.Project)9 PyFunction (com.jetbrains.python.psi.PyFunction)9 PyClass (com.jetbrains.python.psi.PyClass)8 NotNull (org.jetbrains.annotations.NotNull)8 ArrayList (java.util.ArrayList)7 PsiDirectory (com.intellij.psi.PsiDirectory)4 Sdk (com.intellij.openapi.projectRoots.Sdk)3 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)3 PyStatement (com.jetbrains.python.psi.PyStatement)3 PyBlockEvaluator (com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator)3 File (java.io.File)3 Nullable (org.jetbrains.annotations.Nullable)3 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 Editor (com.intellij.openapi.editor.Editor)2 Module (com.intellij.openapi.module.Module)2 PsiNamedElement (com.intellij.psi.PsiNamedElement)2