Search in sources :

Example 1 with Creates

use of org.eclipse.xpect.state.Creates in project n4js by eclipse.

the class N4IDEXpectFileSetup method createThisResource.

/**
 * Creates {@link N4JSResource} in new {@link ResourceSet}. Created resource has uri of processed xt file and its
 * context. During creation resource factory is obtained dynamically to preserve bindings created by XPECT (see
 * {@link org.eclipse.xpect.xtext.lib.tests.ValidationTestModuleSetup#configure})
 */
@Creates(ThisResource.class)
public XtextResource createThisResource() throws IOException, CoreException {
    Entry<IFile, IProject> file2project = findTestResources();
    IFile xpectFile = file2project.getKey();
    IProject userProject = file2project.getValue();
    ResourceSet resourceSet = resourceSetProvider.get(userProject);
    URI xpectFilePlatformURI = URI.createPlatformResourceURI(xpectFile.getFullPath().toString(), ENCODE_PLATFORM_RESOURCE_URIS);
    Injector injector = IXtInjectorProvider.INSTANCE.getInjector(ctx.get(XpectJavaModel.class), xpectFilePlatformURI);
    Resource resource = injector.getInstance(IResourceFactory.class).createResource(xpectFilePlatformURI);
    resourceSet.getResources().add(resource);
    InputStream input = xpectFile.getContents();
    try {
        resource.load(input, null);
    } finally {
        if (input != null)
            input.close();
    }
    return (XtextResource) resource;
}
Also used : IFile(org.eclipse.core.resources.IFile) Injector(com.google.inject.Injector) XpectJavaModel(org.eclipse.xpect.XpectJavaModel) InputStream(java.io.InputStream) ThisResource(org.eclipse.xpect.xtext.lib.setup.ThisResource) XtextResource(org.eclipse.xtext.resource.XtextResource) N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) IResourceFactory(org.eclipse.xtext.resource.IResourceFactory) IProject(org.eclipse.core.resources.IProject) Creates(org.eclipse.xpect.state.Creates)

Aggregations

Injector (com.google.inject.Injector)1 InputStream (java.io.InputStream)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 N4JSResource (org.eclipse.n4js.resource.N4JSResource)1 XpectJavaModel (org.eclipse.xpect.XpectJavaModel)1 Creates (org.eclipse.xpect.state.Creates)1 ThisResource (org.eclipse.xpect.xtext.lib.setup.ThisResource)1 IResourceFactory (org.eclipse.xtext.resource.IResourceFactory)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1