Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2013 itemis AG ( and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at /
  package org.eclipse.xtext.ui.refactoring.impl;
 import  org.eclipse.core.filebuffers.ITextFileBuffer;
 import  org.eclipse.core.runtime.CoreException;
 import  org.eclipse.core.runtime.IProgressMonitor;
 import  org.eclipse.jface.text.IDocument;
 import  org.eclipse.jface.text.IDocumentExtension4;
 import  org.eclipse.ltk.core.refactoring.Change;
 import  org.eclipse.ltk.core.refactoring.DocumentChange;
 import  org.eclipse.ltk.core.refactoring.RefactoringStatus;
 import  org.eclipse.ltk.core.refactoring.TextChange;
 import  org.eclipse.text.edits.UndoEdit;
 import  org.eclipse.ui.texteditor.ITextEditor;
Copied and adapted DocumentChange. The original implementation relies on the ITextFileBuffer API. Xtext doesn't and the fallback implementation in DocumentChange will always yield an invalid thread access error. In addition, we need a way to combine editor saving with document changes, as there is no way to tell JDT to save our editors after a combined Xtext/JDT refactoring.

Jan Koehnlein - Initial contribution and API
 public class EditorDocumentChange extends TextChange {
 	private long modificationStamp = -1l;
 	private boolean doSave;
 	private ITextEditor editor;
 	private IDocument document;
 	public EditorDocumentChange(String name, ITextEditor editorboolean doSave) {
 		this. = editor;
 		this. = doSave;
 		this. = editor.getDocumentProvider().getDocument(editor.getEditorInput());
 	public Object getModifiedElement() {
 		return ;
 	public ITextEditor getEditor() {
 		return ;
 	public boolean isDoSave() {
 		return ;
 	public void setDoSave(boolean doSave) {
 		this. = doSave;
 	public void initializeValidationData(IProgressMonitor pm) {
 		if ( instanceof IDocumentExtension4)
 			 = ((IDocumentExtension4) ).getModificationStamp();
 	public RefactoringStatus isValid(IProgressMonitor pmthrows CoreException {
 		RefactoringStatus refactoringStatus = new RefactoringStatus();
 		if( instanceof IDocumentExtension4 
 				&& ((IDocumentExtension4) ).getModificationStamp() != )
 			refactoringStatus.addFatalError("The content of the document has changed.");
 		return refactoringStatus;
 	protected IDocument acquireDocument(IProgressMonitor pmthrows CoreException {
 		return ;
 	protected void commit(IDocument document, IProgressMonitor pmthrows CoreException {
 	protected void releaseDocument(IDocument document, IProgressMonitor pmthrows CoreException {
 	public Change perform(final IProgressMonitor pmthrows CoreException {
		return new DisplayRunnableWithResult<Change>() {
			protected Change run() throws Exception {
				return EditorDocumentChange.super.perform(pm);
	protected Change createUndoChange(UndoEdit edit) {
		return new EditorDocumentUndoChange(getName(), edit);
New to GrepCode? Check out our FAQ X