@Override public int getCharLength(Object impl) { SourceSection section = (SourceSection) impl; return section.getCharLength(); }
@Override public int getCharLength(Object impl) { SourceSection section = (SourceSection) impl; return section.getCharLength(); }
InstrumentableNode getNextNode() { if (nextNode == null) { return null; } return (InstrumentableNode) nextNode.getOuter(nextMatch.getCharLength()); } }
InstrumentableNode getPreviousNode() { if (previousNode == null) { return null; } return (InstrumentableNode) previousNode.getOuter(previousMatch.getCharLength()); }
/** * 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(); }
private boolean matchSectionOffset(InstrumentableNode node, SourceSection sourceSection, int o1, int o2) { int o; switch (anchor) { case BEFORE: o = o1; break; case AFTER: o = o2; break; default: throw new IllegalArgumentException(anchor.name()); } if (offset == o && isTaggedWith(node, elementTags)) { if (exactIndexMatch == null || sourceSection.getCharLength() > exactIndexMatch.getCharLength()) { exactIndexMatch = sourceSection; } } if (exactIndexMatch != null) { return true; } return false; }
private boolean matchSectionOffset(InstrumentableNode node, SourceSection sourceSection, int o1, int o2) { int o; switch (anchor) { case BEFORE: o = o1; break; case AFTER: o = o2; break; default: throw new IllegalArgumentException(anchor.name()); } if (offset == o && isTaggedWith(node, elementTags)) { if (exactIndexMatch == null || sourceSection.getCharLength() > exactIndexMatch.getCharLength()) { exactIndexMatch = sourceSection; } } if (exactIndexMatch != null) { return true; } return false; }
/** 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(); } }
static String formatIndices(SourceSection sourceSection, boolean needsColumnSpecifier) { StringBuilder b = new StringBuilder(); boolean singleLine = sourceSection.getStartLine() == sourceSection.getEndLine(); if (singleLine) { b.append(sourceSection.getStartLine()); } else { b.append(sourceSection.getStartLine()).append("-").append(sourceSection.getEndLine()); } if (needsColumnSpecifier) { b.append(":"); if (sourceSection.getCharLength() <= 1) { b.append(sourceSection.getCharIndex()); } else { b.append(sourceSection.getCharIndex()).append("-").append(sourceSection.getCharIndex() + sourceSection.getCharLength() - 1); } } return b.toString(); }
private static String formatIndices(SourceSection sourceSection, boolean needsColumnSpecifier) { StringBuilder b = new StringBuilder(); boolean singleLine = sourceSection.getStartLine() == sourceSection.getEndLine(); if (singleLine) { b.append(sourceSection.getStartLine()); } else { b.append(sourceSection.getStartLine()).append("-").append(sourceSection.getEndLine()); } if (needsColumnSpecifier) { b.append(":"); if (sourceSection.getCharLength() <= 1) { b.append(sourceSection.getCharIndex()); } else { b.append(sourceSection.getCharIndex()).append("-").append(sourceSection.getCharIndex() + sourceSection.getCharLength() - 1); } } return b.toString(); }
static String formatIndices(SourceSection sourceSection, boolean needsColumnSpecifier) { StringBuilder b = new StringBuilder(); boolean singleLine = sourceSection.getStartLine() == sourceSection.getEndLine(); if (singleLine) { b.append(sourceSection.getStartLine()); } else { b.append(sourceSection.getStartLine()).append("-").append(sourceSection.getEndLine()); } if (needsColumnSpecifier) { b.append(":"); if (sourceSection.getCharLength() <= 1) { b.append(sourceSection.getCharIndex()); } else { b.append(sourceSection.getCharIndex()).append("-").append(sourceSection.getCharIndex() + sourceSection.getCharLength() - 1); } } return b.toString(); }
/** * Returns an implementation-defined string representation of this source section to be used for * debugging purposes only. * * @see #getCharacters() * @since 0.8 or earlier */ @Override public String toString() { StringBuilder b = new StringBuilder(); b.append("SourceSection(source=").append(getSource().getName()); if (isAvailable()) { b.append(", index=").append(getCharIndex()); b.append(", length=").append(getCharLength()); if (isValid()) { b.append(", characters=").append(getCharacters().toString().replaceAll("\\n", "\\\\n")); } else { b.append(", valid=false"); } } else { b.append(" available=false"); } b.append(")"); return b.toString(); }
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()); }
/** * Returns the 1-based column number of the last 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 column number * @since 0.8 or earlier */ public int getEndColumn() { if (source == null) { return -1; } if (!isValid()) { return 1; } return source.getColumnNumber(getCharIndex() + Math.max(0, getCharLength() - 1)); }
/** * Returns 1-based line number of the last 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 getEndLine() { if (source == null) { return -1; } if (!isValid()) { return 1; } return source.getLineNumber(getCharIndex() + Math.max(0, getCharLength() - 1)); }
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; }
private static boolean hasLargerParent(Node ch, int sectionLength) { Node parent = ch.getParent(); while (parent != null) { if (parent instanceof InstrumentableNode && ((InstrumentableNode) parent).isInstrumentable() || parent instanceof RootNode) { SourceSection pss = parent.getSourceSection(); if (pss != null && pss.getCharLength() > sectionLength) { return true; } } parent = parent.getParent(); } return false; } }
@Override public void onLoad(LoadSourceSectionEvent event) { Node eventNode = event.getNode(); if (!(eventNode instanceof InstrumentableNode && ((InstrumentableNode) eventNode).isInstrumentable())) { return; } InstrumentableNode node = (InstrumentableNode) eventNode; SourceSection sourceSection = event.getSourceSection(); if (matchSectionLine(node, sourceSection)) { // We have exact line match, we do not need to do anything more return; } int o1 = sourceSection.getCharIndex(); int o2; if (sourceSection.getCharLength() > 0) { o2 = sourceSection.getCharEndIndex() - 1; } else { o2 = sourceSection.getCharIndex(); } if (matchSectionOffset(node, sourceSection, o1, o2)) { // We have exact offset index match, we do not need to do anything more return; } // Offset approximation findOffsetApproximation(node, sourceSection, o1, o2); }