return new JavaRefactoringDescriptor(ID_EXTRACT_METHOD, project, Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_descriptor_description, new String[] {getSignature(), method != null ? BindingLabelProvider.getBindingLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED) : '{' + JavaElementLabels.ELLIPSIS_STRING + '}', BindingLabelProvider.getBindingLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)}), getComment(), arguments, RefactoringDescriptor.STRUCTURAL_CHANGE);
JavaRefactoringDescriptor descriptor= new JavaRefactoringDescriptor(ID_EXTRACT_METHOD, project, Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_descriptor_description, new String[] {getSignature(), method != null ? BindingLabelProvider.getBindingLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED) : '{' + JavaElementLabels.ELLIPSIS_STRING + '}', BindingLabelProvider.getBindingLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)}), getComment(), arguments, RefactoringDescriptor.STRUCTURAL_CHANGE); return new RefactoringChangeDescriptor(descriptor);
	public Change createChange(IProgressMonitor pm) throws CoreException {		if (fMethodName == null)			return null;		pm.beginTask("", 2); //$NON-NLS-1$		fAnalyzer.aboutToCreateChange();		BodyDeclaration declaration= fAnalyzer.getEnclosingBodyDeclaration();		fRewriter= ASTRewrite.create(declaration.getAST());		final CompilationUnitChange result= new CompilationUnitChange(RefactoringCoreMessages.ExtractMethodRefactoring_change_name, fCUnit) {			public final ChangeDescriptor getDescriptor() {				final Map arguments= new HashMap();				arguments.put(JavaRefactoringDescriptor.INPUT, fCUnit.getHandleIdentifier());				arguments.put(JavaRefactoringDescriptor.NAME, fMethodName);				arguments.put(ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); //$NON-NLS-1$				arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());				arguments.put(ATTRIBUTE_DESTINATION, new Integer(fDestinationIndex).toString());				arguments.put(ATTRIBUTE_EXCEPTIONS, Boolean.valueOf(fThrowRuntimeExceptions).toString());				arguments.put(ATTRIBUTE_COMMENTS, Boolean.valueOf(fGenerateJavadoc).toString());				arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplaceDuplicates).toString());				String project= null;				IJavaProject javaProject= fCUnit.getJavaProject();				if (javaProject != null)					project= javaProject.getElementName();				ITypeBinding type= null;				if (fDestination instanceof AbstractTypeDeclaration) {					final AbstractTypeDeclaration decl= (AbstractTypeDeclaration) fDestination;					type= decl.resolveBinding();				} else if (fDestination instanceof AnonymousClassDeclaration) {					final AnonymousClassDeclaration decl= (AnonymousClassDeclaration) fDestination;					type= decl.resolveBinding();				}				IMethodBinding method= null;				final BodyDeclaration enclosing= fAnalyzer.getEnclosingBodyDeclaration();				if (enclosing instanceof MethodDeclaration) {					final MethodDeclaration node= (MethodDeclaration) enclosing;					method= node.resolveBinding();				}				return new JavaRefactoringDescriptor(ID_EXTRACT_METHOD, project, Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_descriptor_description, new String[] {getSignature(), method != null ? BindingLabelProvider.getBindingLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED) : '{' + JavaElementLabels.ELLIPSIS_STRING + '}', BindingLabelProvider.getBindingLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)}), getComment(), arguments, RefactoringDescriptor.STRUCTURAL_CHANGE);			}		};		result.setSaveMode(TextFileChange.KEEP_SAVE_STATE);			MultiTextEdit root= new MultiTextEdit();		result.setEdit(root);		// This is cheap since the compilation unit is already open in a editor.		IPath path= ((IFile)WorkingCopyUtil.getOriginal(fCUnit).getResource()).getFullPath();		ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager();		try {			bufferManager.connect(path, new SubProgressMonitor(pm, 1));			fDocument= bufferManager.getTextFileBuffer(path).getDocument();						ASTNode[] selectedNodes= fAnalyzer.getSelectedNodes();			fRewriter.setTargetSourceRangeComputer(new SelectionAwareSourceRangeComputer(selectedNodes,				fDocument, fSelectionStart, fSelectionLength));						TextEditGroup substituteDesc= new TextEditGroup(Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_substitute_with_call, fMethodName)); 			result.addTextEditGroup(substituteDesc);						MethodDeclaration mm= createNewMethod(fMethodName, true, selectedNodes, fDocument.getLineDelimiter(0), substituteDesc);			TextEditGroup insertDesc= new TextEditGroup(Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_add_method, fMethodName)); 			result.addTextEditGroup(insertDesc);						if (fDestination == fDestinations[0]) {				ChildListPropertyDescriptor descriptor= (ChildListPropertyDescriptor)declaration.getLocationInParent();				ListRewrite container= fRewriter.getListRewrite(declaration.getParent(), descriptor);				container.insertAfter(mm, declaration, insertDesc);			} else {				BodyDeclarationRewrite container= BodyDeclarationRewrite.create(fRewriter, fDestination);				container.insert(mm, insertDesc);			}						replaceDuplicates(result);					if (fImportRewriter.hasRecordedChanges()) {				TextEdit edit= fImportRewriter.rewriteImports(null);				root.addChild(edit);				result.addTextEditGroup(new TextEditGroup(					RefactoringCoreMessages.ExtractMethodRefactoring_organize_imports, 					new TextEdit[] {edit}				));			}			root.addChild(fRewriter.rewriteAST(fDocument, fCUnit.getJavaProject().getOptions(true)));		} catch (BadLocationException e) {			throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR,				e.getMessage(), e));		} finally {			bufferManager.disconnect(path, new SubProgressMonitor(pm, 1));			pm.done();		}		return result;	}