Search in sources :

Example 16 with JsonValue

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

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