use of org.eclipse.wst.json.core.document.IJSONArray 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.IJSONArray in project webtools.sourceediting by eclipse.
the class JSONModelImpl method getIndexedRegion.
@Override
public IndexedRegion getIndexedRegion(int offset) {
if (this.document == null)
return null;
// search in document children
IJSONNode parent = null;
int length = this.document.getEndOffset();
if (offset * 2 < length) {
// search from the first
IJSONNode child = (IJSONNode) this.document.getFirstChild();
while (child != null) {
if (child.getEndOffset() <= offset) {
child = (IJSONNode) child.getNextSibling();
continue;
}
if (child.getStartOffset() > offset) {
break;
}
IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
if (startStructuredDocumentRegion != null) {
if (startStructuredDocumentRegion.getEnd() > offset)
return child;
}
IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion();
if (endStructuredDocumentRegion != null) {
if (endStructuredDocumentRegion.getStart() <= offset) {
if (child instanceof IJSONPair) {
IJSONValue value = ((IJSONPair) child).getValue();
if (value instanceof IJSONObject || value instanceof IJSONArray) {
if (value.getStartOffset() < offset) {
child = value;
continue;
}
}
}
return child;
}
}
// dig more
parent = child;
if (parent != null && parent.getNodeType() == IJSONNode.PAIR_NODE) {
IJSONPair pair = (IJSONPair) parent;
child = pair.getValue();
} else {
child = (IJSONNode) parent.getFirstChild();
}
}
} else {
// search from the last
IJSONNode child = (IJSONNode) this.document.getLastChild();
while (child != null) {
if (child.getStartOffset() > offset) {
child = (IJSONNode) child.getPreviousSibling();
continue;
}
if (child.getEndOffset() <= offset) {
break;
}
IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
if (startStructuredDocumentRegion != null) {
if (startStructuredDocumentRegion.getEnd() > offset)
return child;
}
IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion();
if (endStructuredDocumentRegion != null) {
if (endStructuredDocumentRegion.getStart() <= offset) {
if (child instanceof IJSONPair) {
IJSONValue value = ((IJSONPair) child).getValue();
if (value instanceof IJSONObject || value instanceof IJSONArray) {
if (value.getStartOffset() < offset) {
child = value;
continue;
}
}
}
return child;
}
}
// dig more
parent = child;
if (parent != null && parent.getNodeType() == IJSONNode.PAIR_NODE) {
IJSONPair pair = (IJSONPair) parent;
child = pair.getValue();
} else {
child = (IJSONNode) parent.getLastChild();
}
}
}
return parent != null ? parent : document.getFirstChild();
}
use of org.eclipse.wst.json.core.document.IJSONArray in project webtools.sourceediting by eclipse.
the class JSONPairFormatter method formatChildren.
@Override
protected void formatChildren(IJSONNode node, StringBuilder source) {
if (node instanceof IJSONPair) {
IJSONPair pair = (IJSONPair) node;
IJSONValue value = pair.getValue();
if (value instanceof IJSONObject || value instanceof IJSONArray) {
formatObject(node, source, value);
} else {
formatValue(node, source, value);
}
}
}
use of org.eclipse.wst.json.core.document.IJSONArray in project webtools.sourceediting by eclipse.
the class Validator method validateItems.
private void validateItems(IJSONNode node, JsonObject schema, IJSONValue value, JsonValue memberValue, JSONValidationInfo valinfo) {
JsonValue additionalItems = schema.get(IJSONSchemaNode.ADDITIONAL_ITEMS);
if (additionalItems != null && additionalItems.isBoolean() && !additionalItems.asBoolean()) {
if (memberValue != null && memberValue.isArray()) {
if (value instanceof IJSONArray) {
int instanceSize = getSize((IJSONArray) value);
int size = memberValue.asArray().size();
if (instanceSize > size) {
int offset = node.getStartOffset();
int line = node.getModel().getStructuredDocument().getLineOfOffset(offset);
valinfo.addMessage("Array has too many items. Expected " + size + " or fewer", line, 0, offset == 0 ? 1 : offset);
}
}
}
}
}
use of org.eclipse.wst.json.core.document.IJSONArray in project webtools.sourceediting by eclipse.
the class Validator method validateUniqueItems.
private void validateUniqueItems(IJSONNode node, JsonObject schema, IJSONValue value, JsonValue memberValue, JSONValidationInfo valinfo) {
if (memberValue != null && memberValue.isBoolean() && memberValue.asBoolean()) {
if (value instanceof IJSONArray) {
Set<String> instanceValues = new HashSet<String>();
IJSONNode child = value.getFirstChild();
int instanceSize = 0;
while (child != null) {
instanceSize = instanceSize + 1;
instanceValues.add(JSONUtil.getString(child));
child = child.getNextSibling();
}
;
if (instanceSize != instanceValues.size()) {
int offset = node.getStartOffset();
int line = node.getModel().getStructuredDocument().getLineOfOffset(offset);
valinfo.addMessage("Array has duplicate items", line, 0, offset == 0 ? 1 : offset);
}
}
}
}
Aggregations