use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-eclipse by eclipse.
the class WorkspaceEncodingProviderTest method testProjectSpecificEncoding.
@Test
public void testProjectSpecificEncoding() throws CoreException {
project.setDefaultCharset("UTF-16", new NullProgressMonitor());
XtextResourceSet resourceSet = resourceSetProvider.get();
XtextResource resource = (XtextResource) resourceSet.createResource(URI.createURI("platform:/resource/WorkspaceEncodingProviderTest/test1.xtextgrammar"));
assertEquals("UTF-16", resource.getEncoding());
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-eclipse by eclipse.
the class WorkspaceEncodingProviderTest method testWorkspaceDefaultEncoding.
@Test
public void testWorkspaceDefaultEncoding() {
XtextResourceSet resourceSet = resourceSetProvider.get();
XtextResource resource = (XtextResource) resourceSet.createResource(URI.createURI("platform:/resource/WorkspaceEncodingProviderTest/test1.xtextgrammar"));
assertEquals(defaultEncoding, resource.getEncoding());
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-eclipse by eclipse.
the class Bug297909Test method testReconcileDocument.
@Test
public void testReconcileDocument() throws Exception {
Injector injector = doGetSetup().createInjectorAndDoEMFRegistration();
XtextDocument document = injector.getInstance(XtextDocument.class);
document.setValidationJob(new Job("Job") {
@Override
protected IStatus run(IProgressMonitor monitor) {
return Status.OK_STATUS;
}
});
XtextResource resource = injector.getInstance(XtextResource.class);
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.getResources().add(resource);
resource.load(new StringInputStream(""), Collections.singletonMap(XtextResource.OPTION_ENCODING, Charset.defaultCharset().name()));
document.setInput(resource);
document.set("abstract rules firstRule");
XtextDocumentReconcileStrategy strategy = injector.getInstance(XtextDocumentReconcileStrategy.class);
strategy.setDocument(document);
strategy.setResource(resource);
try {
strategy.reconcile(new ReconcilerReplaceRegion(0, document.getLength(), document.get()));
fail("Expected ParseException");
} catch (ParseException expected) {
assertTrue(expected.getMessage().contains("Make sure the EPackage has been registered"));
}
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-eclipse by eclipse.
the class HighlightingReconciler method updatePresentation.
/**
* Update the presentation.
*
* @param textPresentation
* the text presentation
* @param addedPositions
* the added positions
* @param removedPositions
* the removed positions
* @param resource
* the resource for which the positions have been computed
*/
private void updatePresentation(TextPresentation textPresentation, List<AttributedPosition> addedPositions, List<AttributedPosition> removedPositions, XtextResource resource) {
final Runnable runnable = presenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions);
if (runnable == null)
return;
final XtextResourceSet resourceSet = (XtextResourceSet) resource.getResourceSet();
final int modificationStamp = resourceSet.getModificationStamp();
Display display = getDisplay();
display.asyncExec(new Runnable() {
@Override
public void run() {
// never apply outdated highlighting
if (sourceViewer != null && modificationStamp == resourceSet.getModificationStamp())
runnable.run();
}
});
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-eclipse by eclipse.
the class AbstractIncrementalBuilderTest method newBuildRequest.
protected BuildRequest newBuildRequest(final Procedure1<? super BuildRequest> init) {
BuildRequest _buildRequest = new BuildRequest();
final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
final ResourceDescriptionsData newIndex = this.indexState.getResourceDescriptions().copy();
it.setBaseDir(this.uri(""));
XtextResourceSet _get = this.resourceSetProvider.get();
final Procedure1<XtextResourceSet> _function_1 = (XtextResourceSet it_1) -> {
it_1.getURIConverter().getURIHandlers().clear();
EList<URIHandler> _uRIHandlers = it_1.getURIConverter().getURIHandlers();
_uRIHandlers.add(this.inMemoryURIHandler);
it_1.setClasspathURIContext(AbstractIncrementalBuilderTest.class.getClassLoader());
ProjectDescription _projectDescription = new ProjectDescription();
final Procedure1<ProjectDescription> _function_2 = (ProjectDescription it_2) -> {
it_2.setName("test-project");
};
final ProjectDescription projectDescription = ObjectExtensions.<ProjectDescription>operator_doubleArrow(_projectDescription, _function_2);
projectDescription.attachToEmfObject(it_1);
Map<String, ResourceDescriptionsData> _emptyMap = CollectionLiterals.<String, ResourceDescriptionsData>emptyMap();
final ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(_emptyMap, it_1);
index.setContainer(projectDescription.getName(), newIndex);
};
XtextResourceSet _doubleArrow = ObjectExtensions.<XtextResourceSet>operator_doubleArrow(_get, _function_1);
it.setResourceSet(_doubleArrow);
it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
it.setDeletedFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
final BuildRequest.IPostValidationCallback _function_2 = (URI uri, Iterable<Issue> issues) -> {
Iterables.<Issue>addAll(this.issues, issues);
return IterableExtensions.isEmpty(issues);
};
it.setAfterValidate(_function_2);
final Procedure1<URI> _function_3 = (URI it_1) -> {
this.deleted.add(it_1);
};
it.setAfterDeleteFile(_function_3);
final Procedure2<URI, URI> _function_4 = (URI source, URI target) -> {
this.generated.put(source, target);
};
it.setAfterGenerateFile(_function_4);
Source2GeneratedMapping _copy = this.indexState.getFileMappings().copy();
IndexState _indexState = new IndexState(newIndex, _copy);
it.setState(_indexState);
};
final BuildRequest result = ObjectExtensions.<BuildRequest>operator_doubleArrow(_buildRequest, _function);
init.apply(result);
return result;
}
Aggregations