Search in sources :

Example 1 with IJSONDocument

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;
}
Also used : IJSONDocument(org.eclipse.wst.json.core.document.IJSONDocument) IJSONNode(org.eclipse.wst.json.core.document.IJSONNode)

Example 2 with IJSONDocument

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;
}
Also used : IJSONCleanupStrategy(org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy) IJSONModel(org.eclipse.wst.json.core.document.IJSONModel) IJSONDocument(org.eclipse.wst.json.core.document.IJSONDocument)

Example 3 with IJSONDocument

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();
}
Also used : IJSONDocument(org.eclipse.wst.json.core.document.IJSONDocument) IJSONNode(org.eclipse.wst.json.core.document.IJSONNode)

Example 4 with IJSONDocument

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();
    }
}
Also used : IJSONDocument(org.eclipse.wst.json.core.document.IJSONDocument) IJSONNode(org.eclipse.wst.json.core.document.IJSONNode)

Example 5 with IJSONDocument

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) IJSONPair(org.eclipse.wst.json.core.document.IJSONPair) IJSONValue(org.eclipse.wst.json.core.document.IJSONValue) IJSONDocument(org.eclipse.wst.json.core.document.IJSONDocument) IJSONNode(org.eclipse.wst.json.core.document.IJSONNode) IJSONSchemaProcessor(org.eclipse.json.schema.IJSONSchemaProcessor) URL(java.net.URL)

Aggregations

IJSONDocument (org.eclipse.wst.json.core.document.IJSONDocument)10 IJSONModel (org.eclipse.wst.json.core.document.IJSONModel)4 IJSONNode (org.eclipse.wst.json.core.document.IJSONNode)4 Preferences (org.eclipse.core.runtime.Preferences)2 IJSONPair (org.eclipse.wst.json.core.document.IJSONPair)2 IJSONSourceFormatter (org.eclipse.wst.json.core.internal.format.IJSONSourceFormatter)2 JSONFormatUtil (org.eclipse.wst.json.core.internal.format.JSONFormatUtil)2 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 DocumentRewriteSession (org.eclipse.jface.text.DocumentRewriteSession)1 DocumentRewriteSessionType (org.eclipse.jface.text.DocumentRewriteSessionType)1 IDocumentExtension4 (org.eclipse.jface.text.IDocumentExtension4)1 Region (org.eclipse.jface.text.Region)1 IJSONSchemaProcessor (org.eclipse.json.schema.IJSONSchemaProcessor)1