Search in sources :

Example 6 with JsonObject

use of org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject in project webtools.sourceediting by eclipse.

the class JSONSchemaNode method resolveReferences.

private void resolveReferences(JsonObject parent, String name, JsonValue value) {
    if (value instanceof JsonObject) {
        JsonObject json = value.asObject();
        String ref = json.getString(REF, null);
        if (ref != null && ref.startsWith(DEFINITIONS)) {
            String r = ref.substring(DEFINITIONS.length());
            JsonValue v = definitions.get(r);
            parent.set(name, v);
        // json.remove(REF);
        } else {
            Iterator<Member> members = json.iterator();
            while (members.hasNext()) {
                Member member = members.next();
                JsonValue v = member.getValue();
                resolveReferences(json, member.getName(), v);
            }
        }
    } else if (value instanceof JsonArray) {
        JsonArray jsonArray = (JsonArray) value;
        for (int i = 0; i < jsonArray.size(); i++) {
            JsonValue item = jsonArray.get(i);
            if (item instanceof JsonObject) {
                JsonObject json = item.asObject();
                String ref = json.getString(REF, null);
                if (ref != null && ref.startsWith(DEFINITIONS)) {
                    String r = ref.substring(DEFINITIONS.length());
                    JsonValue v = definitions.get(r);
                    jsonArray.set(i, v);
                } else {
                    resolveReferences(json);
                }
            }
        }
    }
}
Also used : JsonArray(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonArray) JsonValue(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue) JsonObject(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject)

Example 7 with JsonObject

use of org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject in project webtools.sourceediting by eclipse.

the class JSONSchemaNode method walk.

private void walk(JsonObject json, IJSONSchemaNode schemaNode) {
    JsonObject properties = (JsonObject) json.get(PROPERTIES);
    addProperties(schemaNode, properties);
    add(json, schemaNode, ALL_OF);
    add(json, schemaNode, ANY_OF);
    add(json, schemaNode, ONE_OF);
    JsonValue notMember = json.get(NOT);
    if (notMember != null) {
        walk(notMember.asObject(), schemaNode);
    }
}
Also used : JsonValue(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue) JsonObject(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject)

Example 8 with JsonObject

use of org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject in project webtools.sourceediting by eclipse.

the class BowerDependencyCompletionProposalCollector method addProposals.

protected void addProposals(JsonValue json, ContentAssistRequest contentAssistRequest, CompletionProposalInvocationContext context, TargetType target) {
    if (json.isArray()) {
        // Ex :
        // [{"name":"angular-mocks","url":"git://github.com/angular/bower-angular-mocks.git"},
        // {"name":"angular-moment","url":"git://github.com/urish/angular-moment.git"}]
        String dependency = null;
        String replacementString = null;
        JsonArray values = (JsonArray) json;
        for (JsonValue value : values) {
            if (value.isObject()) {
                dependency = ((JsonObject) value).get("name").asString();
                replacementString = ContentAssistHelper.getRequiredName(dependency, JSONSchemaType.String);
                Image icon = BowerEditorPluginImageHelper.getInstance().getImage(BowerEditorPluginImages.IMG_OBJ_BOWER);
                JSONKeyCompletionProposal proposal = new JSONKeyCompletionProposal(replacementString, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), replacementString.length() - 2, icon, dependency, null, null, JSONRelevanceConstants.R_OBJECT_KEY);
                contentAssistRequest.addProposal(proposal);
            }
        }
    }
// System.err.println(json);
}
Also used : JsonArray(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonArray) JSONKeyCompletionProposal(org.eclipse.wst.json.ui.contentassist.JSONKeyCompletionProposal) JsonValue(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue) JsonObject(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject) Image(org.eclipse.swt.graphics.Image)

Example 9 with JsonObject

use of org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject in project webtools.sourceediting by eclipse.

the class NPMDependencyCompletionProposalCollector method addProposals.

protected void addProposals(JsonValue json, ContentAssistRequest contentAssistRequest, CompletionProposalInvocationContext context, TargetType target) {
    if (json.isArray()) {
        // Ex :
        // [{"value":"express"},{"value":"lodash"},{"value":"gulp"}]
        String dependency = null;
        String replacementString = null;
        JsonArray values = (JsonArray) json;
        for (JsonValue value : values) {
            if (value.isObject()) {
                dependency = ((JsonObject) value).get("value").asString();
                replacementString = ContentAssistHelper.getRequiredName(dependency, JSONSchemaType.String);
                Image icon = NPMEditorPluginImageHelper.getInstance().getImage(NPMEditorPluginImages.IMG_OBJ_NPM);
                JSONKeyCompletionProposal proposal = new JSONKeyCompletionProposal(replacementString, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), replacementString.length() - 2, icon, dependency, null, null, JSONRelevanceConstants.R_OBJECT_KEY);
                contentAssistRequest.addProposal(proposal);
            }
        }
    }
// System.err.println(json);
}
Also used : JsonArray(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonArray) JSONKeyCompletionProposal(org.eclipse.wst.json.ui.contentassist.JSONKeyCompletionProposal) JsonValue(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue) JsonObject(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject) Image(org.eclipse.swt.graphics.Image)

Aggregations

JsonObject (org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject)9 JsonValue (org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue)7 JsonArray (org.eclipse.json.provisonnal.com.eclipsesource.json.JsonArray)5 IJSONSchemaProperty (org.eclipse.json.schema.IJSONSchemaProperty)2 Image (org.eclipse.swt.graphics.Image)2 IJSONPair (org.eclipse.wst.json.core.document.IJSONPair)2 IJSONValue (org.eclipse.wst.json.core.document.IJSONValue)2 JSONKeyCompletionProposal (org.eclipse.wst.json.ui.contentassist.JSONKeyCompletionProposal)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 JSONSchemaType (org.eclipse.json.schema.JSONSchemaType)1 IJSONNode (org.eclipse.wst.json.core.document.IJSONNode)1 IJSONObject (org.eclipse.wst.json.core.document.IJSONObject)1 JSONValidationInfo (org.eclipse.wst.json.core.internal.validation.JSONValidationInfo)1 ICatalogElement (org.eclipse.wst.json.core.schema.catalog.ICatalogElement)1 ICatalogEntry (org.eclipse.wst.json.core.schema.catalog.ICatalogEntry)1