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;
}
Aggregations