Search in sources :

Example 66 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.

the class AbstractXtendTestCase method file.

protected XtendFile file(String string, boolean validate, boolean shouldBeSyntacticallyValid) throws Exception {
    XtextResourceSet set = getResourceSet();
    String fileName = getFileName(string);
    Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
    resource.load(new StringInputStream(string), null);
    if (shouldBeSyntacticallyValid) {
        assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    }
    if (validate) {
        List<Issue> issues = Lists.newArrayList(Iterables.filter(((XtextResource) resource).getResourceServiceProvider().getResourceValidator().validate(resource, CheckMode.ALL, CancelIndicator.NullImpl), new Predicate<Issue>() {

            @Override
            public boolean apply(Issue issue) {
                return issue.getSeverity() == Severity.ERROR;
            }
        }));
        assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
    }
    XtendFile file = (XtendFile) resource.getContents().get(0);
    return file;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) Issue(org.eclipse.xtext.validation.Issue) 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) Predicate(com.google.common.base.Predicate)

Example 67 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.

the class PartialParserTest method compareWithNewResource.

protected void compareWithNewResource(XtextResource resource, String model, int offset, int length, String newText, String fileName) throws IOException {
    resource.update(offset, length, newText);
    XtextResourceSet secondResourceSet = getResourceSet();
    XtextResource newResource = (XtextResource) secondResourceSet.createResource(URI.createURI(fileName));
    String newModel = new StringBuilder(model).replace(offset, offset + length, newText).toString();
    assertEquals(newModel, resource.getParseResult().getRootNode().getText());
    newResource.load(new StringInputStream(newModel), null);
    assertEquals(newResource.getContents().size(), resource.getContents().size());
    EcoreUtil.resolveAll(resource);
    EcoreUtil.resolveAll(newResource);
    for (int i = 0; i < resource.getContents().size(); i++) {
        assertEquals(EmfFormatter.objToStr(newResource.getContents().get(i)), EmfFormatter.objToStr(resource.getContents().get(i)));
    }
    assertEqualNodes(newResource, resource);
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 68 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.

the class UTF8ParserTest method file.

@Override
protected XtendFile file(String string, boolean validate) throws Exception {
    XtextResourceSet set = getResourceSet();
    String fileName = getFileName(string);
    Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
    resource.load(new StringInputStream(string, "UTF-8"), Collections.singletonMap(XtextResource.OPTION_ENCODING, "UTF-8"));
    assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    XtendFile file = (XtendFile) resource.getContents().get(0);
    return file;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) 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)

Example 69 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.

the class IndexingTest method doTestResourceDescriptionWithoutGetContents.

private void doTestResourceDescriptionWithoutGetContents(final String input) throws IOException {
    XtextResourceSet resourceSet = getResourceSet();
    new ClasspathTypeProvider(classLoader, resourceSet, null, null);
    final Wrapper<Boolean> wrapper = Wrapper.wrap(Boolean.FALSE);
    for (int i = 0; i < 10; i++) {
        DerivedStateAwareResource resource = (DerivedStateAwareResource) resourceSet.createResource(URI.createURI("Dummy" + i + ".xtend"));
        resource.setDerivedStateComputer(new IDerivedStateComputer() {

            @Override
            public void installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) {
                if (!preLinkingPhase) {
                    wrapper.set(Boolean.TRUE);
                }
                derivedStateComputer.installDerivedState(resource, preLinkingPhase);
            }

            @Override
            public void discardDerivedState(DerivedStateAwareResource resource) {
                derivedStateComputer.discardDerivedState(resource);
            }
        });
        String actualInput = input;
        if (i != 0) {
            actualInput = "import C" + (i + 1) + " " + actualInput;
            actualInput = "import C" + (i - 1) + " " + actualInput;
        }
        actualInput = String.format(actualInput, i, i + 1);
        resource.load(new StringInputStream(actualInput), null);
    }
    for (int i = 0; i < 10; i++) {
        Resource resource = resourceSet.getResources().get(i);
        for (IEObjectDescription description : resourceDescriptionManager.getResourceDescription(resource).getExportedObjects()) {
            description.getEObjectOrProxy();
        }
    }
    assertFalse(wrapper.get());
}
Also used : DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) XtextResource(org.eclipse.xtext.resource.XtextResource) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) IDerivedStateComputer(org.eclipse.xtext.resource.IDerivedStateComputer) ClasspathTypeProvider(org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Example 70 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.

the class RichStringEvaluationTest method file.

protected XtendFile file(String string, boolean validate) throws Exception {
    XtextResourceSet set = resourceSetProvider.get();
    String fileName = getFileName(string);
    Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
    resource.load(new StringInputStream(string), null);
    assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    if (validate) {
        List<Issue> issues = ((XtextResource) resource).getResourceServiceProvider().getResourceValidator().validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
        assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
    }
    XtendFile file = (XtendFile) resource.getContents().get(0);
    return file;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) Issue(org.eclipse.xtext.validation.Issue) 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) RichString(org.eclipse.xtend.core.xtend.RichString)

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