use of org.eclipse.wst.json.core.document.IJSONDocument in project webtools.sourceediting by eclipse.
the class RefreshStructureJob method contains.
/**
* Simple hierarchical containment relationship. Note, this method returns
* "false" if the two nodes are equal!
*
* @param root
* @param possible
* @return if the root is parent of possible, return true, otherwise
* return false
*/
private boolean contains(IJSONNode root, IJSONNode possible) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("==============================================================================================================");
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("recursive call w/ root: " + root.getNodeName() + " and possible: " + possible);
// $NON-NLS-1$
System.out.println("--------------------------------------------------------------------------------------------------------------");
}
// can't contain the child if it's null
if (root == null) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("returning false: root is null");
}
return false;
}
// nothing can be parent of Document node
if (possible instanceof IJSONDocument) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("returning false: possible is Document node");
}
return false;
}
// document contains everything
if (root instanceof IJSONDocument) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("returning true: root is Document node");
}
return true;
}
// check parentage
IJSONNode current = possible;
// loop parents
while ((current != null) && (current.getNodeType() != IJSONNode.DOCUMENT_NODE)) {
// found it
if (root.equals(current)) {
if (DEBUG) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println(" !!! found: " + possible.getNodeName() + " in subelement of: " + root.getNodeName());
}
return true;
}
current = current.getParentNode();
}
// never found it
return false;
}
use of org.eclipse.wst.json.core.document.IJSONDocument in project webtools.sourceediting by eclipse.
the class AbstractJSONSourceFormatter method getCleanupStrategy.
/**
* Insert the method's description here.
*
* @return org.eclipse.wst.css.core.internal.cleanup.JSONCleanupStrategy
* @param node
* org.eclipse.wst.css.core.model.interfaces.IJSONNode
*/
protected IJSONCleanupStrategy getCleanupStrategy(IJSONNode node) {
IJSONCleanupStrategy currentStrategy = JSONCleanupStrategyImpl.getInstance();
IJSONDocument doc = node.getOwnerDocument();
if (doc == null)
return currentStrategy;
IJSONModel model = doc.getModel();
if (model == null)
return currentStrategy;
return currentStrategy;
}
use of org.eclipse.wst.json.core.document.IJSONDocument in project webtools.sourceediting by eclipse.
the class AbstractJSONSourceFormatter method getIndent.
protected String getIndent(IJSONNode node) {
if (node == null)
// $NON-NLS-1$
return "";
IJSONNode parent = node.getParentNode();
if (parent == null || parent instanceof IJSONDocument)
// $NON-NLS-1$
return "";
String parentIndent = getIndent(parent);
return parentIndent + getIndentString();
}
use of org.eclipse.wst.json.core.document.IJSONDocument in project webtools.sourceediting by eclipse.
the class Validator method validate.
private void validate(IJSONModel model, IJSONSchemaProperty schemaProperty, JSONValidationInfo valinfo) {
IJSONDocument document = model.getDocument();
IJSONNode node = document.getFirstChild();
while (node != null) {
validate(node, schemaProperty, valinfo);
node = node.getNextSibling();
}
}
use of org.eclipse.wst.json.core.document.IJSONDocument in project webtools.sourceediting by eclipse.
the class SchemaProcessorRegistryReader method getSchemaDocument.
public IJSONSchemaDocument getSchemaDocument(IJSONModel model) throws IOException {
IJSONSchemaProcessor processor = getDefaultProcessor();
if (processor == null) {
return null;
}
IJSONDocument document = model.getDocument();
IJSONNode jsonObject = document.getFirstChild();
if (jsonObject != null) {
IJSONNode child = jsonObject.getFirstChild();
while (child != null) {
if (child instanceof IJSONPair) {
IJSONPair pair = (IJSONPair) child;
String name = pair.getName();
IJSONValue valueNode = pair.getValue();
if (valueNode != null && "$schema".equals(name)) {
// $NON-NLS-1$
String schema = JSONUtil.getString(valueNode);
try {
if (schema != null) {
schema = URIHelper.addImpliedFileProtocol(schema);
new URL(schema);
return processor.getSchema(schema);
}
} catch (MalformedURLException e) {
}
}
}
child = child.getNextSibling();
}
}
String base = model == null || model.getResolver() == null ? null : model.getResolver().getFileBaseLocation();
// Assert.isNotNull(base, "Base location is expected to be non null."); //$NON-NLS-1$
if (base != null) {
base = URIHelper.addImpliedFileProtocol(base);
}
String schemaURL = resolve(base, null, null);
if (schemaURL != null) {
return processor.getSchema(schemaURL);
}
return null;
}
Aggregations