Search in sources :

Example 6 with PyMethodMember

use of com.jetbrains.python.codeInsight.override.PyMethodMember 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);
        }
    }
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) PyMethodMember(com.jetbrains.python.codeInsight.override.PyMethodMember) ArrayList(java.util.ArrayList) Editor(com.intellij.openapi.editor.Editor)

Example 7 with PyMethodMember

use of com.jetbrains.python.codeInsight.override.PyMethodMember 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);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) PyMethodMember(com.jetbrains.python.codeInsight.override.PyMethodMember)

Aggregations

PyMethodMember (com.jetbrains.python.codeInsight.override.PyMethodMember)7 PyFunction (com.jetbrains.python.psi.PyFunction)7 PyClass (com.jetbrains.python.psi.PyClass)5 Editor (com.intellij.openapi.editor.Editor)1 PsiElement (com.intellij.psi.PsiElement)1 ArrayList (java.util.ArrayList)1