Search in sources :

Example 51 with XtextResourceSet

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());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) QualifiedName(org.eclipse.xtext.naming.QualifiedName) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 52 with XtextResourceSet

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());
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 53 with XtextResourceSet

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());
    }
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) TransformationDiagnostic(org.eclipse.xtext.xtext.ecoreInference.TransformationDiagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 54 with XtextResourceSet

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;
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 55 with XtextResourceSet

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);
            }
        }
    }
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) GenModelHelper(org.eclipse.emf.mwe.utils.GenModelHelper) URI(org.eclipse.emf.common.util.URI)

Aggregations

XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)123 Resource (org.eclipse.emf.ecore.resource.Resource)72 XtextResource (org.eclipse.xtext.resource.XtextResource)61 Test (org.junit.Test)44 StringInputStream (org.eclipse.xtext.util.StringInputStream)36 URI (org.eclipse.emf.common.util.URI)24 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)19 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)12 EObject (org.eclipse.emf.ecore.EObject)11 File (java.io.File)10 AbstractResourceSetTest (org.eclipse.xtext.resource.AbstractResourceSetTest)10 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 Issue (org.eclipse.xtext.validation.Issue)8 Grammar (org.eclipse.xtext.Grammar)7 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)7 ResourceDescriptionsData (org.eclipse.xtext.resource.impl.ResourceDescriptionsData)7 ArrayList (java.util.ArrayList)5 ClasspathTypeProvider (org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider)5 Before (org.junit.Before)5 Injector (com.google.inject.Injector)4