Search in sources :

Example 56 with PyClass

use of com.jetbrains.python.psi.PyClass 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;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyClassTypeImpl(com.jetbrains.python.psi.types.PyClassTypeImpl) PyFunction(com.jetbrains.python.psi.PyFunction) QualifiedName(com.intellij.psi.util.QualifiedName) Nullable(org.jetbrains.annotations.Nullable)

Example 57 with PyClass

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

the class PyChangeBaseClassQuickFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement element = descriptor.getPsiElement();
    final PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class);
    assert pyClass != null;
    final PyArgumentList expressionList = pyClass.getSuperClassExpressionList();
    if (expressionList != null && expressionList.getArguments().length != 0) {
        final PyExpression argument = expressionList.getArguments()[0];
        final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(argument);
        builder.replaceElement(argument, argument.getText());
        final VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
        if (virtualFile != null) {
            final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), true);
            assert editor != null;
            builder.run(editor, false);
        }
    }
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyArgumentList(com.jetbrains.python.psi.PyArgumentList) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TemplateBuilder(com.intellij.codeInsight.template.TemplateBuilder) PyExpression(com.jetbrains.python.psi.PyExpression) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement)

Example 58 with PyClass

use of com.jetbrains.python.psi.PyClass 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 59 with PyClass

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

the class PyClassRefactoringHandler method doRefactor.

private void doRefactor(Project project, PsiElement element1, PsiElement element2, Editor editor, PsiFile file, DataContext dataContext) {
    if (ApplicationManagerEx.getApplicationEx().isUnitTestMode())
        return;
    CommonRefactoringUtil.checkReadOnlyStatus(project, file);
    final PyClass clazz = PyUtil.getContainingClassOrSelf(element1);
    if (!inClass(clazz, project, editor, "refactoring.pull.up.error.cannot.perform.refactoring.not.inside.class"))
        return;
    assert clazz != null;
    final PyMemberInfoStorage infoStorage = PyMembersRefactoringSupport.getSelectedMemberInfos(clazz, element1, element2);
    doRefactorImpl(project, clazz, infoStorage, editor);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass)

Example 60 with PyClass

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

the class PyClassNameIndex method findClass.

/**
   * @deprecated use {@link com.jetbrains.python.psi.PyPsiFacade#createClassByQName(String, PsiElement)} or skeleton may be found
   */
@Deprecated
@Nullable
public static PyClass findClass(@NotNull String qName, Project project, GlobalSearchScope scope) {
    int pos = qName.lastIndexOf(".");
    String shortName = pos > 0 ? qName.substring(pos + 1) : qName;
    for (PyClass pyClass : find(shortName, project, scope)) {
        if (qName.equals(pyClass.getQualifiedName())) {
            return pyClass;
        }
    }
    return null;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) Nullable(org.jetbrains.annotations.Nullable)

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