@Override public int getCharIndex(Object impl) { SourceSection section = (SourceSection) impl; return section.getCharIndex(); }
@Override public void breakpointResolved(Breakpoint brkp, SourceSection section) { resolvedIndexPtr[0] = section.getCharIndex() + 1; if (TRACE) { trace(" resolved: " + (resolvedIndexPtr[0])); } } }).build());
@Override public void breakpointResolved(Breakpoint brkp, SourceSection section) { resolvedIndexPtr[0] = section.getCharIndex() + 1; if (TRACE) { trace(" resolved: " + (resolvedIndexPtr[0])); } } }).build());
@Override public int getOffsetStart() { return sourceSection.getCharIndex(); }
@Override public int getCharIndex(Object impl) { SourceSection section = (SourceSection) impl; return section.getCharIndex(); }
/** * Returns the index of the text position immediately following the last character in the * section. Returns <code>0</code> for {@link #isAvailable() unavailable} source sections. * Please note that calling this method does not cause the {@link Source#getCharacters() code} * of the {@link #getSource() source} to be loaded. The returned index might be out of bounds of * the source code if assertions (-ea) are not enabled. * * @return the end position of the section * @since 0.8 or earlier */ public int getCharEndIndex() { if (source == null) { return -1; } return getCharIndex() + getCharLength(); }
/** * Returns the {@link Probe}, if any, associated with a specific line of guest language code; if * more than one, return the one with the first starting character location. */ public Probe findFirstProbe(LineLocation lineLocation) { Probe probe = null; final Collection<Probe> probes = findProbes(lineLocation); for (Probe probesOnLine : probes) { if (probe == null) { probe = probesOnLine; } else if (probesOnLine.getProbedSourceSection().getCharIndex() < probe.getProbedSourceSection().getCharIndex()) { probe = probesOnLine; } } return probe; }
@Override public void breakpointResolved(Breakpoint brkp, SourceSection section) { resolvedIndexPtr[0] = section.getCharIndex() + 1; if (TRACE) { trace("BREAKPOINT resolved to " + section.getStartLine() + ":" + section.getStartColumn()); } } }).build());
/** Get the last character index (inclusive). */ private static int getCharEndIndex(SourceSection ss) { if (ss.getCharLength() > 0) { return ss.getCharEndIndex() - 1; } else { return ss.getCharIndex(); } }
/** Get the last character index (inclusive). */ private static int getCharEndIndex(SourceSection ss) { if (ss.getCharLength() > 0) { return ss.getCharEndIndex() - 1; } else { return ss.getCharIndex(); } }
@Override public void breakpointResolved(Breakpoint brkp, SourceSection section) { resolvedIndexPtr[0] = section.getCharIndex() + 1; if (TRACE) { trace("BREAKPOINT resolved to " + section.getStartLine() + ":" + section.getStartColumn()); } } }).build());
/** * Returns 1-based line number of the first character in this section (inclusive). Returns * <code>1</code> for out of bounds or {@link #isAvailable() unavailable} source sections. * Please note that calling this method causes the {@link Source#getCharacters() code} of the * {@link #getSource() source} to be loaded if it was not yet loaded. * * @return the starting line number * @since 0.8 or earlier */ public int getStartLine() { if (source == null) { return -1; } if (!isValid()) { return 1; } return source.getLineNumber(getCharIndex()); }
/** * Returns the source code fragment described by this section. Returns an empty character * sequence for out of bounds or {@link #isAvailable() unavailable} source sections. Please note * that calling this method causes the {@link Source#getCharacters() code} of the * {@link #getSource() source} to be loaded if it was not yet loaded. * * @return the code as a CharSequence * @since 0.28 */ public CharSequence getCharacters() { if (!isValid()) { return ""; } return source.getCharacters().subSequence(getCharIndex(), getCharEndIndex()); }
@Override public SourceSection getSourceSection() { if (super.getSourceSection() == null && sourceSectionBegin != null && sourceSectionEnd != null) { super.setSourceSection(sourceSectionBegin.getSource().createSection(sourceSectionBegin.getCharIndex(), sourceSectionEnd.getCharEndIndex() - sourceSectionBegin.getCharIndex())); } return super.getSourceSection(); }
private static boolean isIndexIn(SourceSection sourceSection, IndexRange[] ranges) { if (sourceSection == null || !sourceSection.isAvailable()) { return false; } int otherStart = sourceSection.getCharIndex(); int otherEnd = otherStart + sourceSection.getCharLength(); for (IndexRange indexRange : ranges) { if (indexRange.contains(otherStart, otherEnd)) { return true; } } return false; }
private static boolean isIndexIn(SourceSection sourceSection, IndexRange[] ranges) { if (sourceSection == null || !sourceSection.isAvailable()) { return false; } int otherStart = sourceSection.getCharIndex(); int otherEnd = otherStart + sourceSection.getCharLength(); for (IndexRange indexRange : ranges) { if (indexRange.contains(otherStart, otherEnd)) { return true; } } return false; }
@TruffleBoundary private JsonArray sourceSectionsToJson() { return Json.array(getStateSet().stream().map(RegexASTNode::getSourceSection).filter(Objects::nonNull).map(x -> Json.obj( Json.prop("start", x.getCharIndex()), Json.prop("end", x.getCharEndIndex())))); }
@Override public SourceSection getSourceSection() { SourceSection src = super.getSourceSection(); if (src != null && !isEmpty()) { int endIndex = getLastTerm().getSourceSection().getCharEndIndex(); if (endIndex != src.getCharEndIndex()) { int startIndex = src.getCharIndex(); super.setSourceSection(src.getSource().createSection(startIndex, endIndex - startIndex)); } } return super.getSourceSection(); }
@TruffleBoundary private JsonArray sourceSectionsToJson() { if (!groupBoundaries.hasIndexUpdates()) { return Json.array(); } return Json.array(groupBoundaries.getUpdateIndices().stream().mapToObj(x -> { Group group = source.getStateSet().getAst().getGroupByBoundaryIndex(x); SourceSection sourceSection = (x & 1) == 0 ? group.getSourceSectionBegin() : group.getSourceSectionEnd(); return Json.obj(Json.prop("start", sourceSection.getCharIndex()), Json.prop("end", sourceSection.getCharEndIndex())); })); }
InstrumentableNode getContainsNode() { if (containsNode == null) { return null; } if (line > 0) { if (anchor == SuspendAnchor.BEFORE && line == containsMatch.getStartLine() || anchor == SuspendAnchor.AFTER && line == containsMatch.getEndLine()) { return (InstrumentableNode) containsNode.getOuter(containsMatch.getCharLength()); } } else { if (anchor == SuspendAnchor.BEFORE && offset == containsMatch.getCharIndex() || anchor == SuspendAnchor.AFTER && offset == containsMatch.getCharEndIndex() - 1) { return (InstrumentableNode) containsNode.getOuter(containsMatch.getCharLength()); } } return (InstrumentableNode) containsNode.getInner(containsMatch.getCharLength()); }