use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class SimpleEditorTest method testOpenFileReadModifyReadSecond.
@Test
public void testOpenFileReadModifyReadSecond() throws Exception {
IFile file = createFile("foo/z.testlanguage", "/* multi line */\n" + "stuff foo\n" + "stuff bar\n" + "// end");
XtextEditor openEditor = openEditor(file);
assertNotNull(openEditor);
XtextDocument document = (XtextDocument) openEditor.getDocument();
Display.getDefault().readAndDispatch();
document.readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource resource) throws Exception {
assertNotNull(resource);
EList<EObject> contents = resource.getContents();
EObject object = contents.get(0);
assertEquals(2, object.eContents().size());
}
});
document.replace(36, 0, "a");
document.readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource resource) throws Exception {
assertNotNull(resource);
EList<EObject> contents = resource.getContents();
EObject object = contents.get(0);
assertEquals(2, object.eContents().size());
EObject object2 = object.eContents().get(0);
assertEquals("foo", object2.eGet(object2.eClass().getEStructuralFeature("name")));
EObject object3 = object.eContents().get(1);
Object name = object3.eGet(object3.eClass().getEStructuralFeature("name"));
assertEquals("bara", name);
}
});
openEditor.doSave(null);
openEditor.close(true);
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class ValidationJobSchedulerTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
referenceDescriptions = Lists.newArrayList();
dirtyStateManager = new DirtyStateManager();
testMe = new ValidationJobScheduler();
testMe.setDirtyStateManager(dirtyStateManager);
testMe.setDescriptionUtils(new DescriptionUtils());
testMe.setResourceDescriptions(this);
testMe.setResourceDescriptionManager(new DefaultResourceDescriptionManager());
DocumentTokenSource nullSource = new DocumentTokenSource() {
@Override
protected IRegion computeDamageRegion(DocumentEvent e) {
return new Region(0, 0);
}
};
document = new XtextDocument(nullSource, null, outdatedStateManager, operationCanceledManager) {
@Override
public URI getResourceURI() {
return documentURI;
}
@Override
public void checkAndUpdateAnnotations() {
validationScheduled = true;
}
};
documentResource = new TestableDocumentResource();
targetResource = new AbstractResourceDescription() {
@Override
public URI getURI() {
return targetURI;
}
@Override
public Iterable<IReferenceDescription> getReferenceDescriptions() {
throw new UnsupportedOperationException();
}
@Override
public Iterable<QualifiedName> getImportedNames() {
throw new UnsupportedOperationException();
}
@Override
protected List<IEObjectDescription> computeExportedObjects() {
if (documentResource.importedName == null)
throw new UnsupportedOperationException();
return Collections.emptyList();
}
};
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class LexerTokenAndCharacterPairAwareStrategy method findWord.
@Override
protected IRegion findWord(IDocument document, int offset) {
if (document instanceof XtextDocument) {
Iterator<ILexerTokenRegion> tokenIterator = ((XtextDocument) document).getTokens().iterator();
ILexerTokenRegion leadingToken = null;
ILexerTokenRegion trailingToken = null;
while (tokenIterator.hasNext()) {
ILexerTokenRegion token = tokenIterator.next();
if (token.getOffset() <= offset && token.getOffset() + token.getLength() >= offset) {
if (leadingToken != null)
trailingToken = token;
else
leadingToken = token;
}
if (token.getOffset() > offset)
break;
}
if (leadingToken != null) {
try {
if (leadingToken.getLength() > 1 && (trailingToken == null || !Character.isLetter(document.getChar(trailingToken.getOffset())))) {
return new Region(leadingToken.getOffset(), leadingToken.getLength());
} else if (trailingToken != null) {
return new Region(trailingToken.getOffset(), trailingToken.getLength());
}
} catch (BadLocationException ignore) {
}
}
}
return super.findWord(document, offset);
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class EmbeddedEditorModelAccess method updateModel.
public void updateModel(String model, final IUnitOfWork<ITextRegion, XtextResource> editablePartSelector) {
XtextDocument document = (XtextDocument) this.viewer.getDocument();
this.viewer.setRedraw(false);
this.viewer.getUndoManager().disconnect();
document.set(model);
ITextRegion textRegion = document.readOnly(editablePartSelector);
if (textRegion == null) {
this.viewer.resetVisibleRegion();
} else {
this.viewer.setVisibleRegion(textRegion.getOffset(), textRegion.getLength());
}
this.viewer.getUndoManager().connect(this.viewer);
this.viewer.setRedraw(true);
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class XtextGrammarQuickfixProviderTest method validateInEditor.
private void validateInEditor(IXtextDocument document) {
Job validationJob = ((XtextDocument) document).getValidationJob();
validationJob.schedule();
boolean wasInterrupted = false;
do {
try {
Job.getJobManager().join(ValidationJob.XTEXT_VALIDATION_FAMILY, new NullProgressMonitor());
wasInterrupted = false;
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (InterruptedException e) {
wasInterrupted = true;
}
} while (wasInterrupted);
}
Aggregations