use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyImplementMethodsQuickFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
final Editor editor = PyQuickFixUtil.getEditor(file);
if (editor != null && startElement instanceof PyClass) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
ArrayList<PyMethodMember> list = new ArrayList<>();
for (PyFunction function : myToImplement) {
list.add(new PyMethodMember(function));
}
PyOverrideImplementUtil.overrideMethods(editor, (PyClass) startElement, list, true);
} else {
PyOverrideImplementUtil.chooseAndOverrideOrImplementMethods(project, editor, (PyClass) startElement, myToImplement, "Select Methods to Implement", true);
}
}
}
use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyiRelatedItemLineMarkerProvider method collectNavigationMarkers.
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, Collection<? super RelatedItemLineMarkerInfo> result) {
if (element instanceof PyFunction || element instanceof PyTargetExpression || element instanceof PyClass) {
final PsiElement pythonStub = PyiUtil.getPythonStub((PyElement) element);
if (pythonStub != null) {
result.add(createLineMarkerInfo(element, pythonStub, "Has stub item"));
}
final PsiElement originalElement = PyiUtil.getOriginalElement((PyElement) element);
if (originalElement != null) {
result.add(createLineMarkerInfo(element, originalElement, "Stub for item"));
}
}
}
use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyChangeSignatureTest method testAnnotationsForStarredParametersAreNotShownInDialog.
// PY-14774
public void testAnnotationsForStarredParametersAreNotShownInDialog() throws Exception {
runWithLanguageLevel(LanguageLevel.PYTHON30, () -> {
myFixture.configureByText(PythonFileType.INSTANCE, "def func(a, b:int, *args: tuple, c:list, d:str='foo', ** kwargs:dict):\n" + " pass");
final PyFunction function = (PyFunction) new PyChangeSignatureHandler().findTargetMember(myFixture.getFile(), myFixture.getEditor());
assertNotNull(function);
final List<String> expected = Arrays.asList("a", "b", "*args", "c", "d", "**kwargs");
final List<PyParameterInfo> parameters = new PyMethodDescriptor(function).getParameters();
assertEquals(expected, ContainerUtil.map(parameters, info -> info.getOldName()));
});
}
use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyStdlibDocumentationLinkProvider method getStdlibUrlFor.
private String getStdlibUrlFor(PsiElement element, QualifiedName moduleName, Sdk sdk) {
StringBuilder urlBuilder = new StringBuilder(getExternalDocumentationRoot(sdk));
String qnameString = moduleName.toString();
if (qnameString.equals("ntpath") || qnameString.equals("posixpath")) {
qnameString = "os.path";
} else if (qnameString.equals("nt")) {
qnameString = "os";
} else if (qnameString.equals("cPickle")) {
qnameString = "pickle";
} else if (qnameString.equals("pyexpat")) {
qnameString = "xml.parsers.expat";
}
final String pyVersion = PythonDocumentationProvider.pyVersion(sdk.getVersionString());
List<String> modules = pyVersion != null && pyVersion.startsWith("3") ? py3LibraryModules : py2LibraryModules;
boolean foundModule = false;
for (String module : modules) {
if (qnameString.startsWith(module)) {
urlBuilder.append(module.toLowerCase());
urlBuilder.append(".html");
foundModule = true;
break;
}
}
if (foundModule && element instanceof PsiNamedElement && !(element instanceof PyFile)) {
urlBuilder.append('#').append(moduleName).append(".");
if (element instanceof PyFunction) {
final PyClass containingClass = ((PyFunction) element).getContainingClass();
if (containingClass != null) {
urlBuilder.append(containingClass.getName()).append('.');
}
}
urlBuilder.append(((PsiNamedElement) element).getName());
}
return urlBuilder.toString();
}
use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyOverrideTest method testQualified.
public void testQualified() {
// PY-2171
myFixture.configureByFile("override/" + getTestName(true) + ".py");
PyClass dateClass = PyClassNameIndex.findClass("datetime.date", myFixture.getProject());
assertNotNull(dateClass);
PyFunction initMethod = dateClass.findMethodByName(PyNames.INIT, false, null);
assertNotNull(initMethod);
PyOverrideImplementUtil.overrideMethods(myFixture.getEditor(), getTopLevelClass(0), Collections.singletonList(new PyMethodMember(initMethod)), false);
myFixture.checkResultByFile("override/" + getTestName(true) + "_after.py", true);
}
Aggregations