Search in sources :

Example 46 with PyClass

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

the class TransformClassicClassQuickFix method applyFix.

public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement psiElement = descriptor.getPsiElement();
    psiElement = PsiTreeUtil.getParentOfType(psiElement, PyClass.class);
    if (psiElement != null) {
        PyClass pyClass = (PyClass) psiElement;
        PyExpression[] superClassExpressions = pyClass.getSuperClassExpressions();
        PyElementGenerator generator = PyElementGenerator.getInstance(project);
        if (superClassExpressions.length == 0) {
            pyClass.replace(generator.createFromText(LanguageLevel.getDefault(), PyClass.class, "class " + pyClass.getName() + "(" + PyNames.OBJECT + "):\n    " + pyClass.getStatementList().getText()));
        } else {
            StringBuilder stringBuilder = new StringBuilder("class ");
            stringBuilder.append(pyClass.getName()).append("(");
            for (PyExpression expression : superClassExpressions) {
                stringBuilder.append(expression.getText()).append(", ");
            }
            stringBuilder.append(PyNames.OBJECT).append(":\n    ");
            stringBuilder.append(pyClass.getStatementList().getText());
            pyClass.replace(generator.createFromText(LanguageLevel.getDefault(), PyClass.class, stringBuilder.toString()));
        }
    }
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyExpression(com.jetbrains.python.psi.PyExpression) PyElementGenerator(com.jetbrains.python.psi.PyElementGenerator) PsiElement(com.intellij.psi.PsiElement)

Example 47 with PyClass

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

the class PyElementNode method getChildrenImpl.

@Override
protected Collection<AbstractTreeNode> getChildrenImpl() {
    PyElement value = getValue();
    // for performance reasons, we don't show nested functions here
    if (value instanceof PyClass) {
        final PyClass pyClass = (PyClass) value;
        List<AbstractTreeNode> result = new ArrayList<>();
        for (PyClass aClass : pyClass.getNestedClasses()) {
            result.add(new PyElementNode(myProject, aClass, getSettings()));
        }
        for (PyFunction function : pyClass.getMethods()) {
            result.add(new PyElementNode(myProject, function, getSettings()));
        }
        return result;
    }
    return Collections.emptyList();
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PyElement(com.jetbrains.python.psi.PyElement)

Example 48 with PyClass

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

the class PyFileNode method getChildrenImpl.

@Override
public Collection<AbstractTreeNode> getChildrenImpl() {
    PyFile value = (PyFile) getValue();
    List<AbstractTreeNode> children = new ArrayList<>();
    for (PyClass child : value.getTopLevelClasses()) {
        children.add(new PyElementNode(myProject, child, getSettings()));
    }
    for (PyFunction function : value.getTopLevelFunctions()) {
        children.add(new PyElementNode(myProject, function, getSettings()));
    }
    return children;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PyFile(com.jetbrains.python.psi.PyFile)

Example 49 with PyClass

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

the class PyPullUpPresenterImpl method isWritable.

private boolean isWritable() {
    final Collection<PyMemberInfo<PyElement>> infos = myView.getSelectedMemberInfos();
    if (infos.isEmpty()) {
        return true;
    }
    final PyElement element = infos.iterator().next().getMember();
    final Project project = element.getProject();
    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, myView.getSelectedParent()))
        return false;
    final PyClass container = PyUtil.getContainingClassOrSelf(element);
    if (container == null || !CommonRefactoringUtil.checkReadOnlyStatus(project, container))
        return false;
    for (final PyMemberInfo<PyElement> info : infos) {
        final PyElement member = info.getMember();
        if (!CommonRefactoringUtil.checkReadOnlyStatus(project, member))
            return false;
    }
    return true;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) Project(com.intellij.openapi.project.Project) PyMemberInfo(com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo) PyElement(com.jetbrains.python.psi.PyElement)

Example 50 with PyClass

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

the class PyPullUpViewSwingImpl method configure.

@Override
public void configure(@NotNull final PyPullUpViewInitializationInfo configInfo) {
    super.configure(configInfo);
    for (final PyClass parent : configInfo.getParents()) {
        myParentsComboBoxModel.addElement(parent);
    }
    myPresenter.parentChanged();
    myParentsCombo.addItemListener(this);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass)

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