private void markTypeParameterUsages( final PsiClass psiClass, PsiClassType migrationType, PsiReferenceParameterList referenceParameterList, final Map<PsiElement, Pair<PsiReference[], PsiType>> roots) { final PsiSubstitutor[] fullHierarchySubstitutor = { migrationType.resolveGenerics().getSubstitutor() }; RefactoringHierarchyUtil.processSuperTypes( migrationType, new RefactoringHierarchyUtil.SuperTypeVisitor() { @Override public void visitType(PsiType aType) { fullHierarchySubstitutor[0] = fullHierarchySubstitutor[0].putAll( ((PsiClassType) aType).resolveGenerics().getSubstitutor()); } @Override public void visitClass(PsiClass aClass) { // do nothing } }); final PsiClass resolvedClass = (PsiClass) ((PsiJavaCodeReferenceElement) referenceParameterList.getParent()).resolve(); ; LOG.assertTrue(resolvedClass != null); final Set<PsiClass> superClasses = new HashSet<PsiClass>(); superClasses.add(resolvedClass); InheritanceUtil.getSuperClasses(resolvedClass, superClasses, true); for (PsiClass superSuperClass : superClasses) { final TypeParameterSearcher parameterSearcher = new TypeParameterSearcher(superSuperClass.getTypeParameters()); superSuperClass.accept( new JavaRecursiveElementVisitor() { @Override public void visitMethod(final PsiMethod method) { super.visitMethod(method); processMemberType( method, parameterSearcher, psiClass, fullHierarchySubstitutor[0], roots); for (PsiParameter parameter : method.getParameterList().getParameters()) { processMemberType( parameter, parameterSearcher, psiClass, fullHierarchySubstitutor[0], roots); } } @Override public void visitField(final PsiField field) { super.visitField(field); processMemberType( field, parameterSearcher, psiClass, fullHierarchySubstitutor[0], roots); } }); } }
private boolean willBeUsedInSubclass(PsiElement member, PsiClass superclass, PsiClass subclass) { for (PsiReference ref : ReferencesSearch.search(member, new LocalSearchScope(subclass), false)) { PsiElement element = ref.getElement(); if (!RefactoringHierarchyUtil.willBeInTargetClass( element, myMembersToMove, superclass, false)) { return true; } } return false; }
protected void visitClassMemberReferenceElement( PsiMember classMember, PsiJavaCodeReferenceElement classMemberReference) { if (classMember.hasModifierProperty(PsiModifier.STATIC)) { if (!myMembersToMove.contains(classMember) && RefactoringHierarchyUtil.isMemberBetween( myTargetSuperClass, mySourceClass, classMember)) { myReferences.add(classMemberReference); myReferees.add(classMember); myRefereeClasses.add(classMember.getContainingClass()); } else if (myMembersToMove.contains(classMember) || myMembersAfterMove.contains(classMember)) { myReferences.add(classMemberReference); myReferees.add(classMember); myRefereeClasses.add(myTargetSuperClass); } } }
protected PsiClass getPreselection() { PsiClass preselection = RefactoringHierarchyUtil.getNearestBaseClass(myClass, false); final String statKey = PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(); for (StatisticsInfo info : StatisticsManager.getInstance().getAllValues(statKey)) { final String superClassName = info.getValue(); PsiClass superClass = null; for (PsiClass aClass : mySuperClasses) { if (Comparing.strEqual(superClassName, aClass.getQualifiedName())) { superClass = aClass; break; } } if (superClass != null && StatisticsManager.getInstance().getUseCount(info) > 0) { preselection = superClass; break; } } return preselection; }
@Override protected void visitClassMemberReferenceElement( GrMember classMember, GrReferenceElement classMemberReference) { if (classMember.hasModifierProperty( PsiModifier.STATIC) /*&& classMemberReference.isQualified()*/) { if (!myMovedMembers.contains(classMember) && RefactoringHierarchyUtil.isMemberBetween( myTargetSuperClass, mySourceClass, classMember)) { myReferences.add(classMemberReference); myReferees.add(classMember); myRefereeClasses.add(classMember.getContainingClass()); } else if (myMovedMembers.contains(classMember) || myMembersAfterMove.contains(classMember)) { myReferences.add(classMemberReference); myReferees.add(classMember); myRefereeClasses.add(myTargetSuperClass); } } }
protected void visitClassMemberReferenceElement( PsiMember classMember, PsiJavaCodeReferenceElement classMemberReference) { if (classMember != null && RefactoringHierarchyUtil.isMemberBetween(mySuperClass, mySubclass, classMember)) { if (classMember.hasModifierProperty(PsiModifier.STATIC) && !willBeMoved(classMember, myMovedMembers)) { final boolean isAccessible; if (mySuperClass != null) { isAccessible = PsiUtil.isAccessible(classMember, mySuperClass, null); } else if (myTargetPackage != null) { isAccessible = PsiUtil.isAccessibleFromPackage(classMember, myTargetPackage); } else { isAccessible = classMember.hasModifierProperty(PsiModifier.PUBLIC); } if (!isAccessible) { String message = RefactoringBundle.message( "0.uses.1.which.is.not.accessible.from.the.superclass", RefactoringUIUtil.getDescription(myScope, false), RefactoringUIUtil.getDescription(classMember, true)); message = CommonRefactoringUtil.capitalize(message); myConflictsList.putValue(classMember, message); } return; } if (!myAbstractMethods.contains(classMember) && !willBeMoved(classMember, myMovedMembers)) { if (!existsInSuperClass(classMember)) { String message = RefactoringBundle.message( "0.uses.1.which.is.not.moved.to.the.superclass", RefactoringUIUtil.getDescription(myScope, false), RefactoringUIUtil.getDescription(classMember, true)); message = CommonRefactoringUtil.capitalize(message); myConflictsList.putValue(classMember, message); } } } }