use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class AbstractPythonTestRunConfiguration method getTestSpec.
/**
* Create test spec (string to be passed to runner, probably glued with {@link AbstractPythonLegacyTestRunConfiguration#TEST_NAME_PARTS_SPLITTER})
*
* @param location test location as reported by runner
* @param failedTest failed test
* @return string spec or null if spec calculation is impossible
*/
@Nullable
public String getTestSpec(@NotNull final Location<?> location, @NotNull final AbstractTestProxy failedTest) {
PsiElement element = location.getPsiElement();
PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class, false);
if (location instanceof PyPsiLocationWithFixedClass) {
pyClass = ((PyPsiLocationWithFixedClass) location).getFixedClass();
}
PyFunction pyFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class, false);
final VirtualFile virtualFile = location.getVirtualFile();
if (virtualFile != null) {
String path = virtualFile.getCanonicalPath();
if (pyClass != null) {
path += TEST_NAME_PARTS_SPLITTER + pyClass.getName();
}
if (pyFunction != null) {
path += TEST_NAME_PARTS_SPLITTER + pyFunction.getName();
}
return path;
}
return null;
}
use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyTestConfigurationProducer method getKeywords.
@Nullable
private static String getKeywords(@NotNull final PsiElement element, @NotNull final Sdk sdk) {
final PyFunction pyFunction = findTestFunction(element);
final PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class, false);
String keywords = null;
if (pyFunction != null) {
keywords = pyFunction.getName();
if (pyClass != null) {
final List<PyPackage> packages = PyPackageManager.getInstance(sdk).getPackages();
final PyPackage pytestPackage = packages != null ? PyPackageUtil.findPackage(packages, "pytest") : null;
if (pytestPackage != null && PackageVersionComparator.VERSION_COMPARATOR.compare(pytestPackage.getVersion(), "2.3.3") >= 0) {
keywords = pyClass.getName() + " and " + keywords;
} else {
keywords = pyClass.getName() + "." + keywords;
}
}
} else if (pyClass != null) {
keywords = pyClass.getName();
}
return keywords;
}
use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class NumpyClassMembersProvider method getMembers.
@NotNull
@Override
public Collection<PyCustomMember> getMembers(PyClassType clazz, PsiElement location, TypeEvalContext typeEvalContext) {
if (location != null && clazz.getPyClass().isSubclass(PyNames.TYPES_FUNCTION_TYPE, typeEvalContext)) {
final PsiElement element = location.getOriginalElement();
final PsiReference reference = element.getReference();
if (reference != null) {
final PsiElement resolved = reference.resolve();
if (resolved instanceof PyFunction) {
final List<PyCustomMember> result = new ArrayList<>();
if (NumpyUfuncs.isUFunc(((PyFunction) resolved).getName()) && NumpyDocStringTypeProvider.isInsideNumPy(resolved)) {
for (String method : NumpyUfuncs.UFUNC_METHODS) {
result.add(new PyCustomMember(method, resolved));
}
return result;
}
}
}
}
return Collections.emptyList();
}
use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyQtTypeProvider method getReturnType.
@Override
public Ref<PyType> getReturnType(@NotNull PyCallable callable, @NotNull TypeEvalContext context) {
if (PyNames.INIT.equals(callable.getName()) && callable instanceof PyFunction) {
final PyFunction function = (PyFunction) callable;
final PyClass containingClass = function.getContainingClass();
if (containingClass != null && ourQt4Signal.equals(containingClass.getName())) {
final String classQName = containingClass.getQualifiedName();
if (classQName != null) {
final QualifiedName name = QualifiedName.fromDottedString(classQName);
final String qtVersion = name.getComponents().get(0);
final PyClass aClass = PyClassNameIndex.findClass(qtVersion + "." + ourQtBoundSignal, function.getProject());
if (aClass != null) {
final PyType type = new PyClassTypeImpl(aClass, false);
return Ref.create(type);
}
}
}
}
return null;
}
use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyQtTypeProvider method getCallableType.
@Nullable
@Override
public PyType getCallableType(@NotNull PyCallable callable, @NotNull TypeEvalContext context) {
if (callable instanceof PyFunction) {
final String qualifiedName = callable.getQualifiedName();
if (qualifiedName != null && qualifiedName.startsWith("PyQt")) {
final QualifiedName name = QualifiedName.fromDottedString(qualifiedName);
final String qtVersion = name.getComponents().get(0);
final String docstring = ((PyFunction) callable).getDocStringValue();
if (docstring != null && docstring.contains("[signal]")) {
final PyClass aClass = PyClassNameIndex.findClass(qtVersion + "." + ourQtBoundSignal, callable.getProject());
if (aClass != null)
return new PyClassTypeImpl(aClass, false);
}
}
}
return null;
}
Aggregations