Search in sources :

Example 61 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class StructuredTextPartitioner method internalGetPartition.

/**
 * Returns the partition containing the given character position of the
 * given document. The document has previously been connected to the
 * partitioner. If the checkBetween parameter is true, an offset between a
 * start and end tag will return a zero-length region.
 */
private void internalGetPartition(int offset, boolean checkBetween) {
    if (fStructuredDocument == null) {
        // $NON-NLS-1$
        throw new IllegalStateException("document partitioner is not connected");
    }
    boolean partitionFound = false;
    int docLength = fStructuredDocument.getLength();
    // get document region type and map to partition type :
    // Note: a partion can be smaller than a flatnode, if that flatnode
    // contains a region container.
    // That's why we need to get "relevent region".
    IStructuredDocumentRegion structuredDocumentRegion = fStructuredDocument.getRegionAtCharacterOffset(offset);
    // this is king of a "normal case" for empty document
    if (structuredDocumentRegion == null) {
        if (docLength == 0) {
            /*
				 * In order to prevent infinite error loops, this partition
				 * must never have a zero length unless the document is also
				 * zero length
				 */
            setInternalPartition(offset, 0, getDefaultPartitionType());
            partitionFound = true;
        } else {
            /*
				 * This case is "unusual". When would region be null, and
				 * document longer than 0. I think this means something's "out
				 * of sync". And we may want to "flag" that fact and just
				 * return one big region of 'unknown', instead of one
				 * character at a time.
				 */
            setInternalPartition(offset, 1, getUnknown());
            partitionFound = true;
        }
    } else if (checkBetween) {
        // else
        if (structuredDocumentRegion.getStartOffset() == offset) {
            IStructuredDocumentRegion previousStructuredDocumentRegion = getParserSpecificPreviousRegion(structuredDocumentRegion);
            if (previousStructuredDocumentRegion != null) {
                ITextRegion next = structuredDocumentRegion.getRegionAtCharacterOffset(offset);
                ITextRegion previousStart = previousStructuredDocumentRegion.getRegionAtCharacterOffset(previousStructuredDocumentRegion.getStartOffset());
                partitionFound = doParserSpecificCheck(offset, partitionFound, structuredDocumentRegion, previousStructuredDocumentRegion, next, previousStart);
            }
        }
    }
    if (!partitionFound && structuredDocumentRegion != null) {
        /* We want the actual ITextRegion and not a possible ITextRegionCollection that
			 * could be returned by IStructuredDocumentRegion#getRegionAtCharacterOffset
			 * This allows for correct syntax highlighting and content assist.
			 */
        DeepRegion resultRegion = getDeepRegionAtCharacterOffset(structuredDocumentRegion, offset);
        partitionFound = isDocumentRegionBasedPartition(structuredDocumentRegion, resultRegion.region, offset);
        if (!partitionFound) {
            if (resultRegion.region != null) {
                String type = getPartitionType(resultRegion.region, offset);
                setInternalPartition(offset, resultRegion.end - offset, type);
            } else {
                // can happen at EOF
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=224886
                // The unknown type was causing problems with content assist in JSP documents
                setInternalPartition(offset, 1, getDefaultPartitionType());
            }
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 62 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class JSONModelUpdater method insertStructuredDocumentRegion.

/**
 */
private void insertStructuredDocumentRegion(IStructuredDocumentRegion newStructuredDocumentRegion) {
    if (newStructuredDocumentRegion == null)
        // error
        return;
    if (this.parentNode == null)
        // error
        return;
    int newOffset = newStructuredDocumentRegion.getStart();
    int newEnd = newStructuredDocumentRegion.getEnd();
    boolean isEndTag = false;
    // find owner node
    JSONNodeImpl ownerNode = null;
    while (this.parentNode != null) {
        if (this.nextNode != null) {
            IStructuredDocumentRegion nextStructuredDocumentRegion = this.nextNode.getStructuredDocumentRegion();
            if (nextStructuredDocumentRegion != null) {
                int nextOffset = nextStructuredDocumentRegion.getStart();
                if (nextOffset == newOffset) {
                    // found
                    ownerNode = this.nextNode;
                    break;
                }
            // if (this.nextNode.getNodeType() == Node.TEXT_NODE) {
            // int nextEnd = nextStructuredDocumentRegion.getEnd();
            // if (nextOffset < newEnd && nextEnd > newOffset) {
            // ownerNode = this.nextNode;
            // break;
            // }
            // }
            }
            IJSONNode child = this.nextNode.getFirstChild();
            if (child != null) {
                this.parentNode = this.nextNode;
                this.nextNode = (JSONNodeImpl) child;
                continue;
            }
            if (this.nextNode.getNodeType() == IJSONNode.OBJECT_NODE) {
                this.parentNode = this.nextNode;
                this.nextNode = null;
                continue;
            }
            this.nextNode = (JSONNodeImpl) this.nextNode.getNextSibling();
            if (this.nextNode != null)
                continue;
        }
        if (this.parentNode.getNodeType() == IJSONNode.OBJECT_NODE) {
            IJSONObject element = (IJSONObject) this.parentNode;
            IStructuredDocumentRegion endStructuredDocumentRegion = element.getEndStructuredDocumentRegion();
            if (endStructuredDocumentRegion != null) {
                int endOffset = endStructuredDocumentRegion.getStart();
                if (endOffset == newOffset) {
                    // found
                    ownerNode = this.parentNode;
                    isEndTag = true;
                    break;
                }
            }
        }
        this.nextNode = (JSONNodeImpl) this.parentNode.getNextSibling();
        this.parentNode = (JSONNodeImpl) this.parentNode.getParentNode();
    }
    if (ownerNode == null)
        throw new StructuredDocumentRegionManagementException();
    short nodeType = ownerNode.getNodeType();
    if (nodeType == IJSONNode.OBJECT_NODE) {
        JSONObjectImpl element = (JSONObjectImpl) ownerNode;
        if (isEndTag) {
            element.setEndStructuredDocumentRegion(newStructuredDocumentRegion);
        } else {
            element.setStartStructuredDocumentRegion(newStructuredDocumentRegion);
            updateAttrRegions(element, newStructuredDocumentRegion);
        }
    } else
        // if (nodeType == Node.TEXT_NODE) {
        // TextImpl text = (TextImpl) ownerNode;
        // IStructuredDocumentRegion oldStructuredDocumentRegion = text
        // .getStructuredDocumentRegion();
        // if (oldStructuredDocumentRegion == null) {
        // throw new StructuredDocumentRegionManagementException();
        // }
        // int oldOffset = oldStructuredDocumentRegion.getStart();
        // int oldEnd = oldStructuredDocumentRegion.getEnd();
        // if (oldOffset == newOffset && oldEnd == newEnd) {
        // text.setStructuredDocumentRegion(newStructuredDocumentRegion);
        // return;
        // }
        // 
        // if (oldStructuredDocumentRegion instanceof StructuredDocumentRegionProxy) {
        // StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) oldStructuredDocumentRegion;
        // if (oldEnd > newEnd) {
        // StructuredDocumentRegionContainer container = new StructuredDocumentRegionContainer();
        // if (oldOffset == newOffset) {
        // container
        // .appendStructuredDocumentRegion(newStructuredDocumentRegion);
        // } else {
        // StructuredDocumentRegionProxy newProxy = new StructuredDocumentRegionProxy();
        // newProxy.setOffset(oldOffset);
        // newProxy.setLength(newEnd - oldOffset);
        // newProxy.setStructuredDocumentRegion(newStructuredDocumentRegion);
        // container.appendStructuredDocumentRegion(newProxy);
        // }
        // proxy.setOffset(newEnd);
        // proxy.setLength(oldEnd - newEnd);
        // container.appendStructuredDocumentRegion(proxy);
        // text.setStructuredDocumentRegion(container);
        // } else {
        // proxy.setStructuredDocumentRegion(newStructuredDocumentRegion);
        // 
        // if (oldEnd < newEnd) { // to be shared
        // this.nextNode = (JSONNodeImpl) text.getNextSibling();
        // insertStructuredDocumentRegion(newStructuredDocumentRegion);
        // }
        // }
        // return;
        // }
        // 
        // if (oldStructuredDocumentRegion instanceof StructuredDocumentRegionContainer) {
        // StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) oldStructuredDocumentRegion;
        // int count = container.getStructuredDocumentRegionCount();
        // for (int i = 0; i < count; i++) {
        // IStructuredDocumentRegion content = container
        // .getStructuredDocumentRegion(i);
        // if (content == null)
        // continue; // error
        // int offset = content.getStart();
        // int end = content.getEnd();
        // if (end <= newOffset)
        // continue;
        // if (offset == newOffset && end == newEnd) {
        // container.replaceStructuredDocumentRegion(
        // newStructuredDocumentRegion, i);
        // return;
        // }
        // 
        // if (content instanceof StructuredDocumentRegionProxy) {
        // StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) content;
        // if (end > newEnd) {
        // if (offset == newOffset) {
        // container.insertStructuredDocumentRegion(
        // newStructuredDocumentRegion, i);
        // } else {
        // StructuredDocumentRegionProxy newProxy = new StructuredDocumentRegionProxy();
        // newProxy.setOffset(offset);
        // newProxy.setLength(newEnd - offset);
        // newProxy.setStructuredDocumentRegion(newStructuredDocumentRegion);
        // container.insertStructuredDocumentRegion(
        // newProxy, i);
        // }
        // proxy.setOffset(newEnd);
        // proxy.setLength(end - newEnd);
        // return;
        // } else {
        // proxy.setStructuredDocumentRegion(newStructuredDocumentRegion);
        // if (end == newEnd)
        // return;
        // }
        // }
        // }
        // 
        // if (oldEnd < newEnd) { // to be shared
        // this.nextNode = (JSONNodeImpl) text.getNextSibling();
        // insertStructuredDocumentRegion(newStructuredDocumentRegion);
        // }
        // return;
        // } else {
        // throw new StructuredDocumentRegionManagementException();
        // }
        // } else {
        ownerNode.setStructuredDocumentRegion(newStructuredDocumentRegion);
// }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IJSONObject(org.eclipse.wst.json.core.document.IJSONObject) IJSONNode(org.eclipse.wst.json.core.document.IJSONNode)

Example 63 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class JSONModelUpdater method changeStructuredDocumentRegion.

private void changeStructuredDocumentRegion(IStructuredDocumentRegion oldStructuredDocumentRegion) {
    if (oldStructuredDocumentRegion == null)
        // error
        return;
    if (this.parentNode == null)
        // error
        return;
    int oldOffset = oldStructuredDocumentRegion.getStart();
    int oldEnd = oldStructuredDocumentRegion.getEnd();
    boolean isEndTag = false;
    // find owner node
    JSONNodeImpl ownerNode = null;
    while (this.parentNode != null) {
        if (this.nextNode != null) {
            IStructuredDocumentRegion nextStructuredDocumentRegion = this.nextNode.getStructuredDocumentRegion();
            if (nextStructuredDocumentRegion != null) {
                if (nextStructuredDocumentRegion == oldStructuredDocumentRegion) {
                    ownerNode = this.nextNode;
                    break;
                }
                int nextOffset = nextStructuredDocumentRegion.getStart();
                if (nextOffset == oldOffset) {
                    // found
                    ownerNode = this.nextNode;
                    break;
                }
            // if (this.nextNode.getNodeType() == Node.TEXT_NODE) {
            // TextImpl text = (TextImpl) this.nextNode;
            // if (text.hasStructuredDocumentRegion(oldStructuredDocumentRegion)) {
            // ownerNode = this.nextNode;
            // break;
            // }
            // int nextEnd = nextStructuredDocumentRegion.getEnd();
            // if (nextOffset < oldEnd && nextEnd > oldOffset) {
            // ownerNode = this.nextNode;
            // break;
            // }
            // }
            }
            IJSONNode child = this.nextNode.getFirstChild();
            if (child != null) {
                this.parentNode = this.nextNode;
                this.nextNode = (JSONNodeImpl) child;
                continue;
            }
            if (this.nextNode.getNodeType() == IJSONNode.OBJECT_NODE) {
                this.parentNode = this.nextNode;
                this.nextNode = null;
                continue;
            }
            this.nextNode = (JSONNodeImpl) this.nextNode.getNextSibling();
            if (this.nextNode != null)
                continue;
        }
        if (this.parentNode.getNodeType() == IJSONNode.OBJECT_NODE) {
            IJSONObject element = (IJSONObject) this.parentNode;
            IStructuredDocumentRegion endStructuredDocumentRegion = element.getEndStructuredDocumentRegion();
            if (endStructuredDocumentRegion != null) {
                if (endStructuredDocumentRegion == oldStructuredDocumentRegion) {
                    ownerNode = this.parentNode;
                    isEndTag = true;
                    break;
                }
                int endOffset = endStructuredDocumentRegion.getStart();
                if (endOffset == oldOffset) {
                    // found
                    ownerNode = this.parentNode;
                    isEndTag = true;
                    break;
                }
            }
        }
        this.nextNode = (JSONNodeImpl) this.parentNode.getNextSibling();
        this.parentNode = (JSONNodeImpl) this.parentNode.getParentNode();
    }
    if (ownerNode == null)
        throw new StructuredDocumentRegionManagementException();
    short nodeType = ownerNode.getNodeType();
    if (nodeType == IJSONNode.OBJECT_NODE) {
        JSONObjectImpl element = (JSONObjectImpl) ownerNode;
        if (isEndTag) {
            element.setEndStructuredDocumentRegion(oldStructuredDocumentRegion);
        } else {
            element.setStartStructuredDocumentRegion(oldStructuredDocumentRegion);
            updateAttrRegions(element, oldStructuredDocumentRegion);
        }
    } else
        /*if (nodeType == Node.TEXT_NODE) {
			TextImpl text = (TextImpl) ownerNode;

			IStructuredDocumentRegion flatNode = text
					.getStructuredDocumentRegion();
			if (flatNode == oldStructuredDocumentRegion) {
				int newOffset = oldOffset;
				int newEnd = oldEnd;
				if (oldOffset == this.gapOffset) {
					newOffset += this.diff;
				} else {
					newEnd = this.gapOffset;
				}
				int newLength = newEnd - newOffset;
				IStructuredDocumentRegion newStructuredDocumentRegion = new StructuredDocumentRegionProxy(
						newOffset, newLength, oldStructuredDocumentRegion);
				text.setStructuredDocumentRegion(newStructuredDocumentRegion);

				if (oldEnd > newEnd) {
					this.nextNode = (JSONNodeImpl) text.getNextSibling();
					changeStructuredDocumentRegion(oldStructuredDocumentRegion);
				}
				return;
			}

			if (flatNode instanceof StructuredDocumentRegionProxy) {
				StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) flatNode;
				int offset = proxy.getOffset();
				int end = offset + proxy.getLength();
				if (proxy.getStructuredDocumentRegion() == null) {
					if (offset == oldOffset && end == oldEnd) {
						text.setStructuredDocumentRegion(oldStructuredDocumentRegion);
					} else {
						if (end > oldEnd) {
							StructuredDocumentRegionContainer container = new StructuredDocumentRegionContainer();
							container
									.appendStructuredDocumentRegion(oldStructuredDocumentRegion);
							proxy.setOffset(oldEnd);
							proxy.setLength(end - oldEnd);
							container.appendStructuredDocumentRegion(proxy);
							text.setStructuredDocumentRegion(container);
						} else {
							proxy.setStructuredDocumentRegion(oldStructuredDocumentRegion);

							if (end < oldEnd) { // to be shared
								this.nextNode = (JSONNodeImpl) text
										.getNextSibling();
								changeStructuredDocumentRegion(oldStructuredDocumentRegion);
							}
						}
					}
					return;
				}

				if (offset >= this.gapOffset) {
					proxy.setOffset(offset + this.diff);
					end += this.diff;
				}
				if (end < oldEnd) { // to be shared
					this.nextNode = (JSONNodeImpl) text.getNextSibling();
					changeStructuredDocumentRegion(oldStructuredDocumentRegion);
					return;
				}
			} else if (flatNode instanceof StructuredDocumentRegionContainer) {
				StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
				int count = container.getStructuredDocumentRegionCount();
				for (int i = 0; i < count; i++) {
					IStructuredDocumentRegion content = container
							.getStructuredDocumentRegion(i);
					if (content == null)
						continue; // error
					if (content == oldStructuredDocumentRegion) {
						int newOffset = oldOffset;
						int newEnd = oldEnd;
						if (oldOffset == this.gapOffset) {
							newOffset += this.diff;
						} else {
							newEnd = this.gapOffset;
						}
						int newLength = newEnd - newOffset;
						IStructuredDocumentRegion newStructuredDocumentRegion = new StructuredDocumentRegionProxy(
								newOffset, newLength,
								oldStructuredDocumentRegion);
						container.replaceStructuredDocumentRegion(
								newStructuredDocumentRegion, i);

						if (oldEnd > newEnd) { // to be shared
							this.nextNode = (JSONNodeImpl) text.getNextSibling();
							changeStructuredDocumentRegion(oldStructuredDocumentRegion);
						}
						return;
					}

					if (content instanceof StructuredDocumentRegionProxy) {
						StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) content;
						int offset = proxy.getOffset();
						int end = offset + proxy.getLength();
						if (end <= oldOffset)
							continue;
						if (proxy.getStructuredDocumentRegion() == null) {
							if (offset == oldOffset && end == oldEnd) {
								container.replaceStructuredDocumentRegion(
										oldStructuredDocumentRegion, i);
							} else {
								if (end > oldEnd) {
									container.insertStructuredDocumentRegion(
											oldStructuredDocumentRegion, i);
									proxy.setOffset(oldEnd);
									proxy.setLength(end - oldEnd);
								} else {
									proxy.setStructuredDocumentRegion(oldStructuredDocumentRegion);

									if (end < oldEnd) { // to be shared
										this.nextNode = (JSONNodeImpl) text
												.getNextSibling();
										changeStructuredDocumentRegion(oldStructuredDocumentRegion);
									}
								}
							}
							return;
						}

						if (offset >= this.gapOffset) {
							proxy.setOffset(offset + this.diff);
							end += this.diff;
						}
						if (end < oldEnd) { // to be shared
							this.nextNode = (JSONNodeImpl) text.getNextSibling();
							changeStructuredDocumentRegion(oldStructuredDocumentRegion);
							return;
						}
					}
				}
			} else {
				throw new StructuredDocumentRegionManagementException();
			}
		} else {*/
        ownerNode.setStructuredDocumentRegion(oldStructuredDocumentRegion);
// }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IJSONObject(org.eclipse.wst.json.core.document.IJSONObject) IJSONNode(org.eclipse.wst.json.core.document.IJSONNode)

Example 64 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class JSONModelUpdater method replaceChild.

/**
 * replaceChild method
 *
 * @param parentNode
 *            org.w3c.dom.Node
 * @param newChild
 *            org.w3c.dom.Node
 * @param oldChild
 *            org.w3c.dom.Node
 */
void replaceChild(IJSONNode parentNode, IJSONNode newChild, IJSONNode oldChild) {
    if (parentNode == null)
        return;
    if (newChild == null && oldChild == null)
        return;
    if (getStructuredDocument() == null)
        return;
    int start = 0;
    int end = 0;
    String preTag = null;
    String postTag = null;
    JSONObjectImpl postIJSONObject = null;
    if (oldChild != null) {
        JSONNodeImpl node = (JSONNodeImpl) oldChild;
        start = node.getStartOffset();
        end = node.getEndOffset();
        // if (oldChild.getNodeType() == Node.TEXT_NODE) {
        // this.gapStructuredDocumentRegion = node
        // .getStructuredDocumentRegion();
        // }
        // reset values from
        node.resetStructuredDocumentRegions();
    // IStructuredDocumentRegion
    } else {
        JSONNodeImpl prev = (JSONNodeImpl) newChild.getPreviousSibling();
        if (prev != null) {
            start = prev.getEndOffset();
            end = start;
        // preTag = getCloseTag(prev);
        } else {
            // first child
            JSONNodeImpl next = (JSONNodeImpl) newChild.getNextSibling();
            if (next != null) {
                start = next.getStartOffset();
                end = start;
                if (parentNode.getNodeType() == IJSONNode.OBJECT_NODE) {
                // preTag = getStartCloseTag((IJSONIJSONObject) parentNode);
                }
            } else {
                // newly having a child
                if (parentNode.getNodeType() == IJSONNode.OBJECT_NODE) {
                    IJSONObject element = (IJSONObject) parentNode;
                // if (element.isEmptyTag()
                // || isSelfClosedContainer(element)) { // empty
                // // tag
                // // format
                // // need to generate the start and the end tags
                // end = element.getEndOffset();
                // start = end - 2; // for "/>"
                // element.setEmptyTag(false);
                // preTag = this.generator.generateCloseTag(element);
                // postTag = this.generator.generateEndTag(element);
                // postIJSONObject = element;
                // }
                // else if (!element.hasStartTag()) {
                // start = element.getStartOffset();
                // end = start;
                // // invalid end tag or implicit tag
                // // need to generate the start tag
                // preTag = this.generator.generateStartTag(element);
                // if (preTag != null) {
                // int length = preTag.length();
                // if (length > 0) {
                // IStructuredDocumentRegion flatNode = new StructuredDocumentRegionProxy(
                // start, length);
                // element.setStartStructuredDocumentRegion(flatNode);
                // }
                // }
                // if (!element.hasEndTag()) {
                // // implicit tag
                // // need to generate the end tags
                // postTag = this.generator
                // .generateEndTag(element);
                // postIJSONObject = element;
                // }
                // } else {
                // start = element.getStartEndOffset();
                // end = start;
                // preTag = getStartCloseTag(element);
                // if (preTag != null && preTag.length() > 0) {
                // if (!element.hasEndTag()
                // && (element.isJSPContainer() || element
                // .isCDATAContainer())) {
                // // need to generate the end tag
                // postTag = this.generator
                // .generateEndTag(element);
                // postIJSONObject = element;
                // }
                // }
                // }
                }
            // else might DOCUMENT_NODE, start and end are 0
            }
        }
    }
    String source = null;
    if (newChild != null) {
        StringBuffer buffer = new StringBuffer();
        int offset = start;
        if (preTag != null) {
            int length = preTag.length();
            if (length > 0) {
                offset += length;
                buffer.append(preTag);
            }
        }
        JSONNodeImpl node = (JSONNodeImpl) newChild;
        while (node != null) {
            if (node.getNodeType() == IJSONNode.OBJECT_NODE) {
                JSONObjectImpl element = (JSONObjectImpl) node;
                // if (element.preferEmptyTag())
                // element.setEmptyTag(true);
                IStructuredDocumentRegion flatNode = null;
                String startTag = this.generator.generateStartTag(element);
                if (startTag != null) {
                    int length = startTag.length();
                    if (length > 0) {
                        buffer.append(startTag);
                        flatNode = new StructuredDocumentRegionProxy(offset, length);
                        offset += length;
                    }
                }
                element.setStartStructuredDocumentRegion(flatNode);
            } else {
                String content = this.generator.generateSource(node);
                if (content == null)
                    content = JSONNodeImpl.EMPTY_STRING;
                int length = content.length();
                IStructuredDocumentRegion flatNode = null;
                if (length > 0) {
                    buffer.append(content);
                    flatNode = new StructuredDocumentRegionProxy(offset, length);
                    offset += length;
                }
                node.setStructuredDocumentRegion(flatNode);
            }
            JSONNodeImpl child = (JSONNodeImpl) node.getFirstChild();
            if (child != null) {
                node = child;
                continue;
            }
            if (node.getNodeType() == IJSONNode.OBJECT_NODE) {
                JSONObjectImpl element = (JSONObjectImpl) node;
                IStructuredDocumentRegion flatNode = null;
                String endTag = this.generator.generateEndTag(element);
                if (endTag != null) {
                    int length = endTag.length();
                    if (length > 0) {
                        buffer.append(endTag);
                        flatNode = new StructuredDocumentRegionProxy(offset, length);
                        offset += length;
                    }
                }
                element.setEndStructuredDocumentRegion(flatNode);
            }
            while (node != null) {
                if (node == newChild) {
                    node = null;
                    break;
                }
                JSONNodeImpl next = (JSONNodeImpl) node.getNextSibling();
                if (next != null) {
                    node = next;
                    break;
                }
                node = (JSONNodeImpl) node.getParentNode();
                if (node.getNodeType() != IJSONNode.OBJECT_NODE)
                    continue;
                JSONObjectImpl element = (JSONObjectImpl) node;
                IStructuredDocumentRegion flatNode = null;
                String endTag = this.generator.generateEndTag(element);
                if (endTag != null) {
                    int length = endTag.length();
                    if (length > 0) {
                        buffer.append(endTag);
                        flatNode = new StructuredDocumentRegionProxy(offset, length);
                        offset += length;
                    }
                }
                element.setEndStructuredDocumentRegion(flatNode);
            }
        }
        if (postTag != null) {
            int length = postTag.length();
            if (length > 0) {
                buffer.append(postTag);
                if (postIJSONObject != null) {
                    IStructuredDocumentRegion flatNode = new StructuredDocumentRegionProxy(offset, length);
                    postIJSONObject.setEndStructuredDocumentRegion(flatNode);
                }
            }
        }
        source = buffer.toString();
    }
    if (start == end && (source == null || source.length() == 0)) {
        // no thing changed
        return;
    }
    replaceSource(source, start, end);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IJSONObject(org.eclipse.wst.json.core.document.IJSONObject)

Example 65 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class JSONObjectImpl method toString.

public String toString() {
    StringBuilder buffer = new StringBuilder();
    // getName();
    String tagName = null;
    if (hasStartTag())
        buffer.append(tagName);
    if (isEmptyTag())
        buffer.append('/');
    if (hasEndTag()) {
        buffer.append('/');
        buffer.append(tagName);
    }
    if (buffer.length() == 0)
        buffer.append(tagName);
    IStructuredDocumentRegion startStructuredDocumentRegion = getStartStructuredDocumentRegion();
    if (startStructuredDocumentRegion != null) {
        buffer.append('@');
        buffer.append(startStructuredDocumentRegion.toString());
    }
    IStructuredDocumentRegion endStructuredDocumentRegion = getEndStructuredDocumentRegion();
    if (endStructuredDocumentRegion != null) {
        buffer.append('@');
        buffer.append(endStructuredDocumentRegion.toString());
    }
    return buffer.toString();
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

Aggregations

IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)439 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)174 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)99 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)87 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)70 List (java.util.List)40 BadLocationException (org.eclipse.jface.text.BadLocationException)39 ArrayList (java.util.ArrayList)38 Iterator (java.util.Iterator)35 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)35 Node (org.w3c.dom.Node)30 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)26 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)19 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)19 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)17 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)15 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)14 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)13 NodeList (org.w3c.dom.NodeList)13