use of org.eclipse.wst.json.core.document.IJSONPair 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.IJSONPair 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.IJSONPair in project webtools.sourceediting by eclipse.
the class Validator method getProperties.
private Set<String> getProperties(IJSONNode node) {
Set<String> properties = new HashSet<String>();
IJSONNode child = node.getFirstChild();
while (child != null) {
if (child instanceof IJSONPair) {
IJSONPair pair = (IJSONPair) child;
if (pair.getName() != null) {
properties.add(pair.getName());
}
}
child = child.getNextSibling();
}
return properties;
}
use of org.eclipse.wst.json.core.document.IJSONPair in project webtools.sourceediting by eclipse.
the class Validator method validateAdditionalProperties.
private void validateAdditionalProperties(IJSONNode node, JsonObject schema, JsonValue value, JSONValidationInfo valinfo) {
if (value != null && value.isBoolean() && !value.asBoolean()) {
Set<String> s = getProperties(node);
Set<String> p = getProperties(schema.get(IJSONSchemaNode.PROPERTIES));
Set<String> pp = getProperties(schema.get(IJSONSchemaNode.PATTERN_PROPERTIES));
for (String string : p) {
if (s.contains(string)) {
s.remove(string);
}
}
for (String patternStr : pp) {
Pattern pattern = Pattern.compile(patternStr);
Iterator<String> iter = s.iterator();
while (iter.hasNext()) {
String ss = iter.next();
if (ss != null) {
Matcher matcher = pattern.matcher(ss);
if (matcher.find()) {
iter.remove();
}
}
}
}
for (String string : s) {
if ("$schema".equals(string)) {
// $NON-NLS-1$
continue;
}
IJSONNode n = node.getFirstChild();
while (n != null) {
if (n instanceof IJSONPair) {
IJSONPair pair = (IJSONPair) n;
if (string.equals(pair.getName())) {
break;
}
}
n = n.getNextSibling();
}
if (n == null) {
node = n;
}
int offset = n.getStartOffset();
int line = n.getModel().getStructuredDocument().getLineOfOffset(offset);
valinfo.addMessage("Property " + string + " is not allowed", line, 0, offset == 0 ? 1 : offset);
}
}
}
use of org.eclipse.wst.json.core.document.IJSONPair in project webtools.sourceediting by eclipse.
the class Validator method validate.
private void validate(IJSONNode node, IJSONSchemaProperty schemaProperty, JSONValidationInfo valinfo) {
if (node == null || schemaProperty == null) {
return;
}
JsonObject schema = schemaProperty.getJsonObject();
validate(node, schema, valinfo);
IJSONNode child = node.getFirstChild();
while (child != null) {
IJSONSchemaProperty property = schemaProperty.getSchemaDocument().getProperty(child.getPath());
validate(child, property, valinfo);
if (child instanceof IJSONPair) {
IJSONValue value = ((IJSONPair) child).getValue();
if (value instanceof IJSONObject) {
IJSONSchemaProperty prop = schemaProperty.getSchemaDocument().getProperty(value.getPath());
validate(value, prop, valinfo);
}
}
child = child.getNextSibling();
}
}
Aggregations