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
`static class` `XMLPositionUtility.EntityReferenceRange`

### Method Summary

All Methods Static Methods Concrete Methods
`static boolean` `covers​(org.eclipse.lsp4j.Range range, org.eclipse.lsp4j.Position position)`
`static org.eclipse.lsp4j.DocumentLink` `createDocumentLink​(DOMRange target, String location, boolean adjust)` Create a document link
`static org.eclipse.lsp4j.Location` `createLocation​(DOMRange target)` Returns the location for the given `target` node.
`static org.eclipse.lsp4j.LocationLink` `createLocationLink​(DOMRange origin, DOMRange target)` Returns the location link for the given `origin` and `target` nodes.
`static org.eclipse.lsp4j.LocationLink` `createLocationLink​(org.eclipse.lsp4j.Range origin, DOMRange target)` Returns the location link for the given `origin` and `target` nodes.
`static org.eclipse.lsp4j.LocationLink` `createLocationLink​(org.eclipse.lsp4j.Range origin, TargetRange target)` Returns the location link for the given `origin` and `target` nodes.
`static org.eclipse.lsp4j.Range` `createRange​(int startOffset, int endOffset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `createRange​(DOMRange range)` Returns the range for the given `node`.
`static org.eclipse.lsp4j.Range` `createSelectionRange​(DOMRange origin)` Returns the selection range for the given `origin` node.
`static boolean` `doesTagCoverPosition​(org.eclipse.lsp4j.Range startTagRange, org.eclipse.lsp4j.Range endTagRange, org.eclipse.lsp4j.Position position)`
`static org.eclipse.lsp4j.Range` `getElementDeclMissingContentOrCategory​(int offset, DOMDocument document)`
`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.
`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.
`static org.eclipse.lsp4j.Range` `getLastDTDDeclParameter​(int offset, DOMDocument document)` Will give the range for the last DTD Decl parameter at 'offset'.
`static org.eclipse.lsp4j.Range` `getLastValidDTDDeclParameter​(int offset, DOMDocument document)`
`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'.
`static org.eclipse.lsp4j.Range` `getLastValidDTDDeclParameterOrUnrecognized​(int offset, DOMDocument document)` Will give the range for the last VALID DTD Decl parameter at 'offset'.
`static org.eclipse.lsp4j.Position` `getMatchingTagPosition​(DOMDocument xmlDocument, org.eclipse.lsp4j.Position position)`
`static org.eclipse.lsp4j.Range` `getTagNameRange​(TokenType tokenType, int startOffset, DOMDocument xmlDocument)`
`static boolean` `isBeforeOrEqual​(org.eclipse.lsp4j.Position pos1, org.eclipse.lsp4j.Position pos2)`
`static boolean` `isInAttributeValue​(DOMDocument xmlDocument, org.eclipse.lsp4j.Position position)` Returns true if the given position is within an attribute value, and false otherwise
`static org.eclipse.lsp4j.Range` `selectAllAttributes​(int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectAttributeFromGivenNameAt​(String attrName, int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectAttributeName​(DOMAttr attr)` Returns the attribute name range and null otherwise.
`static org.eclipse.lsp4j.Range` `selectAttributeNameAt​(int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectAttributeNameFromGivenNameAt​(String attrName, int offset, DOMDocument document)`
`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
`static org.eclipse.lsp4j.Range` `selectAttributeValue​(DOMAttr attr)` Returns the attribute value range and null otherwise.
`static org.eclipse.lsp4j.Range` `selectAttributeValue​(DOMAttr attr, boolean withoutQuote)` Returns the attribute value range and null otherwise.
`static org.eclipse.lsp4j.Range` `selectAttributeValueAt​(String attrName, int offset, boolean withouQuote, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectAttributeValueAt​(String attrName, int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectAttributeValueByGivenValueAt​(String attrValue, int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectAttributeValueFromGivenValue​(String attrValue, int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectChildEndTag​(String childTag, int offset, DOMDocument document)`
`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
`static org.eclipse.lsp4j.Range` `selectContent​(int offset, DOMDocument document)`
`static int` `selectCurrentTagOffset​(int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectDTDDeclTagNameAt​(int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectDTDElementDeclAt​(int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectEndTagLocalName​(DOMElement element)` Returns the range of the end tag of the given LOCAL `element` name and null otherwise.
`static org.eclipse.lsp4j.Range` `selectEndTagName​(int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectEndTagName​(DOMElement element)` Returns the range of the end tag of the given `element` name and null otherwise.
`static org.eclipse.lsp4j.Range` `selectEndTagName​(DOMElement element, boolean localNameOnly)` Returns the range of the end tag of the given `element` and null otherwise.
`static XMLPositionUtility.EntityReferenceRange` `selectEntityReference​(int offset, DOMDocument document)` Returns the range of the entity reference in a text node (ex : &) and null otherwise.
`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.
`static org.eclipse.lsp4j.Range` `selectFirstChild​(int offset, DOMDocument document)` Returns the range covering the first child of the node located at offset.
`static org.eclipse.lsp4j.Range` `selectFirstNonWhitespaceText​(int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectParameterNameFromGivenName​(String parameterName, DTDDeclNode declNode)`
`static org.eclipse.lsp4j.Range` `selectRootAttributeValue​(String attrName, DOMDocument document)` Finds the root element of the given document and returns the attribute value `Range` for the attribute `attrName`.
`static org.eclipse.lsp4j.Range` `selectRootStartTag​(DOMDocument document)` Returns the range of the root start tag (excludes the '<') of the given `document` and null otherwise.
`static org.eclipse.lsp4j.Range` `selectStartTagLocalName​(DOMNode element)` Returns the range of a tag's local name.
`static org.eclipse.lsp4j.Range` `selectStartTagName​(int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Range` `selectStartTagName​(DOMNode element)` Returns the range of the start tag name (excludes the '<') of the given `element` and null otherwise.
`static org.eclipse.lsp4j.Range` `selectText​(DOMText text)` Returns the text content range and null otherwise.
`static org.eclipse.lsp4j.Range` `selectTrimmedText​(int offset, DOMDocument document)` Returns the range covering the trimmed text belonging to the node located at offset.
`static org.eclipse.lsp4j.Range` `selectValueWithoutQuote​(DOMRange node)` Select the value from the start/end node without quote.
`static org.eclipse.lsp4j.Range` `selectWholeTag​(int offset, DOMDocument document)`
`static org.eclipse.lsp4j.Location` `toLocation​(org.eclipse.lsp4j.LocationLink locationLink)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### 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/tag
  `attrName` - the attribute name
  `offset` - text offset from beginning of document
  `document` - 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 document
  `position` - 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 value `Range` for the attribute `attrName`. If `attrName` is not declared then null is returned.

Parameters:
  `attrName` - The name of the attribute to find the range of the value for
  `document` - The document to use the root element of
Returns:
  The range in `document` where the declared value of attribute `attrName` resides (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 given `document` and null otherwise.

Parameters:
  `document` - the DOM document.
Returns:
  the range of the root start tag (excludes the '<') of the given `document` and 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 given `element` and null otherwise.

Parameters:
  `element` - the DOM element
Returns:
  the range of the start tag of the given `element` and 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 given `element` name and null otherwise.

Parameters:
  `element` - the DOM element
Returns:
  the range of the end tag of the given `element` and null otherwise.

#### selectEndTagLocalName

    public static org.eclipse.lsp4j.Range selectEndTagLocalName​(DOMElement element)

Returns the range of the end tag of the given LOCAL `element` name and null otherwise.

Parameters:
  `element` - the DOM element
Returns:
  the range of the end tag of the given `element` and null otherwise.

#### selectEndTagName

    public static org.eclipse.lsp4j.Range selectEndTagName​(DOMElement element,
                                                           boolean localNameOnly)

Returns the range of the end tag of the given `element` and null otherwise.

Parameters:
  `element` - the DOM element
Returns:
  the range of the end tag of the given `element` and 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 offset
  `document` - 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 offset
  `document` - the document
  `endsWithSemicolon` - 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 given `node`.

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 given `origin` and `target` nodes.

Parameters:
  `origin` - the origin node.
  `target` - the target node.
Returns:
  the location link for the given `origin` and `target` nodes.

#### createSelectionRange

    public static org.eclipse.lsp4j.Range createSelectionRange​(DOMRange origin)

Returns the selection range for the given `origin` node.

Parameters:
  `origin` - the origin node.
Returns:
  the selection range for the given `origin` node.

#### createLocationLink

    public static org.eclipse.lsp4j.LocationLink createLocationLink​(org.eclipse.lsp4j.Range origin,
                                                                    DOMRange target)

Returns the location link for the given `origin` and `target` nodes.

Parameters:
  `origin` - the origin node.
  `target` - the target node.
Returns:
  the location link for the given `origin` and `target` nodes.

#### createLocationLink

    public static org.eclipse.lsp4j.LocationLink createLocationLink​(org.eclipse.lsp4j.Range origin,
                                                                    TargetRange target)

Returns the location link for the given `origin` and `target` nodes.

Parameters:
  `origin` - the origin node.
  `target` - the target node.
Returns:
  the location link for the given `origin` and `target` nodes.

#### createLocation

    public static org.eclipse.lsp4j.Location createLocation​(DOMRange target)

Returns the location for the given `target` node.

Parameters:
  `target` - the target node.
Returns:
  the location for the given `target` node.

#### 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 link
  `location` - URI where the link should point
  `adjust` - `true` means the first and last character of `target` will not be a part of the link.
Returns:
  A DocumentLink over the range `target` that points to `location`.
Throws:
  `BadLocationException` - if `target` is 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 return range without ".

Parameters:
  `node` - the DOM node.
Returns:
  the value from the start/end node without quote.