Package org.eclipse.lemminx.utils
Class XMLPositionUtility
- java.lang.Object
-
- org.eclipse.lemminx.utils.XMLPositionUtility
-
public class XMLPositionUtility extends Object
XML position utility.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXMLPositionUtility.EntityReferenceRange
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancovers(org.eclipse.lsp4j.Range range, org.eclipse.lsp4j.Position position)static org.eclipse.lsp4j.DocumentLinkcreateDocumentLink(DOMRange target, String location, boolean adjust)Create a document linkstatic org.eclipse.lsp4j.LocationcreateLocation(DOMRange target)Returns the location for the giventargetnode.static org.eclipse.lsp4j.LocationLinkcreateLocationLink(DOMRange origin, DOMRange target)Returns the location link for the givenoriginandtargetnodes.static org.eclipse.lsp4j.LocationLinkcreateLocationLink(org.eclipse.lsp4j.Range origin, DOMRange target)Returns the location link for the givenoriginandtargetnodes.static org.eclipse.lsp4j.LocationLinkcreateLocationLink(org.eclipse.lsp4j.Range origin, TargetRange target)Returns the location link for the givenoriginandtargetnodes.static org.eclipse.lsp4j.RangecreateRange(int startOffset, int endOffset, DOMDocument document)static org.eclipse.lsp4j.RangecreateRange(DOMRange range)Returns the range for the givennode.static org.eclipse.lsp4j.RangecreateSelectionRange(DOMRange origin)Returns the selection range for the givenoriginnode.static booleandoesTagCoverPosition(org.eclipse.lsp4j.Range startTagRange, org.eclipse.lsp4j.Range endTagRange, org.eclipse.lsp4j.Position position)static org.eclipse.lsp4j.RangegetElementDeclMissingContentOrCategory(int offset, DOMDocument document)static intgetEntityReferenceEndOffset(String text, int offset)Returns the end offset of the entity reference (ex : &am|p;) from the right of the given offset and -1 if no entity reference.static intgetEntityReferenceStartOffset(String text, int offset)Returns the start offset of the entity reference (ex : &am|p;) from the left of the given offset and -1 if no entity reference.static org.eclipse.lsp4j.RangegetLastDTDDeclParameter(int offset, DOMDocument document)Will give the range for the last DTD Decl parameter at 'offset'.static org.eclipse.lsp4j.RangegetLastValidDTDDeclParameter(int offset, DOMDocument document)static org.eclipse.lsp4j.RangegetLastValidDTDDeclParameter(int offset, DOMDocument document, boolean selectWholeParameter)Will give the range for the last VALID DTD Decl parameter at 'offset'.static org.eclipse.lsp4j.RangegetLastValidDTDDeclParameterOrUnrecognized(int offset, DOMDocument document)Will give the range for the last VALID DTD Decl parameter at 'offset'.static org.eclipse.lsp4j.PositiongetMatchingTagPosition(DOMDocument xmlDocument, org.eclipse.lsp4j.Position position)static org.eclipse.lsp4j.RangegetTagNameRange(TokenType tokenType, int startOffset, DOMDocument xmlDocument)static booleanisBeforeOrEqual(org.eclipse.lsp4j.Position pos1, org.eclipse.lsp4j.Position pos2)static booleanisInAttributeValue(DOMDocument xmlDocument, org.eclipse.lsp4j.Position position)Returns true if the given position is within an attribute value, and false otherwisestatic org.eclipse.lsp4j.RangeselectAllAttributes(int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectAttributeFromGivenNameAt(String attrName, int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectAttributeName(DOMAttr attr)Returns the attribute name range and null otherwise.static org.eclipse.lsp4j.RangeselectAttributeNameAt(int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectAttributeNameFromGivenNameAt(String attrName, int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectAttributePrefixFromGivenNameAt(String attrName, int offset, DOMDocument document)Returns the range of the prefix of an attribute name For example, if attrName = "xsi:example", the range for "xsi" will be returnedstatic org.eclipse.lsp4j.RangeselectAttributeValue(DOMAttr attr)Returns the attribute value range and null otherwise.static org.eclipse.lsp4j.RangeselectAttributeValue(DOMAttr attr, boolean withoutQuote)Returns the attribute value range and null otherwise.static org.eclipse.lsp4j.RangeselectAttributeValueAt(String attrName, int offset, boolean withouQuote, DOMDocument document)static org.eclipse.lsp4j.RangeselectAttributeValueAt(String attrName, int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectAttributeValueByGivenValueAt(String attrValue, int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectAttributeValueFromGivenValue(String attrValue, int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectChildEndTag(String childTag, int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectChildNodeAttributeValueFromGivenNameAt(String childNodeName, String attrName, int offset, DOMDocument document)Returns the range of the attribute value of a specific child node, if it existsstatic org.eclipse.lsp4j.RangeselectContent(int offset, DOMDocument document)static intselectCurrentTagOffset(int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectDTDDeclTagNameAt(int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectDTDElementDeclAt(int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectEndTagLocalName(DOMElement element)Returns the range of the end tag of the given LOCALelementname and null otherwise.static org.eclipse.lsp4j.RangeselectEndTagName(int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectEndTagName(DOMElement element)Returns the range of the end tag of the givenelementname and null otherwise.static org.eclipse.lsp4j.RangeselectEndTagName(DOMElement element, boolean localNameOnly)Returns the range of the end tag of the givenelementand null otherwise.static XMLPositionUtility.EntityReferenceRangeselectEntityReference(int offset, DOMDocument document)Returns the range of the entity reference in a text node (ex : &) and null otherwise.static XMLPositionUtility.EntityReferenceRangeselectEntityReference(int offset, DOMDocument document, boolean endsWithSemicolon)Returns the range of the entity reference in a text node (ex : &) and null otherwise.static org.eclipse.lsp4j.RangeselectFirstChild(int offset, DOMDocument document)Returns the range covering the first child of the node located at offset.static org.eclipse.lsp4j.RangeselectFirstNonWhitespaceText(int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectParameterNameFromGivenName(String parameterName, DTDDeclNode declNode)static org.eclipse.lsp4j.RangeselectRootAttributeValue(String attrName, DOMDocument document)Finds the root element of the given document and returns the attribute valueRangefor the attributeattrName.static org.eclipse.lsp4j.RangeselectRootStartTag(DOMDocument document)Returns the range of the root start tag (excludes the '<') of the givendocumentand null otherwise.static org.eclipse.lsp4j.RangeselectStartTagLocalName(DOMNode element)Returns the range of a tag's local name.static org.eclipse.lsp4j.RangeselectStartTagName(int offset, DOMDocument document)static org.eclipse.lsp4j.RangeselectStartTagName(DOMNode element)Returns the range of the start tag name (excludes the '<') of the givenelementand null otherwise.static org.eclipse.lsp4j.RangeselectText(DOMText text)Returns the text content range and null otherwise.static org.eclipse.lsp4j.RangeselectTrimmedText(int offset, DOMDocument document)Returns the range covering the trimmed text belonging to the node located at offset.static org.eclipse.lsp4j.RangeselectValueWithoutQuote(DOMRange node)Select the value from the start/end node without quote.static org.eclipse.lsp4j.RangeselectWholeTag(int offset, DOMDocument document)static org.eclipse.lsp4j.LocationtoLocation(org.eclipse.lsp4j.LocationLink locationLink)
-
-
-
Method Detail
-
selectAttributeName
public static org.eclipse.lsp4j.Range selectAttributeName(DOMAttr attr)
Returns the attribute name range and null otherwise.- Parameters:
attr- the attribute.- Returns:
- the attribute name range and null otherwise.
-
selectAttributeNameAt
public static org.eclipse.lsp4j.Range selectAttributeNameAt(int offset, DOMDocument document)
-
selectAttributeValue
public static org.eclipse.lsp4j.Range selectAttributeValue(DOMAttr attr)
Returns the attribute value range and null otherwise.- Parameters:
attr- the attribute.- Returns:
- the attribute value range and null otherwise.
-
selectAttributeValue
public static org.eclipse.lsp4j.Range selectAttributeValue(DOMAttr attr, boolean withoutQuote)
Returns the attribute value range and null otherwise.- Parameters:
attr- the attribute.withoutQuote- true if range must remove the quote and false otherwise.- Returns:
- the attribute value range and null otherwise.
-
selectAttributeValueAt
public static org.eclipse.lsp4j.Range selectAttributeValueAt(String attrName, int offset, DOMDocument document)
-
selectAttributeValueAt
public static org.eclipse.lsp4j.Range selectAttributeValueAt(String attrName, int offset, boolean withouQuote, DOMDocument document)
-
selectAttributeValueFromGivenValue
public static org.eclipse.lsp4j.Range selectAttributeValueFromGivenValue(String attrValue, int offset, DOMDocument document)
-
selectAttributeValueByGivenValueAt
public static org.eclipse.lsp4j.Range selectAttributeValueByGivenValueAt(String attrValue, int offset, DOMDocument document)
-
selectAttributeNameFromGivenNameAt
public static org.eclipse.lsp4j.Range selectAttributeNameFromGivenNameAt(String attrName, int offset, DOMDocument document)
-
selectAttributePrefixFromGivenNameAt
public static org.eclipse.lsp4j.Range selectAttributePrefixFromGivenNameAt(String attrName, int offset, DOMDocument document)
Returns the range of the prefix of an attribute name For example, if attrName = "xsi:example", the range for "xsi" will be returned
-
selectAttributeFromGivenNameAt
public static org.eclipse.lsp4j.Range selectAttributeFromGivenNameAt(String attrName, int offset, DOMDocument document)
-
selectChildNodeAttributeValueFromGivenNameAt
public static org.eclipse.lsp4j.Range selectChildNodeAttributeValueFromGivenNameAt(String childNodeName, String attrName, int offset, DOMDocument document)
Returns the range of the attribute value of a specific child node, if it exists- Parameters:
childNodeName- the tag name of the child node/tagattrName- the attribute nameoffset- text offset from beginning of documentdocument- the DOM document.- Returns:
- the child node attribute value range and null otherwise.
-
selectAllAttributes
public static org.eclipse.lsp4j.Range selectAllAttributes(int offset, DOMDocument document)
-
isInAttributeValue
public static boolean isInAttributeValue(DOMDocument xmlDocument, org.eclipse.lsp4j.Position position)
Returns true if the given position is within an attribute value, and false otherwise- Parameters:
xmlDocument- the model of the documentposition- the position to check- Returns:
- true if the given position is within an attribute value, and false otherwise
-
selectRootAttributeValue
public static org.eclipse.lsp4j.Range selectRootAttributeValue(String attrName, DOMDocument document)
Finds the root element of the given document and returns the attribute valueRangefor the attributeattrName. IfattrNameis not declared then null is returned.- Parameters:
attrName- The name of the attribute to find the range of the value fordocument- The document to use the root element of- Returns:
- The range in
documentwhere the declared value of attributeattrNameresides (including quotations), or null if the attriubte is not declared.
-
selectChildEndTag
public static org.eclipse.lsp4j.Range selectChildEndTag(String childTag, int offset, DOMDocument document)
-
selectRootStartTag
public static org.eclipse.lsp4j.Range selectRootStartTag(DOMDocument document)
Returns the range of the root start tag (excludes the '<') of the givendocumentand null otherwise.- Parameters:
document- the DOM document.- Returns:
- the range of the root start tag (excludes the '<') of the given
documentand null otherwise.
-
selectStartTagName
public static org.eclipse.lsp4j.Range selectStartTagName(int offset, DOMDocument document)
-
selectStartTagName
public static org.eclipse.lsp4j.Range selectStartTagName(DOMNode element)
Returns the range of the start tag name (excludes the '<') of the givenelementand null otherwise.- Parameters:
element- the DOM element- Returns:
- the range of the start tag of the given
elementand null otherwise.
-
selectStartTagLocalName
public static org.eclipse.lsp4j.Range selectStartTagLocalName(DOMNode element)
Returns the range of a tag's local name. If the tag does not have a prefix, implying it doesn't have a local name, it will return null.- Parameters:
element-- Returns:
-
selectCurrentTagOffset
public static int selectCurrentTagOffset(int offset, DOMDocument document)
-
selectEndTagName
public static org.eclipse.lsp4j.Range selectEndTagName(int offset, DOMDocument document)
-
selectEndTagName
public static org.eclipse.lsp4j.Range selectEndTagName(DOMElement element)
Returns the range of the end tag of the givenelementname and null otherwise.- Parameters:
element- the DOM element- Returns:
- the range of the end tag of the given
elementand null otherwise.
-
selectEndTagLocalName
public static org.eclipse.lsp4j.Range selectEndTagLocalName(DOMElement element)
Returns the range of the end tag of the given LOCALelementname and null otherwise.- Parameters:
element- the DOM element- Returns:
- the range of the end tag of the given
elementand null otherwise.
-
selectEndTagName
public static org.eclipse.lsp4j.Range selectEndTagName(DOMElement element, boolean localNameOnly)
Returns the range of the end tag of the givenelementand null otherwise.- Parameters:
element- the DOM element- Returns:
- the range of the end tag of the given
elementand null otherwise.
-
selectEntityReference
public static XMLPositionUtility.EntityReferenceRange selectEntityReference(int offset, DOMDocument document)
Returns the range of the entity reference in a text node (ex : &) and null otherwise.- Parameters:
offset- the offsetdocument- the document- Returns:
- the range of the entity reference in a text node (ex : &) and null otherwise.
-
selectEntityReference
public static XMLPositionUtility.EntityReferenceRange selectEntityReference(int offset, DOMDocument document, boolean endsWithSemicolon)
Returns the range of the entity reference in a text node (ex : &) and null otherwise.- Parameters:
offset- the offsetdocument- the documentendsWithSemicolon- true if the entity reference must end with ';' and false otherwise.- Returns:
- the range of the entity reference in a text node (ex : &) and null otherwise.
-
getEntityReferenceStartOffset
public static int getEntityReferenceStartOffset(String text, int offset)
Returns the start offset of the entity reference (ex : &am|p;) from the left of the given offset and -1 if no entity reference.- Parameters:
text- the XML content.offset- the offset.- Returns:
- the start offset of the entity reference (ex : &am|p;) from the left of the given offset and -1 if no entity reference.
-
getEntityReferenceEndOffset
public static int getEntityReferenceEndOffset(String text, int offset)
Returns the end offset of the entity reference (ex : &am|p;) from the right of the given offset and -1 if no entity reference.- Parameters:
text- the XML content.offset- the offset.- Returns:
- the end offset of the entity reference (ex : &am|p;) from the right of the given offset and -1 if no entity reference.
-
selectFirstNonWhitespaceText
public static org.eclipse.lsp4j.Range selectFirstNonWhitespaceText(int offset, DOMDocument document)
-
selectText
public static org.eclipse.lsp4j.Range selectText(DOMText text)
Returns the text content range and null otherwise.- Parameters:
text- the DOM text node..- Returns:
- the text content range and null otherwise.
-
selectContent
public static org.eclipse.lsp4j.Range selectContent(int offset, DOMDocument document)
-
selectTrimmedText
public static org.eclipse.lsp4j.Range selectTrimmedText(int offset, DOMDocument document)Returns the range covering the trimmed text belonging to the node located at offset. This method assumes that the node located at offset only contains text. For example, if the node located at offset is: hello the returned range will cover only "hello".- Parameters:
offset-document-- Returns:
- range covering the trimmed text belonging to the node located at offset
-
selectDTDElementDeclAt
public static org.eclipse.lsp4j.Range selectDTDElementDeclAt(int offset, DOMDocument document)
-
getLastValidDTDDeclParameter
public static org.eclipse.lsp4j.Range getLastValidDTDDeclParameter(int offset, DOMDocument document, boolean selectWholeParameter)Will give the range for the last VALID DTD Decl parameter at 'offset'. An unrecognized Parameter is not considered VALID, eg: "-
getLastValidDTDDeclParameter
public static org.eclipse.lsp4j.Range getLastValidDTDDeclParameter(int offset, DOMDocument document)
-
getLastValidDTDDeclParameterOrUnrecognized
public static org.eclipse.lsp4j.Range getLastValidDTDDeclParameterOrUnrecognized(int offset, DOMDocument document)Will give the range for the last VALID DTD Decl parameter at 'offset'. An unrecognized Parameter is not considered VALID, eg:-
getLastDTDDeclParameter
public static org.eclipse.lsp4j.Range getLastDTDDeclParameter(int offset, DOMDocument document)Will give the range for the last DTD Decl parameter at 'offset'. An unrecognized Parameter is considered as well. eg:-
selectDTDDeclTagNameAt
public static org.eclipse.lsp4j.Range selectDTDDeclTagNameAt(int offset, DOMDocument document)
-
getElementDeclMissingContentOrCategory
public static org.eclipse.lsp4j.Range getElementDeclMissingContentOrCategory(int offset, DOMDocument document)
-
selectParameterNameFromGivenName
public static org.eclipse.lsp4j.Range selectParameterNameFromGivenName(String parameterName, DTDDeclNode declNode)
-
createRange
public static org.eclipse.lsp4j.Range createRange(DOMRange range)
Returns the range for the givennode.- Parameters:
node- the node- Returns:
- the range for the given
node.
-
createRange
public static org.eclipse.lsp4j.Range createRange(int startOffset, int endOffset, DOMDocument document)
-
createLocationLink
public static org.eclipse.lsp4j.LocationLink createLocationLink(DOMRange origin, DOMRange target)
Returns the location link for the givenoriginandtargetnodes.- Parameters:
origin- the origin node.target- the target node.- Returns:
- the location link for the given
originandtargetnodes.
-
createSelectionRange
public static org.eclipse.lsp4j.Range createSelectionRange(DOMRange origin)
Returns the selection range for the givenoriginnode.- Parameters:
origin- the origin node.- Returns:
- the selection range for the given
originnode.
-
createLocationLink
public static org.eclipse.lsp4j.LocationLink createLocationLink(org.eclipse.lsp4j.Range origin, DOMRange target)Returns the location link for the givenoriginandtargetnodes.- Parameters:
origin- the origin node.target- the target node.- Returns:
- the location link for the given
originandtargetnodes.
-
createLocationLink
public static org.eclipse.lsp4j.LocationLink createLocationLink(org.eclipse.lsp4j.Range origin, TargetRange target)Returns the location link for the givenoriginandtargetnodes.- Parameters:
origin- the origin node.target- the target node.- Returns:
- the location link for the given
originandtargetnodes.
-
createLocation
public static org.eclipse.lsp4j.Location createLocation(DOMRange target)
Returns the location for the giventargetnode.- Parameters:
target- the target node.- Returns:
- the location for the given
targetnode.
-
createDocumentLink
public static org.eclipse.lsp4j.DocumentLink createDocumentLink(DOMRange target, String location, boolean adjust) throws BadLocationException
Create a document link- Parameters:
target- The range in the document that should be the linklocation- URI where the link should pointadjust-truemeans the first and last character oftargetwill not be a part of the link.- Returns:
- A DocumentLink over the range
targetthat points tolocation. - Throws:
BadLocationException- iftargetis out of the bounds of the document
-
selectFirstChild
public static org.eclipse.lsp4j.Range selectFirstChild(int offset, DOMDocument document)Returns the range covering the first child of the node located at offset. Returns null if node is not a DOMElement, or if a node does not exist at offset.- Parameters:
offset-document-- Returns:
- range covering the first child of the node located at offset
-
selectWholeTag
public static org.eclipse.lsp4j.Range selectWholeTag(int offset, DOMDocument document)
-
doesTagCoverPosition
public static boolean doesTagCoverPosition(org.eclipse.lsp4j.Range startTagRange, org.eclipse.lsp4j.Range endTagRange, org.eclipse.lsp4j.Position position)
-
covers
public static boolean covers(org.eclipse.lsp4j.Range range, org.eclipse.lsp4j.Position position)
-
isBeforeOrEqual
public static boolean isBeforeOrEqual(org.eclipse.lsp4j.Position pos1, org.eclipse.lsp4j.Position pos2)
-
getTagNameRange
public static org.eclipse.lsp4j.Range getTagNameRange(TokenType tokenType, int startOffset, DOMDocument xmlDocument)
-
toLocation
public static org.eclipse.lsp4j.Location toLocation(org.eclipse.lsp4j.LocationLink locationLink)
-
getMatchingTagPosition
public static org.eclipse.lsp4j.Position getMatchingTagPosition(DOMDocument xmlDocument, org.eclipse.lsp4j.Position position)
-
selectValueWithoutQuote
public static org.eclipse.lsp4j.Range selectValueWithoutQuote(DOMRange node)
Select the value from the start/end node without quote. For the given attr value:
it will returnrange without ". - Parameters:
node- the DOM node.- Returns:
- the value from the start/end node without quote.
-
-
-
-
-