Search in sources :

Example 76 with PyClass

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

the class PyTestFinder method findClassesForTest.

@NotNull
@Override
public Collection<PsiElement> findClassesForTest(@NotNull PsiElement element) {
    final PyFunction sourceFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class);
    final PyClass source = PsiTreeUtil.getParentOfType(element, PyClass.class);
    if (sourceFunction == null && source == null)
        return Collections.emptySet();
    List<Pair<? extends PsiNamedElement, Integer>> classesWithWeights = new ArrayList<>();
    final List<Pair<String, Integer>> possibleNames = new ArrayList<>();
    if (source != null)
        possibleNames.addAll(TestFinderHelper.collectPossibleClassNamesWithWeights(source.getName()));
    if (sourceFunction != null)
        possibleNames.addAll(TestFinderHelper.collectPossibleClassNamesWithWeights(sourceFunction.getName()));
    for (Pair<String, Integer> eachNameWithWeight : possibleNames) {
        for (PyClass eachClass : PyClassNameIndex.find(eachNameWithWeight.first, element.getProject(), GlobalSearchScope.projectScope(element.getProject()))) {
            if (!PyTestUtil.isPyTestClass(eachClass, null))
                classesWithWeights.add(new Pair<PsiNamedElement, Integer>(eachClass, eachNameWithWeight.second));
        }
        for (PyFunction function : PyFunctionNameIndex.find(eachNameWithWeight.first, element.getProject(), GlobalSearchScope.projectScope(element.getProject()))) {
            if (!PyTestUtil.isPyTestFunction(function))
                classesWithWeights.add(new Pair<PsiNamedElement, Integer>(function, eachNameWithWeight.second));
        }
    }
    return TestFinderHelper.getSortedElements(classesWithWeights, false);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) PsiNamedElement(com.intellij.psi.PsiNamedElement) ArrayList(java.util.ArrayList) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with PyClass

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

the class PyExceptionBreakpointType method addBreakpoint.

@Override
public XBreakpoint<PyExceptionBreakpointProperties> addBreakpoint(final Project project, JComponent parentComponent) {
    final PyClassTreeChooserDialog dialog = new PyClassTreeChooserDialog("Select Exception Class", project, GlobalSearchScope.allScope(project), new PyExceptionCachingFilter(), null);
    dialog.showDialog();
    // on ok
    final PyClass pyClass = dialog.getSelected();
    if (pyClass != null) {
        final String qualifiedName = pyClass.getQualifiedName();
        assert qualifiedName != null : "Qualified name of the class shouldn't be null";
        return ApplicationManager.getApplication().runWriteAction(new Computable<XBreakpoint<PyExceptionBreakpointProperties>>() {

            @Override
            public XBreakpoint<PyExceptionBreakpointProperties> compute() {
                return XDebuggerManager.getInstance(project).getBreakpointManager().addBreakpoint(PyExceptionBreakpointType.this, new PyExceptionBreakpointProperties(qualifiedName));
            }
        });
    }
    return null;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint)

Example 78 with PyClass

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

the class PyControlFlowBuilderTest method testQualifiedSelfReference.

public void testQualifiedSelfReference() {
    final String testName = getTestName(false).toLowerCase();
    configureByFile(testName + ".py");
    final String fullPath = getTestDataPath() + testName + ".txt";
    final PyClass pyClass = ((PyFile) myFile).getTopLevelClasses().get(0);
    final ControlFlow flow = ControlFlowCache.getControlFlow(pyClass.getMethods()[0]);
    check(fullPath, flow);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) ControlFlow(com.intellij.codeInsight.controlflow.ControlFlow)

Example 79 with PyClass

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

the class PyClassMROTest method testTangledInheritance.

public void testTangledInheritance() {
    final int numClasses = 100;
    final List<String> expectedMRO = new ArrayList<>();
    for (int i = numClasses - 1; i >= 1; i--) {
        expectedMRO.add(String.format("Class%03d", i));
    }
    expectedMRO.add("object");
    final PyClass pyClass = getClass(String.format("Class%03d", numClasses));
    final long startTime = System.currentTimeMillis();
    assertMRO(pyClass, ArrayUtil.toStringArray(expectedMRO));
    final long elapsed = System.currentTimeMillis() - startTime;
    assertTrue("Calculation of MRO takes too much time: " + elapsed + " ms", elapsed < 1000);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) ArrayList(java.util.ArrayList)

Example 80 with PyClass

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

the class PyClassMROTest method getClass.

@NotNull
public PyClass getClass(@NotNull String name) {
    myFixture.configureByFile(getPath(getTestName(false)));
    final PyClass cls = myFixture.findElementByText(name, PyClass.class);
    assertNotNull(cls);
    return cls;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PyClass (com.jetbrains.python.psi.PyClass)88 PyFunction (com.jetbrains.python.psi.PyFunction)32 PsiElement (com.intellij.psi.PsiElement)22 NotNull (org.jetbrains.annotations.NotNull)17 ArrayList (java.util.ArrayList)15 Nullable (org.jetbrains.annotations.Nullable)15 PyElement (com.jetbrains.python.psi.PyElement)12 PyMemberInfo (com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo)9 PyFile (com.jetbrains.python.psi.PyFile)8 PsiFile (com.intellij.psi.PsiFile)7 Project (com.intellij.openapi.project.Project)6 Editor (com.intellij.openapi.editor.Editor)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 MultiMap (com.intellij.util.containers.MultiMap)5 PyMethodMember (com.jetbrains.python.codeInsight.override.PyMethodMember)4 PyMemberInfoStorage (com.jetbrains.python.refactoring.classes.PyMemberInfoStorage)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 PsiNamedElement (com.intellij.psi.PsiNamedElement)3 PyHierarchyNodeDescriptor (com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor)3 ControlFlow (com.intellij.codeInsight.controlflow.ControlFlow)2