/** * Returns the {@link Tag} of the specified {@linkplain TagType type} that {@linkplain Segment#encloses(int) encloses} the specified position in the source document. * <p> * See the {@link Tag} class documentation for more details about the behaviour of this method. * * @param pos the position in the source document, may be out of bounds. * @param tagType the <code>TagType</code> to search for. * @return the {@link Tag} of the specified {@linkplain TagType type} that {@linkplain Segment#encloses(int) encloses} the specified position in the source document, or <code>null</code> if the position is not within a tag of the specified type or is out of bounds. */ public Tag getEnclosingTag(final int pos, final TagType tagType) { final Tag tag=getPreviousTag(pos,tagType); if (tag==null || tag.end<=pos) return null; return tag; }
/** * Returns the {@link StartTag} of the specified {@linkplain StartTagType type} at or immediately preceding (or {@linkplain Segment#encloses(int) enclosing}) the specified position in the source document. * <p> * See the {@link Tag} class documentation for more details about the behaviour of this method. * <p> * This is exactly equivalent to <code>(StartTag)</code>{@link #getPreviousTag(int,TagType) getPreviousTag}<code>(pos,startTagType)</code>, * but can be used to avoid the explicit cast to a {@link StartTag} object. * * @param pos the position in the source document from which to start the search, may be out of bounds. * @param startTagType the <code>StartTagType</code> to search for, must not be <code>null</code>. * @return the {@link StartTag} of the specified {@linkplain StartTagType type} at or immediately preceding (or {@linkplain Segment#encloses(int) enclosing}) the specified position in the source document, or <code>null</code> if none exists or the specified position is out of bounds. */ public StartTag getPreviousStartTag(final int pos, final StartTagType startTagType) { if (startTagType==null) throw new IllegalArgumentException("startTagType argument must not be null"); return (StartTag)getPreviousTag(pos,startTagType); }
/** * Returns the {@link EndTag} of the specified {@linkplain EndTagType type} at or immediately preceding (or {@linkplain Segment#encloses(int) enclosing}) the specified position in the source document. * <p> * See the {@link Tag} class documentation for more details about the behaviour of this method. * <p> * This is exactly equivalent to <code>(EndTag)</code>{@link #getPreviousTag(int,TagType) getPreviousTag}<code>(pos,endTagType)</code>, * but can be used to avoid the explicit cast to an {@link EndTag} object. * * @param pos the position in the source document from which to start the search, may be out of bounds. * @param endTagType the <code>EndTagType</code> to search for, must not be <code>null</code>. * @return the {@link EndTag} of the specified {@linkplain EndTagType type} at or immediately preceding (or {@linkplain Segment#encloses(int) enclosing}) the specified position in the source document, or <code>null</code> if none exists or the specified position is out of bounds. */ public EndTag getPreviousEndTag(final int pos, final EndTagType endTagType) { if (endTagType==null) throw new IllegalArgumentException("endTagType argument must not be null"); return (EndTag)getPreviousTag(pos,endTagType); }
Tag getPreviousNonServerTag(int pos) { while (true) { final Tag tag=getPreviousTag(pos-1); if (tag==null) return null; if (!tag.getTagType().isServerTag()) return tag; pos=tag.begin-1; } }
public ParserTag getPreviousTag(int i) { Tag encosingTag = fSource.getEnclosingTag(i); Tag parserTag = fSource.getPreviousTag(i); if (parserTag.getBegin() == encosingTag.getBegin()) return makeParserTag(fSource.getPreviousTag(encosingTag.getBegin() - 1)); return makeParserTag(fSource.getPreviousTag(i)); }
if (searchName==null) return (StartTag)source.getPreviousTag(pos,searchStartTagType); if (source.wasFullSequentialParseCalled() && isXMLTagName) {