Search in sources :

Example 76 with XtextResourceSet

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

the class AbstractSmokeTest method createResource.

protected LazyLinkingResource createResource(final String model) throws IOException {
    if (logger.isTraceEnabled()) {
        logger.trace("createResource: " + model);
    }
    XtextResourceSet set = getResourceSet();
    typeProviderFactory.findOrCreateTypeProvider(set);
    LazyLinkingResource resource = (LazyLinkingResource) resourceFactory.createResource(URI.createURI("Test.xtend"));
    set.getResources().add(resource);
    resource.load(new StringInputStream(model), null);
    resource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
    return resource;
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource)

Example 77 with XtextResourceSet

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

the class AbstractXtendTestCase method getResourceSet.

protected XtextResourceSet getResourceSet() {
    XtextResourceSet set = resourceSetProvider.get();
    set.setClasspathURIContext(getClass().getClassLoader());
    return set;
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Example 78 with XtextResourceSet

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

the class AbstractXtendTestCase method files.

protected Iterable<XtendFile> files(boolean validate, String... contents) throws Exception {
    XtextResourceSet set = getResourceSet();
    List<XtendFile> result = newArrayList();
    for (String string : contents) {
        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());
    }
    for (Resource resource : new ArrayList<Resource>(set.getResources())) {
        XtendFile file = (XtendFile) resource.getContents().get(0);
        result.add(file);
    }
    if (validate) {
        for (XtendFile file : result) {
            List<Issue> issues = ((XtextResource) file.eResource()).getResourceServiceProvider().getResourceValidator().validate(file.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
            assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
        }
    }
    return result;
}
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) ArrayList(java.util.ArrayList) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 79 with XtextResourceSet

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

the class ConvertToArrayBenchmark method setUp.

@Override
protected void setUp() throws Exception {
    Injector injector = new XbaseStandaloneSetup().createInjectorAndDoEMFRegistration();
    XtextResourceSet resourceSet = new XtextResourceSet();
    ClassLoader loader = getClass().getClassLoader();
    resourceSet.setClasspathURIContext(loader);
    ClasspathTypeProvider typeProvider = new ClasspathTypeProvider(loader, resourceSet, indexedAccess, null);
    CommonTypeComputationServices services = injector.getInstance(CommonTypeComputationServices.class);
    StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, resourceSet);
    typeReference = type.getReference(typeProvider, owner);
    EcoreUtil.resolveAll(resourceSet);
}
Also used : XbaseStandaloneSetup(org.eclipse.xtext.xbase.XbaseStandaloneSetup) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) CommonTypeComputationServices(org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices) ClasspathTypeProvider(org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 80 with XtextResourceSet

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

the class ParameterizedTypeReferenceBenchmark method setUp.

@Override
protected void setUp() throws Exception {
    Injector injector = new XbaseStandaloneSetup().createInjectorAndDoEMFRegistration();
    XtextResourceSet resourceSet = new XtextResourceSet();
    ClassLoader loader = getClass().getClassLoader();
    resourceSet.setClasspathURIContext(loader);
    ClasspathTypeProvider typeProvider = new ClasspathTypeProvider(loader, resourceSet, indexedAccess, null);
    CommonTypeComputationServices services = injector.getInstance(CommonTypeComputationServices.class);
    StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, resourceSet);
    typeReference = type.getReference(typeProvider, owner);
    EcoreUtil.resolveAll(resourceSet);
}
Also used : XbaseStandaloneSetup(org.eclipse.xtext.xbase.XbaseStandaloneSetup) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) CommonTypeComputationServices(org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices) ClasspathTypeProvider(org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

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