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);
}
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;
}
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);
}
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);
}
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;
}
Aggregations