@Override public String getName(Object impl) { com.oracle.truffle.api.source.Source source = (com.oracle.truffle.api.source.Source) impl; return source.getName(); }
/** * Get URI of the source. Every source has an associated {@link URI}, which can be used as a * persistent identification of the source. For example one can * {@link com.oracle.truffle.api.debug.DebuggerSession#install(com.oracle.truffle.api.debug.Breakpoint) * register a breakpoint using a URI} to a source that isn't loaded yet and it will be activated * when the source is evaluated. The {@link URI} returned by this method should be as unique as * possible, yet it can happen that different {@link Source sources} return the same * {@link #getURI} - for example when content of a {@link Source#newBuilder(String, TruffleFile) * file on a disk} changes and is re-loaded. * * @return a URI, it's never <code>null</code> * @since 0.14 */ public final URI getURI() { URI uri = getOriginalURI(); if (uri == null) { uri = computedURI; if (uri == null) { byte[] bytes = hasBytes() ? getBytes().toByteArray() : getCharacters().toString().getBytes(); uri = computedURI = getNamedURI(getName(), bytes); } } return uri; }
@Override public String getName(Object impl) { com.oracle.truffle.api.source.Source source = (com.oracle.truffle.api.source.Source) impl; return source.getName(); }
@Override public String getName() { return base.getName(); }
@Override public String getName() { return key.base.getName(); }
@Override public String toString() { String keyDescription; if (key == null) { keyDescription = "AlwaysHalt"; } else if (key instanceof Source) { keyDescription = "sourceName=" + ((Source) key).getName(); } else if (key instanceof URI) { keyDescription = "uri=" + ((URI) key).toString(); } else { keyDescription = key.toString(); } return keyDescription + ", line=" + line + ", column=" + column; }
@Override public String toString() { String keyDescription; if (key == null) { keyDescription = "AlwaysHalt"; } else if (key instanceof Source) { keyDescription = "sourceName=" + ((Source) key).getName(); } else if (key instanceof URI) { keyDescription = "uri=" + ((URI) key).toString(); } else { keyDescription = key.toString(); } return keyDescription + ", line=" + line + ", column=" + column; }
TextMap createTextMap() { final CharSequence code = getCharacters(); if (code == null) { throw new RuntimeException("can't read file " + getName()); } return TextMap.fromCharSequence(code); }
TextMap createTextMap() { final CharSequence code = getCharacters(); if (code == null) { throw new RuntimeException("can't read file " + getName()); } return TextMap.fromCharSequence(code); }
protected TextMap createTextMap() { final String code = getCode(); if (code == null) { throw new RuntimeException("can't read file " + getName()); } return TextMap.fromString(code); }
private static String formatPath(SourceSection sourceSection) { if (sourceSection.getSource().getPath() != null) { Path path = FileSystems.getDefault().getPath(".").toAbsolutePath(); Path filePath = FileSystems.getDefault().getPath(sourceSection.getSource().getPath()).toAbsolutePath(); try { return path.relativize(filePath).toString(); } catch (IllegalArgumentException e) { // relativization failed } } return sourceSection.getSource().getName(); }
private static String getShortDescription(SourceSection sourceSection) { StringBuilder b = new StringBuilder(); b.append(sourceSection.getSource().getName()); b.append(":"); if (sourceSection.getStartLine() == sourceSection.getEndLine()) { b.append(sourceSection.getStartLine()); } else { b.append(sourceSection.getStartLine()).append("-").append(sourceSection.getEndLine()); } return b.toString(); }
private static String formatLocation(SourceSection sourceSection) { if (sourceSection == null) { return ""; } if (sourceSection.getSource() == null) { // TODO we can remove this block if SourceSection#createUnavailable was removed, because // then source cannot become null anymore. return "at <Unknown>"; } else { return "at " + String.format("%s:%d", sourceSection.getSource().getName(), sourceSection.getStartLine()); } }
private static String formatSourceSection(SourceSection sourceSection) { if (sourceSection == null || sourceSection.getSource() == null) { return "n/a"; } return String.format("%s:%d", sourceSection.getSource().getName(), sourceSection.getStartLine()); }
private static String formatLocation(SourceSection sourceSection) { if (sourceSection == null) { return ""; } if (sourceSection.getSource() == null) { // TODO we can remove this block if SourceSection#createUnavailable was removed, because // then source cannot become null anymore. return "at <Unknown>"; } else { return "at " + String.format("%s:%d", sourceSection.getSource().getName(), sourceSection.getStartLine()); } }
final boolean equalAttributes(Source other) { return Objects.equals(getMimeType(), other.getMimeType()) && Objects.equals(getLanguage(), other.getLanguage()) && Objects.equals(getName(), other.getName()) && Objects.equals(getPath(), other.getPath()) && isInternal() == other.isInternal() && isInteractive() == other.isInteractive(); }
private String formatFileName() { if (sourceSection == null) { return "<Unknown>"; } Source source = sourceSection.getSource(); if (source == null) { // TODO the source == null branch can be removed if the deprecated // SourceSection#createUnavailable has be removed. return "<Unknown>"; } else if (source.getPath() == null) { return source.getName(); } else { return source.getPath(); } }
protected static String sourceInfo(Node node) { final SourceSection src = node.getSourceSection(); if (src != null) { if (src instanceof NullSourceSection) { final NullSourceSection nullSection = (NullSourceSection) src; return nullSection.getShortDescription(); } else { return src.getSource().getName() + ":" + src.getStartLine(); } } return ""; }
StackTraceElement toTraceElement() { if (stackTrace == null) { LanguageInfo language = getLanguage(); String declaringClass = language != null ? "<" + language.getId() + ">" : "<unknown>"; String methodName = getName0(); if (methodName == null) { methodName = ""; } SourceSection sourceLocation = getSourceSection(); String fileName = sourceLocation != null ? sourceLocation.getSource().getName() : "Unknown"; int startLine = sourceLocation != null ? sourceLocation.getStartLine() : -1; stackTrace = new StackTraceElement(declaringClass, methodName, fileName, startLine); } return stackTrace; } }
/** * {@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() + "]"; }