Search in sources :

Example 41 with PyClass

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

the class PyInheritorsSearchTest method testDotted.

public void testDotted() throws Exception {
    setupProject();
    final PyClass pyClass = findClass("A");
    Collection<PyClass> inheritors = PyClassInheritorsSearch.search(pyClass, true).findAll();
    assertEquals(1, inheritors.size());
}
Also used : PyClass(com.jetbrains.python.psi.PyClass)

Example 42 with PyClass

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

the class PyInheritorsSearchTest method findClass.

private PyClass findClass(final String name) {
    final Project project = myFixture.getProject();
    final Collection<PyClass> classes = PyClassNameIndex.find(name, project, false);
    assertEquals(1, classes.size());
    return classes.iterator().next();
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) Project(com.intellij.openapi.project.Project)

Example 43 with PyClass

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

the class PyDeclarationRangeHandler method getDeclarationRange.

@NotNull
@Override
public TextRange getDeclarationRange(@NotNull PsiElement container) {
    int start = container.getTextRange().getStartOffset();
    if (container instanceof PyFunction) {
        PyParameterList parameterList = ((PyFunction) container).getParameterList();
        return new TextRange(start, parameterList.getTextRange().getEndOffset());
    }
    if (container instanceof PyClass) {
        PyArgumentList argumentList = ((PyClass) container).getSuperClassExpressionList();
        if (argumentList != null) {
            return new TextRange(start, argumentList.getTextRange().getEndOffset());
        }
        ASTNode nameNode = ((PyClass) container).getNameNode();
        if (nameNode != null) {
            return new TextRange(start, nameNode.getStartOffset() + nameNode.getTextLength());
        }
    }
    return container.getTextRange();
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyArgumentList(com.jetbrains.python.psi.PyArgumentList) PyFunction(com.jetbrains.python.psi.PyFunction) ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) PyParameterList(com.jetbrains.python.psi.PyParameterList) NotNull(org.jetbrains.annotations.NotNull)

Example 44 with PyClass

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

the class PyLineMarkerProvider method collectSlowLineMarkers.

public void collectSlowLineMarkers(@NotNull final List<PsiElement> elements, @NotNull final Collection<LineMarkerInfo> result) {
    Set<PyFunction> functions = new HashSet<PyFunction>();
    for (PsiElement element : elements) {
        if (element instanceof PyClass) {
            collectInheritingClasses((PyClass) element, result);
        } else if (element instanceof PyFunction) {
            functions.add((PyFunction) element);
        }
    }
    collectOverridingMethods(functions, result);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet)

Example 45 with PyClass

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

the class PyLineMarkerProvider method collectOverridingMethods.

private static void collectOverridingMethods(final Set<PyFunction> functions, final Collection<LineMarkerInfo> result) {
    Set<PyClass> classes = new HashSet<PyClass>();
    final MultiMap<PyClass, PyFunction> candidates = new MultiMap<PyClass, PyFunction>();
    for (PyFunction function : functions) {
        PyClass pyClass = function.getContainingClass();
        if (pyClass != null && function.getName() != null) {
            classes.add(pyClass);
            candidates.putValue(pyClass, function);
        }
    }
    final Set<PyFunction> overridden = new HashSet<PyFunction>();
    for (final PyClass pyClass : classes) {
        PyClassInheritorsSearch.search(pyClass, true).forEach(inheritor -> {
            for (Iterator<PyFunction> it = candidates.get(pyClass).iterator(); it.hasNext(); ) {
                PyFunction func = it.next();
                if (inheritor.findMethodByName(func.getName(), false, null) != null) {
                    overridden.add(func);
                    it.remove();
                }
            }
            return !candidates.isEmpty();
        });
        if (candidates.isEmpty())
            break;
    }
    for (PyFunction func : overridden) {
        result.add(new LineMarkerInfo<PyFunction>(func, func.getTextOffset(), AllIcons.Gutter.OverridenMethod, Pass.LINE_MARKERS, ourOverridingMethodTooltipProvider, ourOverridingMethodNavigator));
    }
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) MultiMap(com.intellij.util.containers.MultiMap) PyFunction(com.jetbrains.python.psi.PyFunction) HashSet(com.intellij.util.containers.HashSet)

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