@Override public boolean hasCharacters(Object impl) { com.oracle.truffle.api.source.Source source = (com.oracle.truffle.api.source.Source) impl; return source.hasCharacters(); }
@Override public boolean hasCharacters() { return key.base.hasCharacters(); }
Source resolve(Source source) { if (source.hasCharacters() || source.hasBytes()) { return source; } Source resolved; synchronized (resolvedMap) { resolved = resolvedMap.getOrDefault(source, source); if (resolved == source) { // not resolved resolved = doResolve(source); resolvedMap.put(source, resolved); } } return resolved; }
if (source.hasCharacters()) { b.append(", characters=").append(getCharacters().toString().replaceAll("\\n", "\\\\n")); } else {
if (hasCharacters()) { section = new SourceSectionLoaded(this, charIndex, length); assert assertValid(section);
if (hasBytes() || !hasCharacters()) { throw new UnsupportedOperationException("Operation is only enabled for character based sources."); } else if (startColumn <= 0) { throw new IllegalArgumentException("startColumn < 1"); } else if (hasCharacters() && length < 0) { throw new IllegalArgumentException("length < 0");
/** * Gets the number of characters or bytes of the source. * * @throws UnsupportedOperationException if this source does not contain {@link #hasCharacters() * characters}, nor {@link #hasBytes() bytes}. * @since 0.8 */ public final int getLength() { if (hasCharacters()) { return getTextMap().length(); } else if (hasBytes()) { return getBytes().length(); } else { throw new UnsupportedOperationException("Operation is only enabled for sources with character or byte content."); } }
static SourceSection findNearest(Source source, SourceElement[] sourceElements, int line, int column, SuspendAnchor anchor, TruffleInstrument.Env env) { if (!source.hasCharacters()) { return null; } int boundLine = line; int boundColumn = column; int maxLine = source.getLineCount(); if (boundLine > maxLine) { boundLine = maxLine; } int maxColumn = source.getLineLength(boundLine) + 1; if (boundColumn > maxColumn) { boundColumn = maxColumn; } return findNearestBound(source, getElementTags(sourceElements), boundLine, boundColumn, anchor, env); }
private static void validateSource(PolyglotLanguageContext context, Source source) { if (!source.hasBytes() && !source.hasCharacters()) { throw new PolyglotIllegalArgumentException(String.format("Error evaluating the source. The source does not specify characters nor bytes.")); if (mimeType != null && source.hasCharacters() != expectCharacters) { if (source.hasBytes()) { throw new PolyglotIllegalArgumentException( if (source.hasCharacters() != expectCharacters) { Set<String> binaryMimeTypes = new HashSet<>(); Set<String> characterMimeTypes = new HashSet<>();
throw new IllegalArgumentException("startColumn " + startColumn + " > endColumn " + endColumn); if (hasCharacters()) { if (startColumn < 1 || endColumn < 1) { throw new IllegalArgumentException("columnNumber < 1");
/** * Uses configuration of this builder to create new {@link Source} object. The method throws * an {@link IOException} if an error loading the source occured. * * @return the source object * @throws IOException if an error reading the content occurred * @throws SecurityException if this {@link SourceBuilder} was created for a * {@link TruffleFile} and the used {@link org.graalvm.polyglot.io.FileSystem * filesystem} denied its reading * @since 1.0 */ public Source build() throws IOException { assert this.language != null; Source source = buildSource(this.language, this.origin, this.name, this.mimeType, this.content, this.uri, this.internal, this.interactive, this.cached, false); // make sure origin is not consumed again if builder is used twice if (source.hasBytes()) { this.content = source.getBytes(); } else if (source.hasCharacters()) { this.content = source.getCharacters(); } assert source.getName() != null; assert !source.hasCharacters() || source.getCharacters() != null; assert !source.hasBytes() || source.getBytes() != null; assert source.getLanguage() != null; return source; }
if (hasCharacters()) { final int charIndex = getTextMap().lineStartOffset(lineNumber); final int length = getTextMap().lineLength(lineNumber);
/** * @since 0.15 * @deprecated see {@link SourceBuilder#build()} */ @SuppressWarnings("unused") @Deprecated public Source build() throws E1, E2, E3 { try { Source source = buildSource(this.language, this.origin, this.name, this.mime, this.characters, this.uri, this.internal, this.interactive, this.cached, true); // legacy sources must have character sources assert source.hasCharacters(); // make sure origin is not consumed again if builder is used twice this.characters = source.getCharacters(); if (source.getMimeType() == null) { throw raise(RuntimeException.class, new MissingMIMETypeException()); } if (source.getName() == null) { throw raise(RuntimeException.class, new MissingNameException()); } return source; } catch (IOException ex) { throw raise(RuntimeException.class, ex); } } }
/** * {@inheritDoc} * * @since 1.0 */ @Override public String toString() { return "Source [language=" + getLanguage() + ", name=" + getName() + ", path=" + getPath() + ", internal=" + isInternal() + ", cached=" + isCached() + ", interactive=" + isInteractive() + ", hasBytes=" + hasBytes() + ", hasCharacters=" + hasCharacters() + ", URL=" + getURL() + ", URI=" + getURI() + ", mimeType=" + getMimeType() + "]"; }