use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class DefaultResourceDescription2Test method testBrokenLink.
@Test
public void testBrokenLink() 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 Baz"), null);
EcoreUtil.resolveAll(res2);
Iterable<QualifiedName> names = res2.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res2).getImportedNames();
assertEquals(QualifiedName.create("baz"), names.iterator().next());
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class DefaultResourceDescription2Test method testClasspathURIIsNormalized.
@Test
public void testClasspathURIIsNormalized() {
XtextResourceSet xtextResourceSet = new XtextResourceSet();
xtextResourceSet.setClasspathURIContext(this);
URI classpathURI = URI.createURI("classpath:/org/eclipse/xtext/XtextGrammarTestLanguage.ecore");
Resource resource = xtextResourceSet.getResource(classpathURI, true);
IResourceDescription ecoreResourceDescription = createResourceDescription(resource);
assertNotSame(classpathURI, ecoreResourceDescription.getURI());
assertEquals(xtextResourceSet.getURIConverter().normalize(classpathURI), ecoreResourceDescription.getURI());
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class Xtext2EcoreTransformerTest method testBug_266807.
@Test
public void testBug_266807() throws Exception {
final XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class);
rs.setClasspathURIContext(this.getClass());
StringConcatenation _builder = new StringConcatenation();
_builder.append("classpath:/");
String _replace = this.getClass().getPackage().getName().replace(Character.valueOf('.').charValue(), Character.valueOf('/').charValue());
_builder.append(_replace);
_builder.append("/Test.xtext");
Resource _createResource = rs.createResource(URI.createURI(_builder.toString()), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
final XtextResource resource = ((XtextResource) _createResource);
resource.load(null);
EList<Resource.Diagnostic> _errors = resource.getErrors();
for (final Resource.Diagnostic d : _errors) {
Assert.fail(d.getMessage());
}
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class AbstractGeneratorFragmentTests method doGetResource.
@Override
public XtextResource doGetResource(final InputStream in, final URI uri) throws Exception {
final XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class);
rs.setClasspathURIContext(this.getClass());
Resource _createResource = this.getResourceFactory().createResource(uri);
final XtextResource resource = ((XtextResource) _createResource);
rs.getResources().add(resource);
resource.load(in, null);
return resource;
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class EMFGeneratorFragment2 method registerUsedGenModel.
private void registerUsedGenModel(final URIConverter converter, final Grammar grammar) {
final URI genModelUri = this.getGenModelUri(grammar);
boolean _exists = converter.exists(genModelUri, null);
if (_exists) {
try {
GenModelHelper _genModelHelper = new GenModelHelper();
XtextResourceSet _xtextResourceSet = new XtextResourceSet();
_genModelHelper.registerGenModel(_xtextResourceSet, genModelUri);
} catch (final Throwable _t) {
if (_t instanceof Exception) {
final Exception e = (Exception) _t;
EMFGeneratorFragment2.LOG.error("Failed to register GenModel", e);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
}
Aggregations