int pos= getIndex(input);
int pos= getIndex(root, input, list);
	public void run(IAction action) {				String errorTitle= CompareMessages.getString("AddFromHistory.title"); //$NON-NLS-1$		String errorMessage= CompareMessages.getString("AddFromHistory.internalErrorMessage"); //$NON-NLS-1$				Shell shell= JavaPlugin.getActiveWorkbenchShell();		// shell can be null; as a result error dialogs won't be parented				ICompilationUnit cu= null;		IParent parent= null;		IMember input= null;				// analyse selection		ISelection selection= getSelection();		if (selection.isEmpty()) {			// no selection: we try to use the editor's input			if (fEditor != null) {				IEditorInput editorInput= fEditor.getEditorInput();				IWorkingCopyManager manager= JavaPlugin.getDefault().getWorkingCopyManager();				if (manager != null) {					cu= manager.getWorkingCopy(editorInput);					parent= cu;				}			}		} else {			input= getEditionElement(selection);			if (input != null) {				cu= input.getCompilationUnit();							if (input instanceof IParent) {					parent= (IParent)input;					input= null;				} else {					IJavaElement parentElement= input.getParent();					if (parentElement instanceof IParent)						parent= (IParent)parentElement;				}			} else {				if (selection instanceof IStructuredSelection) {					Object o= ((IStructuredSelection)selection).getFirstElement();					if (o instanceof ICompilationUnit) {						cu= (ICompilationUnit) o;						parent= cu;					}				}			}		}				if (parent == null || cu == null) {			String invalidSelectionMessage= CompareMessages.getString("AddFromHistory.invalidSelectionMessage"); //$NON-NLS-1$			MessageDialog.openInformation(shell, errorTitle, invalidSelectionMessage);			return;		}				IFile file= getFile(parent);		if (file == null) {			MessageDialog.openError(shell, errorTitle, errorMessage);			return;		}						boolean inEditor= beingEdited(file);		if (inEditor) {			parent= (IParent) getWorkingCopy((IJavaElement)parent);			if (input != null)				input= (IMember) getWorkingCopy(input);		}		// get a TextBuffer where to insert the text		TextBuffer buffer= null;		try {			buffer= TextBuffer.acquire(file);					// configure EditionSelectionDialog and let user select an edition			ITypedElement target= new JavaTextBufferNode(buffer, inEditor);			ITypedElement[] editions= buildEditions(target, file);														ResourceBundle bundle= ResourceBundle.getBundle(BUNDLE_NAME);			EditionSelectionDialog d= new EditionSelectionDialog(shell, bundle);			d.setAddMode(true);			d.setHelpContextId(IJavaHelpContextIds.ADD_ELEMENT_FROM_HISTORY_DIALOG);			ITypedElement selected= d.selectEdition(target, editions, parent);			if (selected == null)				return;	// user cancel											ICompilationUnit cu2= cu;			if (parent instanceof IMember)				cu2= ((IMember)parent).getCompilationUnit();						CompilationUnit root= AST.parsePartialCompilationUnit(cu2, 0, false);						ASTRewrite rewriter= new ASTRewrite(root);						List list= getContainerList(parent, root);			if (list == null) {				MessageDialog.openError(shell, errorTitle, errorMessage);				return;								}						int pos= getIndex(input);										ITypedElement[] results= d.getSelection();			for (int i= 0; i < results.length; i++) {				ITypedElement ti= results[i];				if (!(ti instanceof IStreamContentAccessor))					continue;												InputStream is= ((IStreamContentAccessor)ti).getContents();				String content= trimTextBlock(is, buffer.getLineDelimiter());				if (content == null) {					MessageDialog.openError(shell, errorTitle, errorMessage);					return;				}								ASTNode n= rewriter.createPlaceholder(content, getPlaceHolderType(parent, content));				if (pos < 0 && pos <= list.size())					list.add(n);				else					list.add(pos, n);				rewriter.markAsInserted(n);			}						applyChanges(rewriter, buffer, shell, inEditor);	 	} catch(InvocationTargetException ex) {			ExceptionHandler.handle(ex, shell, errorTitle, errorMessage);					} catch(InterruptedException ex) {			// shouldn't be called because is not cancable			Assert.isTrue(false);					} catch(CoreException ex) {			ExceptionHandler.handle(ex, shell, errorTitle, errorMessage);		} finally {			if (buffer != null)				TextBuffer.release(buffer);		}	}