Search in sources :

Example 86 with XtextResourceSet

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);
    }
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) 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) URI(org.eclipse.emf.common.util.URI)

Example 87 with XtextResourceSet

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);
    }
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) DocumentFormattingParams(org.eclipse.lsp4j.DocumentFormattingParams) 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) XtextResource(org.eclipse.xtext.resource.XtextResource) Document(org.eclipse.xtext.ide.server.Document)

Example 88 with XtextResourceSet

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()));
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IContainer(org.eclipse.xtext.resource.IContainer) Test(org.junit.Test)

Example 89 with XtextResourceSet

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());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IContainer(org.eclipse.xtext.resource.IContainer) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 90 with XtextResourceSet

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());
}
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)

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