private InputStream delegate() throws IOException { if (delegate == null) { delegate = new StringInputStream(string, encoding); } return delegate; }
protected InputStream getAsStream(String model) { return new StringInputStream(model); }
protected InputStream getAsStream(String model) { return new StringInputStream(model); }
protected InputStream getAsStream(String model) { return new StringInputStream(model); }
protected InputStream getAsStream(CharSequence text) { return new StringInputStream(text == null ? "" : text.toString()); }
protected InputStream getAsStream(CharSequence text) { return new StringInputStream(text.toString()); }
public void addModel(String uri, String content) { models.put(URI.createURI(uri), new StringInputStream(content)); }
protected StringInputStream getInputStream(String contentsAsString, String encoding) { try { return new StringInputStream(contentsAsString, encoding); } catch (UnsupportedEncodingException e) { throw new RuntimeIOException(e); } }
/** * @since 2.4 */ public InputStream readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException { String name = getFileName(fileName, outputCfgName); Object contents = files.get(name); if (contents == null) throw new RuntimeIOException("File not found: " + name); if (contents instanceof byte[]) return new ByteArrayInputStream((byte[]) contents); if (contents instanceof CharSequence) return new StringInputStream(contents.toString()); throw new RuntimeIOException("Unknown File Data Type: " + contents.getClass() + " File: " + name); }
protected XtextResource createResource(String content) { XtextResource result = this.resourceProvider.createResource(); try { result.load(new StringInputStream(content, result.getEncoding()), Collections.emptyMap()); } catch (Exception e) { throw new RuntimeException(e); } return result; }
/** Format the code in the given resource. * * @param resource the resource of the code to format. */ public void format(XtextResource resource) { assert resource != null; final String result = formatResource(resource); // Write back to the resource try (StringInputStream stringInputStream = new StringInputStream(result)) { resource.load(stringInputStream, Collections.emptyMap()); } catch (Exception exception) { throw Exceptions.sneakyThrow(exception); } }
/** Format the code in the given region. * * @param resource the resource to format. * @param offset the offset of the text to format. * @param length the length of the text. */ public void formatRegion(XtextResource resource, int offset, int length) { assert resource != null; assert offset >= 0; assert length >= 0; final String result = formatResourceRegion(resource, offset, length); // Write back to the resource try (StringInputStream stringInputStream = new StringInputStream(result)) { resource.load(stringInputStream, Collections.emptyMap()); } catch (Exception exception) { throw Exceptions.sneakyThrow(exception); } }
public InputStream createInputStream(URI uri, Map<?, ?> options) throws IOException { if (contentProvider.hasContent(uri)) { return new StringInputStream(contentProvider.getContent(uri)); } return delegate.createInputStream(uri, options); }
@Override protected InputStream getInitialContents() { final StringBuilder content = new StringBuilder(); final IPath folderInWorkspace = getContainerFullPath(); final IPath packagePath = determinePackageName(folderInWorkspace); if (packagePath != null && packagePath.segmentCount() > 0) { content.append(this.grammarAccess.getPackageKeyword() + " "); //$NON-NLS-1$ final StringBuilder packageName = new StringBuilder(); packageName.append(packagePath.segment(0)); for (int i = 1; i < packagePath.segmentCount(); ++i) { packageName.append(this.grammarAccess.getFullStopKeyword()); packageName.append(packagePath.segment(i)); } content.append(this.converter.getQualifiedNameValueConverter().toString(packageName.toString())); content.append("\n"); //$NON-NLS-1$ } return new StringInputStream(content.toString()); }
public void reparse(String newContent) throws IOException { try { isUpdating = true; clearInternalState(); doLoad(new StringInputStream(newContent, getEncoding()), null); setModified(false); } finally { isUpdating = false; } }
@Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { create(file.getParent()); file.delete(true, monitor()); file.create(new StringInputStream(s), true, monitor()); }
@Override public void processInput(String input, DeltaScenarioProcessor tester) throws Exception { XtextResource resource = tester.get(XtextResource.class); resource.setURI(URI.createURI("dummy.uri")); try { resource.load(new StringInputStream(input, "UTF-8"), Collections.singletonMap(XtextResource.OPTION_ENCODING, "UTF-8")); } catch (Exception e) { Assert.fail(e.getMessage()); } ICompositeNode rootNode = resource.getParseResult().getRootNode(); for(ILeafNode token: rootNode.getLeafNodes()) { int start = token.getTotalOffset(); int length = token.getTotalLength(); if (length > 1 && length != 3) { tester.processFile(input, input, start, length, ""); } } } },
@Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { create(file.getParent()); file.delete(true, monitor()); file.create(new StringInputStream(s), true, monitor()); }
protected ContentAssistProcessorTestBuilder applyProposal(ICompletionProposal proposal) throws Exception { final XtextResource xtextResource = loadHelper.getResourceFor(new StringInputStream(Strings.emptyIfNull(model))); IXtextDocument document = getDocument(xtextResource, model); proposal.apply(document); ContentAssistProcessorTestBuilder reset = reset(); return reset.append(document.get()); }
public <Result> Result useTemporaryResource( ResourceSet resourceSet, Grammar language, AbstractRule rootRule, String content, IUnitOfWork<Result, XtextResource> runnable) { XtextResource resource = languageRegistry.createTemporaryResourceIn(language, resourceSet); if (rootRule != null) PartialParser.assignRootRule(resource, (ParserRule) rootRule); try { resource.load(new StringInputStream(content, resource.getEncoding()), null); return runnable.exec(resource); } catch(Exception e) { throw new RuntimeException(e); } finally { if (resource != null) { if (resource.isLoaded()) resource.unload(); resourceSet.getResources().remove(resource); } } }