public void addLoadOption(Object key, Object value) { getLoadOptions().put(key, value); }
public void removeLoadOption(Object key) { getLoadOptions().remove(key); }
private XtextResourceSet newResourceSetWithUTF8Encoding() { XtextResourceSet result = resourceSetProvider.get(); result.setClasspathURIContext(classpathUriContext); result.getLoadOptions().put(XtextResource.OPTION_ENCODING, StandardCharsets.UTF_8.name()); return result; }
if (entry.getName().endsWith(".mapping")) { Resource mappingResource = resourceSet.createResource(URI.createURI("fake:/" + entry.getName())); mappingResource.load(new ByteArrayInputStream(copyStream(zis, entry)),resourceSet.getLoadOptions()); } else { Resource resource = resourceSet.createResource(URI.createURI("fake:/" + entry.getName())); resource.load(new ByteArrayInputStream(copyStream(zis, entry)), resourceSet.getLoadOptions());
public Model extract(final String modelName) { FunctionblockPackage.eINSTANCE.eClass(); InformationModelPackage.eINSTANCE.eClass(); ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(this.zipFile)); ZipEntry entry = null; FunctionblockStandaloneSetup.doSetup(); Injector injector = new InformationModelStandaloneSetup().createInjectorAndDoEMFRegistration(); XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); Resource infoModelResource = null; try { while ((entry = zis.getNextEntry()) != null) { Resource resource = resourceSet.createResource(URI.createURI("fake:/" + entry.getName())); resource.load(new ByteArrayInputStream(copyStream(zis, entry)), resourceSet.getLoadOptions()); if (((Model) resource.getContents().get(0)).getName().equals(modelName)) { infoModelResource = resource; } } } catch (Exception ex) { ex.printStackTrace(); } EcoreUtil2.resolveAll(resourceSet); return (Model)infoModelResource.getContents().get(0); }
private XExpression parseScriptIntoXTextEObject(String scriptAsString) throws ScriptParsingException { XtextResourceSet resourceSet = getResourceSet(); Resource resource = resourceSet.createResource(computeUnusedUri(resourceSet)); // IS-A XtextResource try { resource.load(new StringInputStream(scriptAsString, StandardCharsets.UTF_8.name()), resourceSet.getLoadOptions()); } catch (IOException e) { throw new ScriptParsingException( "Unexpected IOException; from close() of a String-based ByteArrayInputStream, no real I/O; how is that possible???", scriptAsString, e); } List<Diagnostic> errors = resource.getErrors(); if (errors.size() != 0) { throw new ScriptParsingException("Failed to parse expression (due to managed SyntaxError/s)", scriptAsString).addDiagnosticErrors(errors); } EList<EObject> contents = resource.getContents(); if (!contents.isEmpty()) { Iterable<Issue> validationErrors = getValidationErrors(contents.get(0)); if (!validationErrors.iterator().hasNext()) { return (XExpression) contents.get(0); } else { throw new ScriptParsingException("Failed to parse expression (due to managed ValidationError/s)", scriptAsString).addValidationIssues(validationErrors); } } else { return null; } }
/** * creates a fresh resource set with the given resources * * @param resources - pairs of file names and their contents * @return a ResourceSet, containing the given resources. * @throws IOException if the resource loading fails */ public ResourceSet resourceSet(@SuppressWarnings("unchecked") Pair<String,? extends CharSequence> ...resources ) throws IOException { XtextResourceSet result = newResourceSetWithUTF8Encoding(); FileProjectConfig projectConfig = new FileProjectConfig(new File(workspaceRoot,PROJECT_NAME), PROJECT_NAME); projectConfig.addSourceFolder("src"); ProjectConfigAdapter.install(result, projectConfig); for (Pair<String, ? extends CharSequence> entry : resources) { URI uri = copyToWorkspace(getSourceFolderPath()+"/"+entry.getKey(), entry.getValue()); Resource resource = result.createResource(uri); if (resource == null) throw new IllegalStateException("Couldn't create resource for URI "+uri+". Resource.Factory not registered?"); resource.load(result.getLoadOptions()); } return result; }
final ProjectManager projectManager = workspaceManager.getProjectManager(uri); final XtextResourceSet resourceSet = projectManager.createNewResourceSet(projectManager.getIndexState().getResourceDescriptions()); resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.LIVE_SCOPE, Boolean.valueOf(true)); final int offset = document.getOffSet(renameParams.getPosition()); final WorkspaceEdit workspaceEdit = new WorkspaceEdit();