use of org.eclipse.wst.json.core.document.IJSONNode in project webtools.sourceediting by eclipse.
the class JSONContentOutlineConfiguration method getFilteredNode.
private Object getFilteredNode(Object o) {
IJSONNode node = null;
if (o instanceof IJSONNode) {
node = (IJSONNode) o;
if (node.getOwnerPairNode() != null) {
IJSONPair owner = node.getOwnerPairNode();
IJSONValue value = owner.getValue();
if (!(value instanceof IJSONArray)) {
return node.getOwnerPairNode();
}
}
/*
* short nodeType = node.getNodeType(); if (node instanceof
* IJSONValue) { while (node != null && !(node instanceof
* IJSONStyleDeclItem)) { node = node.getParentNode(); } } else if
* (nodeType == IJSONNode.STYLEDECLARATION_NODE) { node =
* node.getParentNode(); } else if (nodeType ==
* IJSONNode.MEDIALIST_NODE) { node = node.getParentNode(); }
*/
}
return node;
}
use of org.eclipse.wst.json.core.document.IJSONNode in project webtools.sourceediting by eclipse.
the class JSONFoldingStrategy method calcNewFoldPosition.
/**
* @see org.eclipse.wst.sse.ui.internal.projection.AbstractFoldingStrategy#calcNewFoldPosition(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)
*/
protected Position calcNewFoldPosition(IndexedRegion indexedRegion) {
Position retPos = null;
// only want to fold regions of the valid type and with a valid range
if (indexedRegion.getStartOffset() >= 0 && indexedRegion.getLength() >= 0) {
IJSONNode node = (IJSONNode) indexedRegion;
IStructuredDocumentRegion startRegion = node.getStartStructuredDocumentRegion();
IStructuredDocumentRegion endRegion = node.getEndStructuredDocumentRegion();
// don't fold it
if (startRegion != null && endRegion != null) {
if (startRegion.getEndOffset() == endRegion.getStartOffset())
return null;
if (endRegion.getEndOffset() >= startRegion.getStartOffset() && endRegion.getEndOffset() <= getDocument().getLength())
retPos = new JSONObjectFoldingPosition(startRegion, endRegion);
}
// else if(startRegion != null && indexedRegion instanceof
// CommentImpl) {
// retPos = new JSONCommentFoldingPosition(startRegion);
// }
}
return retPos;
}
use of org.eclipse.wst.json.core.document.IJSONNode in project webtools.sourceediting by eclipse.
the class JSONSourceFormatterFactory method getSourceFormatter.
public IJSONSourceFormatter getSourceFormatter(INodeNotifier target) {
IJSONNode node = (IJSONNode) target;
short type = node.getNodeType();
switch(type) {
case IJSONNode.DOCUMENT_NODE:
return JSONDocumentFormatter.getInstance();
case IJSONNode.OBJECT_NODE:
return JSONObjectFormatter.getInstance();
case IJSONNode.ARRAY_NODE:
return JSONArrayFormatter.getInstance();
case IJSONNode.PAIR_NODE:
return JSONPairFormatter.getInstance();
default:
return UnknownRuleFormatter.getInstance();
}
}
use of org.eclipse.wst.json.core.document.IJSONNode 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);
// }
}
use of org.eclipse.wst.json.core.document.IJSONNode 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);
// }
}
Aggregations