diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMAttr.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMAttr.java index eb6bf47b6..9c7c39553 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMAttr.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMAttr.java @@ -40,7 +40,7 @@ class AttrNameOrValue extends DOMNode { private final DOMAttr ownerAttr; public AttrNameOrValue(int start, int end, DOMAttr ownerAttr) { - super(start, end, ownerAttr.getOwnerDocument()); + super(start, end); this.ownerAttr = ownerAttr; } @@ -64,7 +64,7 @@ public DOMAttr(String name, DOMNode ownerElement) { } public DOMAttr(String name, int start, int end, DOMNode ownerElement) { - super(-1, -1, ownerElement.getOwnerDocument()); + super(-1, -1); this.name = name; this.nodeAttrName = start != -1 ? new AttrNameOrValue(start, end, this) : null; this.ownerElement = ownerElement; diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMCDATASection.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMCDATASection.java index 977ef8a5b..22c21a118 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMCDATASection.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMCDATASection.java @@ -21,8 +21,8 @@ public class DOMCDATASection extends DOMText implements CDATASection { int startContent; int endContent; - public DOMCDATASection(int start, int end, DOMDocument ownerDocument) { - super(start, end, ownerDocument); + public DOMCDATASection(int start, int end) { + super(start, end); } @Override diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMCharacterData.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMCharacterData.java index b6b811d6c..5144548ed 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMCharacterData.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMCharacterData.java @@ -34,8 +34,8 @@ public abstract class DOMCharacterData extends DOMNode implements org.w3c.dom.Ch private String delimiter; - public DOMCharacterData(int start, int end, DOMDocument ownerDocument) { - super(start, end, ownerDocument); + public DOMCharacterData(int start, int end) { + super(start, end); } public boolean hasMultiLine() { diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMComment.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMComment.java index 35897aee0..cb58fd159 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMComment.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMComment.java @@ -22,8 +22,8 @@ public class DOMComment extends DOMCharacterData implements org.w3c.dom.Comment int endContent; - public DOMComment(int start, int end, DOMDocument ownerDocument) { - super(start, end, ownerDocument); + public DOMComment(int start, int end) { + super(start, end); } public boolean isCommentSameLineEndTag() { diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMDocument.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMDocument.java index 8aa791189..1b75e0600 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMDocument.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMDocument.java @@ -57,7 +57,7 @@ public class DOMDocument extends DOMNode implements Document { private boolean hasExternalGrammar; public DOMDocument(TextDocument textDocument, URIResolverExtensionManager resolverExtensionManager) { - super(0, textDocument.getText().length(), null); + super(0, textDocument.getText().length()); this.textDocument = textDocument; this.resolverExtensionManager = resolverExtensionManager; resetGrammar(); @@ -364,23 +364,23 @@ private static String getPrefixedName(String prefix, String localName) { } public DOMElement createElement(int start, int end) { - return new DOMElement(start, end, this); + return new DOMElement(start, end); } public DOMCDATASection createCDataSection(int start, int end) { - return new DOMCDATASection(start, end, this); + return new DOMCDATASection(start, end); } public DOMProcessingInstruction createProcessingInstruction(int start, int end) { - return new DOMProcessingInstruction(start, end, this); + return new DOMProcessingInstruction(start, end); } public DOMComment createComment(int start, int end) { - return new DOMComment(start, end, this); + return new DOMComment(start, end); } public DOMText createText(int start, int end) { - return new DOMText(start, end, this); + return new DOMText(start, end); } public DOMDocumentType createDocumentType(int start, int end) { diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMElement.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMElement.java index 5d4e4e88c..d18cfc32e 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMElement.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMElement.java @@ -39,8 +39,8 @@ public class DOMElement extends DOMNode implements org.w3c.dom.Element { int endTagCloseOffset = NULL_VALUE;// //DomElement.end = | , is always scanner.getTokenEnd() - public DOMElement(int start, int end, DOMDocument ownerDocument) { - super(start, end, ownerDocument); + public DOMElement(int start, int end) { + super(start, end); } /* diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMNode.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMNode.java index f2ae11800..f8190476c 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMNode.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMNode.java @@ -66,7 +66,6 @@ public abstract class DOMNode implements Node { int end; // | DOMNode parent; - private final DOMDocument ownerDocument; class XMLNodeList extends ArrayList implements NodeList { @@ -135,15 +134,26 @@ public T setNamedItemNS(org.w3c.dom.Node arg0) throws DOMException { } - public DOMNode(int start, int end, DOMDocument ownerDocument) { + public DOMNode(int start, int end) { this.start = start; this.end = end; - this.ownerDocument = ownerDocument; this.closed = false; } + /** + * Returns the owner document and null otherwise. + * + * @return the owner document and null otherwise. + */ public DOMDocument getOwnerDocument() { - return ownerDocument; + Node node = parent; + while (node != null) { + if (node.getNodeType() == Node.DOCUMENT_NODE) { + return (DOMDocument) node; + } + node = node.getParentNode(); + } + return null; } @Override @@ -409,7 +419,8 @@ public boolean isClosed() { public DOMElement getParentElement() { DOMNode parent = getParentNode(); - while (parent != null && parent != getOwnerDocument()) { + DOMDocument ownerDocument = getOwnerDocument(); + while (parent != null && parent != ownerDocument) { if (parent.isElement()) { return (DOMElement) parent; } @@ -418,10 +429,6 @@ public DOMElement getParentElement() { return null; } - public String getNodeAsString() { - return ownerDocument.getText().substring(start, end); - } - public boolean isComment() { return getNodeType() == DOMNode.COMMENT_NODE; } diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMProcessingInstruction.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMProcessingInstruction.java index 36e5ee97b..3c1655204 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMProcessingInstruction.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMProcessingInstruction.java @@ -26,8 +26,8 @@ public class DOMProcessingInstruction extends DOMCharacterData implements org.w3 int endContent; int endTagOpenOffset = NULL_VALUE; - public DOMProcessingInstruction(int start, int end, DOMDocument ownerDocument) { - super(start, end, ownerDocument); + public DOMProcessingInstruction(int start, int end) { + super(start, end); } public boolean isProlog() { diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMText.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMText.java index 586bc0275..5d00cc5e5 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMText.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMText.java @@ -18,8 +18,8 @@ */ public class DOMText extends DOMCharacterData implements org.w3c.dom.Text { - public DOMText(int start, int end, DOMDocument ownerDocument) { - super(start, end, ownerDocument); + public DOMText(int start, int end) { + super(start, end); } /* diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DTDDeclNode.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DTDDeclNode.java index 31367d5e7..23eb395cf 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DTDDeclNode.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DTDDeclNode.java @@ -36,13 +36,13 @@ public class DTDDeclNode extends DOMNode{ ArrayList parameters; public DTDDeclNode(int start, int end, DOMDocumentType parentDocumentType) { - super(start, end, parentDocumentType != null ? parentDocumentType.getOwnerDocument() : null); + super(start, end); this.parentDocumentType = parentDocumentType; this.parentDocument = null; } public DTDDeclNode(int start, int end, DOMDocument parentDocumentType) { - super(start, end, parentDocumentType != null ? parentDocumentType : null); + super(start, end); this.parentDocument = parentDocumentType; this.parentDocumentType = null; } diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/dom/DOMParserTest.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/dom/DOMParserTest.java index be8dd7fab..a8a33236d 100644 --- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/dom/DOMParserTest.java +++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/dom/DOMParserTest.java @@ -909,8 +909,8 @@ private static class MockProcessingInstruction extends DOMProcessingInstruction public String content; - public MockProcessingInstruction(int start, int end, DOMDocument ownerDocument) { - super(start, end, ownerDocument); + public MockProcessingInstruction(int start, int end) { + super(start, end); } @Override @@ -923,8 +923,8 @@ private static class MockCDataSection extends DOMCDATASection { public String content; - public MockCDataSection(int start, int end, DOMDocument ownerDocument) { - super(start, end, ownerDocument); + public MockCDataSection(int start, int end) { + super(start, end); } @Override @@ -937,8 +937,8 @@ private static class MockText extends DOMText { public String content; - public MockText(int start, int end, DOMDocument ownerDocument) { - super(start, end, ownerDocument); + public MockText(int start, int end) { + super(start, end); } @Override @@ -951,8 +951,8 @@ private static class MockComment extends DOMComment { public String content; - public MockComment(int start, int end, DOMDocument ownerDocument) { - super(start, end, ownerDocument); + public MockComment(int start, int end) { + super(start, end); } @Override @@ -963,8 +963,8 @@ public String getData() { private static class MockNode extends DOMNode { - public MockNode(int start, int end, DOMDocument ownerDocument) { - super(start, end, ownerDocument); + public MockNode(int start, int end) { + super(start, end); } @Override @@ -982,17 +982,17 @@ public short getNodeType() { private static DOMNode createNode(short nodeType, int start, int end) { switch (nodeType) { case DOMNode.ELEMENT_NODE: - return new DOMElement(start, end, null); + return new DOMElement(start, end); case DOMNode.PROCESSING_INSTRUCTION_NODE: - return new MockProcessingInstruction(start, end, null); + return new MockProcessingInstruction(start, end); case DOMNode.CDATA_SECTION_NODE: - return new MockCDataSection(start, end, null); + return new MockCDataSection(start, end); case DOMNode.TEXT_NODE: - return new MockText(start, end, null); + return new MockText(start, end); case DOMNode.COMMENT_NODE: - return new MockComment(start, end, null); + return new MockComment(start, end); } - return new MockNode(start, end, null); + return new MockNode(start, end); } private static void setRestOfNode(DOMNode n, String tag, Integer endTagStart, boolean closed) {