Search in sources :

Example 1 with PushDownConflicts

use of com.intellij.refactoring.memberPushDown.PushDownConflicts in project intellij-community by JetBrains.

the class InlineSuperClassRefactoringProcessor method preprocessUsages.

@Override
protected boolean preprocessUsages(@NotNull final Ref<UsageInfo[]> refUsages) {
    final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    final PushDownConflicts pushDownConflicts = new PushDownConflicts(mySuperClass, myMemberInfos, conflicts);
    for (PsiClass targetClass : myTargetClasses) {
        if (targetClass instanceof PsiAnonymousClass) {
            conflicts.putValue(targetClass, "Cannot inline into anonymous class.");
        } else if (PsiTreeUtil.isAncestor(mySuperClass, targetClass, false)) {
            conflicts.putValue(targetClass, "Cannot inline into the inner class. Move \'" + targetClass.getName() + "\' to upper level");
        } else {
            for (MemberInfo info : myMemberInfos) {
                final PsiMember member = info.getMember();
                pushDownConflicts.checkMemberPlacementInTargetClassConflict(targetClass, member);
            }
        //todo check accessibility conflicts
        }
    }
    if (myCurrentInheritor != null) {
        ReferencesSearch.search(myCurrentInheritor).forEach(reference -> {
            final PsiElement element = reference.getElement();
            if (element != null) {
                final PsiElement parent = element.getParent();
                if (parent instanceof PsiNewExpression) {
                    final PsiClass aClass = PsiUtil.resolveClassInType(getPlaceExpectedType(parent));
                    if (aClass == mySuperClass) {
                        conflicts.putValue(parent, "Instance of target type is passed to a place where super class is expected.");
                        return false;
                    }
                }
            }
            return true;
        });
    }
    checkConflicts(refUsages, conflicts);
    return showConflicts(conflicts, refUsages.get());
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) PushDownConflicts(com.intellij.refactoring.memberPushDown.PushDownConflicts) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo)

Aggregations

PushDownConflicts (com.intellij.refactoring.memberPushDown.PushDownConflicts)1 MemberInfo (com.intellij.refactoring.util.classMembers.MemberInfo)1 MultiMap (com.intellij.util.containers.MultiMap)1