use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class ContentAssistContextTestHelper method parse.
private XtextResource parse(final String doc) {
try {
String _primaryFileExtension = this.fileExtension.getPrimaryFileExtension();
String _plus = ("dummy." + _primaryFileExtension);
final URI uri = URI.createURI(_plus);
Resource _createResource = this.resFactory.createResource(uri);
final XtextResource res = ((XtextResource) _createResource);
EList<Resource> _resources = new XtextResourceSet().getResources();
_resources.add(res);
if ((this.entryPoint != null)) {
res.setEntryPoint(this.entryPoint);
}
StringInputStream _stringInputStream = new StringInputStream(doc);
res.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
this.validator.assertNoErrors(res);
return res;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class FormattingTest method doTestAPIMaintenanceLayer.
private void doTestAPIMaintenanceLayer(final FormattingService fs) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Foo{int bar} type Bar{Foo foo}");
final String model = _builder.toString();
final XtextResourceSet rs = this.rsp.get();
Resource _createResource = rs.createResource(URI.createURI("dummy.testlang"));
final XtextResource r = ((XtextResource) _createResource);
StringInputStream _stringInputStream = new StringInputStream(model);
r.load(_stringInputStream, null);
try {
Document _document = new Document(1, model);
DocumentFormattingParams _documentFormattingParams = new DocumentFormattingParams();
fs.format(_document, r, _documentFormattingParams, CancelIndicator.NullImpl);
Assert.fail("IllegalStateException expected");
} catch (final Throwable _t) {
if (_t instanceof IllegalStateException) {
final IllegalStateException e = (IllegalStateException) _t;
String _message = e.getMessage();
boolean _notEquals = (!Objects.equal(_message, "api maintenance layer broken"));
if (_notEquals) {
throw e;
}
} else {
throw Exceptions.sneakyThrow(_t);
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class AbstractLiveContainerTest method testContainerAddRemove.
@Test
public void testContainerAddRemove() throws Exception {
ResourceSet resourceSet = new XtextResourceSet();
Resource res = parse("local", resourceSet).eResource();
parse("other", resourceSet);
IResourceDescription resourceDescription = descriptionManager.getResourceDescription(res);
IResourceDescriptions resourceDescriptions = descriptionsProvider.getResourceDescriptions(res);
List<IContainer> containers = containerManager.getVisibleContainers(resourceDescription, resourceDescriptions);
assertEquals(1, containers.size());
IContainer container = containers.get(0);
assertEquals("local, other", format(container.getExportedObjects()));
Resource foo = parse("foo", resourceSet).eResource();
assertEquals("foo, local, other", format(container.getExportedObjects()));
resourceSet.getResources().remove(foo);
assertEquals("local, other", format(container.getExportedObjects()));
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class AbstractLiveContainerTest method testNonNormalizedURIs.
@Test
public // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=382555
void testNonNormalizedURIs() throws Exception {
ResourceSet resourceSet = new XtextResourceSet();
parser.parse("B", URI.createURI("a." + parser.fileExtension), resourceSet);
parser.parse("B", URI.createURI("b." + parser.fileExtension), resourceSet);
IResourceDescriptions index = descriptionsProvider.getResourceDescriptions(resourceSet);
IResourceDescription rd = index.getResourceDescription(URI.createURI("a." + parser.fileExtension));
List<IContainer> containers = containerManager.getVisibleContainers(rd, index);
List<IEObjectDescription> objects = Lists.newArrayList();
EClass type = (EClass) grammarAccess.getGrammar().getRules().get(0).getType().getClassifier();
for (IContainer container : containers) Iterables.addAll(objects, container.getExportedObjects(type, QualifiedName.create("B"), false));
assertEquals(2, objects.size());
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class DefaultResourceDescription2Test method testValidExternalLink.
@Test
public void testValidExternalLink() throws Exception {
XtextResourceSet rs = get(XtextResourceSet.class);
Resource res1 = rs.createResource(URI.createURI("foo.langatestlanguage"));
res1.load(new StringInputStream("type Foo"), null);
XtextResource res2 = (XtextResource) rs.createResource(URI.createURI("bar.langatestlanguage"));
res2.load(new StringInputStream("import 'foo.langatestlanguage'" + "type Bar extends Foo"), null);
EcoreUtil.resolveAll(res2);
Iterable<QualifiedName> names = res2.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res2).getImportedNames();
assertEquals(QualifiedName.create("foo"), names.iterator().next());
}
Aggregations