Search in sources :

Example 51 with PyClass

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

the class MembersConflictDialog method convertDescription.

@NotNull
private static MultiMap<PsiElement, String> convertDescription(@NotNull final MultiMap<PyClass, PyMemberInfo<?>> duplicateConflictDescriptions, @NotNull final Collection<PyMemberInfo<?>> dependenciesConflicts) {
    final MultiMap<PsiElement, String> result = new MultiMap<>();
    for (final PyClass aClass : duplicateConflictDescriptions.keySet()) {
        for (final PyMemberInfo<?> pyMemberInfo : duplicateConflictDescriptions.get(aClass)) {
            final String message = RefactoringBundle.message("0.already.contains.a.1", RefactoringUIUtil.getDescription(aClass, false), RefactoringUIUtil.getDescription(pyMemberInfo.getMember(), false));
            result.putValue(aClass, message);
        }
    }
    for (final PyMemberInfo<?> memberUnderConflict : dependenciesConflicts) {
        result.putValue(memberUnderConflict.getMember(), PyBundle.message("refactoring.will.not.be.accessible", RefactoringUIUtil.getDescription(memberUnderConflict.getMember(), false)));
    }
    return result;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) MultiMap(com.intellij.util.containers.MultiMap) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 52 with PyClass

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

the class MembersManager method getAllDependencies.

/**
   * Returns all elements this member depends on.
   *
   * @param classWhereMemberDeclared class where member declared
   * @param member                   member itself
   * @param destinationClass         where this member would be moved (or null if new class is unknown)
   * @return collection of elements this member depends on excluding those, would be available in destination class
   */
@NotNull
public static Collection<? extends PyElement> getAllDependencies(@NotNull final PyClass classWhereMemberDeclared, @NotNull final PyElement member, @Nullable final PyClass destinationClass) {
    final PyMemberInfo<PyElement> memberInfo = findMember(classWhereMemberDeclared, member);
    final Collection<? extends PyElement> elementsToCheckDependency = memberInfo.getMembersManager().getElementsToStoreReferences(Collections.singleton(member));
    final MultiMap<PyClass, PyElement> dependencies = new MultiMap<>();
    final Collection<PyElement> result = new HashSet<>();
    for (final MembersManager<? extends PyElement> manager : MANAGERS) {
        for (final PyElement elementToCheckDependency : elementsToCheckDependency) {
            dependencies.putAllValues(manager.getDependencies(elementToCheckDependency));
        }
    }
    if (destinationClass != null) {
        final Iterator<PyClass> classesIterator = dependencies.keySet().iterator();
        while (classesIterator.hasNext()) {
            final PyClass memberClass = classesIterator.next();
            if (memberClass.equals(destinationClass) || ArrayUtil.contains(memberClass, destinationClass.getSuperClasses(null))) {
                // IF still would be available
                classesIterator.remove();
            }
        }
    }
    for (final MembersManager<? extends PyElement> manager : MANAGERS) {
        result.addAll(manager.getDependencies(dependencies));
    }
    result.addAll(dependencies.values());
    return result;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) MultiMap(com.intellij.util.containers.MultiMap) PyElement(com.jetbrains.python.psi.PyElement) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with PyClass

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

the class PyMembersRefactoringBaseProcessor method performRefactoring.

@Override
protected final void performRefactoring(@NotNull final UsageInfo[] usages) {
    final Collection<PyClass> destinations = new ArrayList<>(usages.length);
    for (final UsageInfo usage : usages) {
        if (!(usage instanceof PyUsageInfo)) {
            throw new IllegalArgumentException("Only PyUsageInfo is accepted here");
        }
        //We collect destination info to pass it to members manager
        destinations.add(((PyUsageInfo) usage).getTo());
    }
    MembersManager.moveAllMembers(myMembersToMove, myFrom, destinations.toArray(new PyClass[destinations.size()]));
    // To remove unneeded imports
    PyClassRefactoringUtil.optimizeImports(myFrom.getContainingFile());
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) ArrayList(java.util.ArrayList) UsageInfo(com.intellij.usageView.UsageInfo)

Example 54 with PyClass

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

the class RenamePyClassProcessor method findReferences.

@NotNull
@Override
public Collection<PsiReference> findReferences(final PsiElement element) {
    if (element instanceof PyClass) {
        final PyFunction initMethod = ((PyClass) element).findMethodByName(PyNames.INIT, true, null);
        if (initMethod != null) {
            final List<PsiReference> allRefs = Collections.synchronizedList(new ArrayList<PsiReference>());
            allRefs.addAll(super.findReferences(element));
            ReferencesSearch.search(initMethod, GlobalSearchScope.projectScope(element.getProject())).forEach(psiReference -> {
                if (psiReference.getCanonicalText().equals(((PyClass) element).getName())) {
                    allRefs.add(psiReference);
                }
                return true;
            });
            return allRefs;
        }
    }
    return super.findReferences(element);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) PsiReference(com.intellij.psi.PsiReference) NotNull(org.jetbrains.annotations.NotNull)

Example 55 with PyClass

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

the class PyQtTypeProvider method getReturnType.

@Override
public Ref<PyType> getReturnType(@NotNull PyCallable callable, @NotNull TypeEvalContext context) {
    if (PyNames.INIT.equals(callable.getName()) && callable instanceof PyFunction) {
        final PyFunction function = (PyFunction) callable;
        final PyClass containingClass = function.getContainingClass();
        if (containingClass != null && ourQt4Signal.equals(containingClass.getName())) {
            final String classQName = containingClass.getQualifiedName();
            if (classQName != null) {
                final QualifiedName name = QualifiedName.fromDottedString(classQName);
                final String qtVersion = name.getComponents().get(0);
                final PyClass aClass = PyClassNameIndex.findClass(qtVersion + "." + ourQtBoundSignal, function.getProject());
                if (aClass != null) {
                    final PyType type = new PyClassTypeImpl(aClass, false);
                    return Ref.create(type);
                }
            }
        }
    }
    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) PyType(com.jetbrains.python.psi.types.PyType)

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