for (final Iterator iterator= rewrites.keySet().iterator(); iterator.hasNext();) {
for (final Iterator iterator= fCompilationUnitRewrites.keySet().iterator(); iterator.hasNext();) {
	private TextChangeManager createChangeManager(final IProgressMonitor monitor, final RefactoringStatus status) throws CoreException {		Assert.isNotNull(monitor);		Assert.isNotNull(status);		try {			monitor.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, 8);			final ICompilationUnit source= getDeclaringType().getCompilationUnit();			final IType destination= getDestinationType();			final ICompilationUnit target= destination.getCompilationUnit();			final Map rewrites= new HashMap(3);			final CompilationUnitRewrite sourceRewriter= getCompilationUnitRewrite(rewrites, source);			final CompilationUnitRewrite targetRewriter= getCompilationUnitRewrite(rewrites, target);			final Map deleteMap= createMembersToDeleteMap(new SubProgressMonitor(monitor, 1));			final Map effectedMap= createEffectedTypesMap(new SubProgressMonitor(monitor, 1));			final ICompilationUnit[] units= getAffectedCompilationUnits(new SubProgressMonitor(monitor, 1));			ICompilationUnit unit= null;			CompilationUnitRewrite rewrite= null;			final Map adjustments= new HashMap();			MemberVisibilityAdjustor adjustor= null;			final IProgressMonitor sub= new SubProgressMonitor(monitor, 1);			try {				sub.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, units.length * 11);				for (int index= 0; index < units.length; index++) {					unit= units[index];					if (!(source.equals(unit) || target.equals(unit) || deleteMap.containsKey(unit) || effectedMap.containsKey(unit))) {						sub.worked(10);						continue;					}					rewrite= getCompilationUnitRewrite(rewrites, unit);					if (deleteMap.containsKey(unit) && !destination.isInterface())						deleteDeclarationNodes(sourceRewriter, sourceRewriter.getCu().equals(targetRewriter.getCu()), rewrite, (List) deleteMap.get(unit), SET_PULL_UP);					final CompilationUnit root= sourceRewriter.getRoot();					if (unit.equals(target)) {						final ASTRewrite rewriter= rewrite.getASTRewrite();						if (!JdtFlags.isAbstract(destination) && !destination.isInterface() && getAbstractMethods().length > 0) {							final AbstractTypeDeclaration declaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(destination, rewrite.getRoot());							ModifierRewrite.create(rewriter, declaration).setModifiers(declaration.getModifiers() | Modifier.ABSTRACT, rewrite.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_make_target_abstract, SET_PULL_UP));						}						final TypeVariableMaplet[] mapping= TypeVariableUtil.subTypeToSuperType(getDeclaringType(), destination);						final IProgressMonitor subsub= new SubProgressMonitor(sub, 1);						final AbstractTypeDeclaration declaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(destination, rewrite.getRoot());						fMembersToMove= JavaElementUtil.sortByOffset(fMembersToMove);						subsub.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, fMembersToMove.length);						IMember member= null;						for (int offset= fMembersToMove.length - 1; offset >= 0; offset--) {							member= fMembersToMove[offset];							adjustor= new MemberVisibilityAdjustor(destination, member);							adjustor.setRewrite(sourceRewriter.getASTRewrite(), root);							// TW: set to error if bug 78387 is fixed							adjustor.setFailureSeverity(RefactoringStatus.WARNING);							adjustor.setOwner(fOwner);							adjustor.setRewrites(rewrites);							adjustor.setStatus(status);							adjustor.setAdjustments(adjustments);							adjustor.adjustVisibility(new SubProgressMonitor(subsub, 1));							adjustments.remove(member);							if (member instanceof IField) {								final VariableDeclarationFragment oldField= ASTNodeSearchUtil.getFieldDeclarationFragmentNode((IField) member, root);								if (oldField != null) {									int flags= getModifiersWithUpdatedVisibility(member, member.getFlags(), adjustments, new SubProgressMonitor(subsub, 1), true, status);									if (destination.isInterface())										flags|= Flags.AccFinal;									final FieldDeclaration newField= createNewFieldDeclarationNode(rewriter, root, (IField) member, oldField, mapping, new SubProgressMonitor(subsub, 1), status, flags);									rewriter.getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertAt(newField, ASTNodes.getInsertionIndex(newField, declaration.bodyDeclarations()), rewrite.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_add_member, SET_PULL_UP));									ImportRewriteUtil.addImports(rewrite, oldField.getParent(), new HashMap(), new HashMap(), false);								}							} else if (member instanceof IMethod) {								final MethodDeclaration oldMethod= ASTNodeSearchUtil.getMethodDeclarationNode((IMethod) member, root);								if (oldMethod != null) {									final MethodDeclaration newMethod= createNewMethodDeclarationNode(sourceRewriter, rewrite, ((IMethod) member), oldMethod, root, mapping, adjustments, new SubProgressMonitor(subsub, 1), status);									rewriter.getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, declaration.bodyDeclarations()), rewrite.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_add_member, SET_PULL_UP));									ImportRewriteUtil.addImports(rewrite, oldMethod, new HashMap(), new HashMap(), false);								}							} else if (member instanceof IType) {								final AbstractTypeDeclaration oldType= ASTNodeSearchUtil.getAbstractTypeDeclarationNode((IType) member, root);								if (oldType != null) {									final BodyDeclaration newType= createNewTypeDeclarationNode(((IType) member), oldType, root, mapping, rewriter);									rewriter.getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertAt(newType, ASTNodes.getInsertionIndex(newType, declaration.bodyDeclarations()), rewrite.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_add_member, SET_PULL_UP));									ImportRewriteUtil.addImports(rewrite, oldType, new HashMap(), new HashMap(), false);								}							} else								Assert.isTrue(false);							subsub.worked(1);						}						subsub.done();						for (int offset= 0; offset < fAbstractMethods.length; offset++)							createAbstractMethod(fAbstractMethods[offset], sourceRewriter, root, declaration, mapping, rewrite, adjustments, new SubProgressMonitor(sub, 1), status);					} else						sub.worked(2);					if (unit.equals(sourceRewriter.getCu())) {						final IProgressMonitor subsub= new SubProgressMonitor(sub, 1);						subsub.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, fAbstractMethods.length * 2);						IMethod method= null;						for (int offset= 0; offset < fAbstractMethods.length; offset++) {							method= fAbstractMethods[offset];							adjustor= new MemberVisibilityAdjustor(destination, method);							adjustor.setRewrite(sourceRewriter.getASTRewrite(), root);							adjustor.setRewrites(rewrites);							// TW: set to error if bug 78387 is fixed							adjustor.setFailureSeverity(RefactoringStatus.WARNING);							adjustor.setOwner(fOwner);							adjustor.setStatus(status);							adjustor.setAdjustments(adjustments);							if (needsVisibilityAdjustment(method, false, new SubProgressMonitor(subsub, 1), status))								adjustments.put(method, new MemberVisibilityAdjustor.OutgoingMemberVisibilityAdjustment(method, Modifier.ModifierKeyword.PROTECTED_KEYWORD, RefactoringStatus.createWarningStatus(Messages.format(RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_method_warning, new String[] { MemberVisibilityAdjustor.getLabel(method), RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_protected}), JavaStatusContext.create(method))));						}					} else						sub.worked(2);					if (effectedMap.containsKey(unit))						addNecessaryMethodStubs((List) effectedMap.get(unit), root, rewrite, adjustments, new SubProgressMonitor(sub, 2), status);					if (sub.isCanceled())						throw new OperationCanceledException();				}			} finally {				sub.done();			}			if (adjustor != null && !adjustments.isEmpty())				adjustor.rewriteVisibility(new SubProgressMonitor(monitor, 1));			final TextChangeManager manager= new TextChangeManager();			if (fReplace) {				for (final Iterator iterator= rewrites.keySet().iterator(); iterator.hasNext();) {					unit= (ICompilationUnit) iterator.next();					rewrite= (CompilationUnitRewrite) rewrites.get(unit);					if (rewrite != null)						manager.manage(unit, rewrite.createChange(false, null));				}				TextEdit edit= null;				TextChange change= null;				final Map workingcopies= new HashMap();				final IProgressMonitor subMonitor= new SubProgressMonitor(monitor, 1);				try {					subMonitor.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, rewrites.keySet().size());					for (final Iterator iterator= rewrites.keySet().iterator(); iterator.hasNext();) {						unit= (ICompilationUnit) iterator.next();						change= manager.get(unit);						if (change != null) {							edit= change.getEdit();							if (edit != null) {								final ICompilationUnit copy= createWorkingCopy(unit, edit, status, new SubProgressMonitor(monitor, 1));								if (copy != null)									workingcopies.put(unit, copy);							}						}					}					final ICompilationUnit current= (ICompilationUnit) workingcopies.get(sourceRewriter.getCu());					if (current != null)						rewriteTypeOccurrences(manager, sourceRewriter, current, new HashSet(), status, new SubProgressMonitor(monitor, 1));				} finally {					subMonitor.done();					for (final Iterator iterator= workingcopies.values().iterator(); iterator.hasNext();) {						((ICompilationUnit) iterator.next()).discardWorkingCopy();					}				}			}			for (final Iterator iterator= rewrites.keySet().iterator(); iterator.hasNext();) {				unit= (ICompilationUnit) iterator.next();				rewrite= (CompilationUnitRewrite) rewrites.get(unit);				if (rewrite != null)					manager.manage(unit, rewrite.createChange());			}			return manager;		} finally {			monitor.done();		}	}