Search in sources :

Example 11 with JsonValue

use of org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue 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 12 with JsonValue

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

the class JSONSchemaNode method resolveReferences.

private void resolveReferences(JsonObject json) {
    Iterator<Member> members = json.iterator();
    while (members.hasNext()) {
        Member member = members.next();
        JsonValue value = member.getValue();
        resolveReferences(json, member.getName(), value);
    }
}
Also used : JsonValue(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue)

Example 13 with JsonValue

use of org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue 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 14 with JsonValue

use of org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue 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 15 with JsonValue

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

the class HttpCompletionProposalCollector method addProposals.

@Override
public void addProposals(ContentAssistRequest contentAssistRequest, CompletionProposalInvocationContext context, TargetType target) {
    String url = getUrl(contentAssistRequest, target);
    try {
        JsonValue json = HttpHelper.makeRequest(url);
        addProposals(json, contentAssistRequest, context, target);
    } catch (IOException e) {
        Logger.logException(e);
    }
}
Also used : JsonValue(org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue) IOException(java.io.IOException)

Aggregations

JsonValue (org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue)16 JsonArray (org.eclipse.json.provisonnal.com.eclipsesource.json.JsonArray)10 JsonObject (org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject)7 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 IJSONPair (org.eclipse.wst.json.core.document.IJSONPair)3 InputStreamReader (java.io.InputStreamReader)2 JSONSchemaType (org.eclipse.json.schema.JSONSchemaType)2 Image (org.eclipse.swt.graphics.Image)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 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 StatusLine (org.apache.http.StatusLine)1 HttpClient (org.apache.http.client.HttpClient)1 HttpGet (org.apache.http.client.methods.HttpGet)1