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;
}
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;
}
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());
}
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);
}
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;
}
Aggregations