Search in sources :

Example 71 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project intellij-plugins by JetBrains.

the class RemoteAnalysisServerImpl method processResponse.

private void processResponse(JsonObject response) throws Exception {
    // handle notification
    if (processNotification(response)) {
        return;
    }
    // prepare ID
    JsonPrimitive idJsonPrimitive = (JsonPrimitive) response.get("id");
    if (idJsonPrimitive == null) {
        return;
    }
    String idString = idJsonPrimitive.getAsString();
    // prepare consumer
    Consumer consumer;
    synchronized (consumerMapLock) {
        consumer = consumerMap.get(idString);
    }
    JsonObject errorObject = (JsonObject) response.get("error");
    RequestError requestError = null;
    if (errorObject != null) {
        requestError = processErrorResponse(errorObject);
        listener.requestError(requestError);
    }
    // handle result
    JsonObject resultObject = (JsonObject) response.get("result");
    //
    if (consumer instanceof UpdateContentConsumer) {
        ((UpdateContentConsumer) consumer).onResponse();
    } else //
    if (consumer instanceof GetSuggestionsConsumer) {
        new CompletionIdProcessor((GetSuggestionsConsumer) consumer).process(resultObject, requestError);
    } else //
    if (consumer instanceof FindElementReferencesConsumer) {
        new FindElementReferencesProcessor((FindElementReferencesConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof FindMemberDeclarationsConsumer) {
        new FindMemberDeclarationsProcessor((FindMemberDeclarationsConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof FindMemberReferencesConsumer) {
        new FindMemberReferencesProcessor((FindMemberReferencesConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof FindTopLevelDeclarationsConsumer) {
        new FindTopLevelDeclarationsProcessor((FindTopLevelDeclarationsConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof GetTypeHierarchyConsumer) {
        new TypeHierarchyProcessor((GetTypeHierarchyConsumer) consumer).process(resultObject, requestError);
    } else //
    if (consumer instanceof FormatConsumer) {
        new FormatProcessor((FormatConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof GetHoverConsumer) {
        new HoverProcessor((GetHoverConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof GetRefactoringConsumer) {
        new GetRefactoringProcessor(requestToRefactoringKindMap, (GetRefactoringConsumer) consumer).process(idString, resultObject, requestError);
    } else if (consumer instanceof GetAssistsConsumer) {
        new AssistsProcessor((GetAssistsConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof GetFixesConsumer) {
        new FixesProcessor((GetFixesConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof GetStatementCompletionConsumer) {
        new StatementCompletionProcessor((GetStatementCompletionConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof GetLibraryDependenciesConsumer) {
        new LibraryDependenciesProcessor((GetLibraryDependenciesConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof GetNavigationConsumer) {
        new GetNavigationProcessor((GetNavigationConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof GetAvailableRefactoringsConsumer) {
        new RefactoringGetAvailableProcessor((GetAvailableRefactoringsConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof GetErrorsConsumer) {
        new AnalysisErrorsProcessor((GetErrorsConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof OrganizeDirectivesConsumer) {
        new OrganizeDirectivesProcessor((OrganizeDirectivesConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof SortMembersConsumer) {
        new SortMembersProcessor((SortMembersConsumer) consumer).process(resultObject, requestError);
    } else //
    if (consumer instanceof CreateContextConsumer) {
        new CreateContextProcessor((CreateContextConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof MapUriConsumer) {
        new MapUriProcessor((MapUriConsumer) consumer).process(resultObject, requestError);
    } else //
    if (consumer instanceof GetServerPortConsumer) {
        new GetServerPortProcessor((GetServerPortConsumer) consumer).process(resultObject, requestError);
    } else //
    if (consumer instanceof GetVersionConsumer) {
        new VersionProcessor((GetVersionConsumer) consumer).process(resultObject, requestError);
    } else if (consumer instanceof BasicConsumer) {
        ((BasicConsumer) consumer).received();
    }
    synchronized (consumerMapLock) {
        consumerMap.remove(idString);
    }
}
Also used : JsonObject(com.google.gson.JsonObject) JsonPrimitive(com.google.gson.JsonPrimitive) RequestError(org.dartlang.analysis.server.protocol.RequestError)

Example 72 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project intellij-plugins by JetBrains.

the class ExtractMethodFeedback method toJson.

public JsonObject toJson() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("offset", offset);
    jsonObject.addProperty("length", length);
    jsonObject.addProperty("returnType", returnType);
    JsonArray jsonArrayNames = new JsonArray();
    for (String elt : names) {
        jsonArrayNames.add(new JsonPrimitive(elt));
    }
    jsonObject.add("names", jsonArrayNames);
    jsonObject.addProperty("canCreateGetter", canCreateGetter);
    JsonArray jsonArrayParameters = new JsonArray();
    for (RefactoringMethodParameter elt : parameters) {
        jsonArrayParameters.add(elt.toJson());
    }
    jsonObject.add("parameters", jsonArrayParameters);
    JsonArray jsonArrayOffsets = new JsonArray();
    for (int elt : offsets) {
        jsonArrayOffsets.add(new JsonPrimitive(elt));
    }
    jsonObject.add("offsets", jsonArrayOffsets);
    JsonArray jsonArrayLengths = new JsonArray();
    for (int elt : lengths) {
        jsonArrayLengths.add(new JsonPrimitive(elt));
    }
    jsonObject.add("lengths", jsonArrayLengths);
    return jsonObject;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 73 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project intellij-plugins by JetBrains.

the class ContextData method toJson.

public JsonObject toJson() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("name", name);
    jsonObject.addProperty("explicitFileCount", explicitFileCount);
    jsonObject.addProperty("implicitFileCount", implicitFileCount);
    jsonObject.addProperty("workItemQueueLength", workItemQueueLength);
    JsonArray jsonArrayCacheEntryExceptions = new JsonArray();
    for (String elt : cacheEntryExceptions) {
        jsonArrayCacheEntryExceptions.add(new JsonPrimitive(elt));
    }
    jsonObject.add("cacheEntryExceptions", jsonArrayCacheEntryExceptions);
    return jsonObject;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 74 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project streamsx.topology by IBMStreams.

the class GraphUtilities method removeOperators.

static void removeOperators(Collection<JsonObject> operators, JsonObject graph) {
    for (JsonObject iso : operators) {
        // Get parents and children of operator
        Set<JsonObject> operatorParents = GraphUtilities.getUpstream(iso, graph);
        Set<JsonObject> operatorChildren = GraphUtilities.getDownstream(iso, graph);
        JsonArray operatorOutputs = array(iso, "outputs");
        // Get the output name of the operator
        String operatorOutName = "";
        if (operatorOutputs != null) {
            JsonObject operatorFirstOutput = operatorOutputs.get(0).getAsJsonObject();
            if (operatorFirstOutput != null) {
                operatorOutName = jstring(operatorFirstOutput, "name");
            }
        }
        // Also get input names
        List<String> operatorInNames = new ArrayList<>();
        inputs(iso, input -> operatorInNames.add(jstring(input, "name")));
        // Respectively, the names of the child and parent input and
        // output ports connected to the operator.
        List<String> childInputPortNames = new ArrayList<>();
        List<String> parentOutputPortNames = new ArrayList<>();
        // References to the list of connections for the parent and child
        // output and input ports that are connected to the $isolate$
        // operator.
        List<JsonArray> childConnections = new ArrayList<>();
        List<JsonArray> parentConnections = new ArrayList<>();
        // operator;
        for (JsonObject child : operatorChildren) {
            JsonArray inputs = child.get("inputs").getAsJsonArray();
            for (JsonElement inputObj : inputs) {
                JsonObject input = inputObj.getAsJsonObject();
                JsonArray connections = input.get("connections").getAsJsonArray();
                for (JsonElement connectionObj : connections) {
                    String connection = connectionObj.getAsString();
                    if (connection.equals(operatorOutName)) {
                        childInputPortNames.add(jstring(input, "name"));
                        childConnections.add(connections);
                        connections.remove(connectionObj);
                        break;
                    }
                }
            }
        }
        // $Isolate$ operator;
        for (JsonObject parent : operatorParents) {
            JsonArray outputs = parent.get("outputs").getAsJsonArray();
            for (JsonElement outputObj : outputs) {
                JsonObject output = outputObj.getAsJsonObject();
                JsonArray connections = output.get("connections").getAsJsonArray();
                for (JsonElement connectionObj : connections) {
                    String connection = connectionObj.getAsString();
                    if (operatorInNames.contains(connection)) {
                        parentOutputPortNames.add(jstring(output, "name"));
                        parentConnections.add(connections);
                        connections.remove(connectionObj);
                        break;
                    }
                }
            }
        }
        // Connect child to parents
        for (JsonArray childConnection : childConnections) {
            for (String name : parentOutputPortNames) childConnection.add(new JsonPrimitive(name));
        }
        // Connect parent to children
        for (JsonArray parentConnection : parentConnections) {
            for (String name : childInputPortNames) parentConnection.add(new JsonPrimitive(name));
        }
        JsonArray ops = graph.get("operators").getAsJsonArray();
        ops.remove(iso);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Example 75 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project streamsx.topology by IBMStreams.

the class OperatorGenerator method getHostPoolName.

/**
     * Gets or creates a host pool at the graphConfig level corresponding to the
     * unique set of tags.
     */
private static String getHostPoolName(JsonObject graphConfig, Set<String> uniqueResourceTags) {
    JsonArray hostPools = array(graphConfig, "__spl_hostPools");
    if (hostPools == null) {
        graphConfig.add("__spl_hostPools", hostPools = new JsonArray());
    }
    // Look for a host pool matching this one
    for (JsonElement hpe : hostPools) {
        JsonObject hostPoolDef = hpe.getAsJsonObject();
        JsonArray rta = hostPoolDef.get("resourceTags").getAsJsonArray();
        Set<String> poolResourceTags = new HashSet<>();
        for (JsonElement tage : rta) poolResourceTags.add(tage.getAsString());
        if (uniqueResourceTags.equals(poolResourceTags)) {
            return jstring(hostPoolDef, "name");
        }
    }
    JsonObject hostPoolDef = new JsonObject();
    String hostPool;
    hostPoolDef.addProperty("name", hostPool = "__jaaHostPool" + hostPools.size());
    JsonArray rta = new JsonArray();
    for (String tag : uniqueResourceTags) rta.add(new JsonPrimitive(tag));
    hostPoolDef.add("resourceTags", rta);
    hostPools.add(hostPoolDef);
    return hostPool;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) HashSet(java.util.HashSet)

Aggregations

JsonPrimitive (com.google.gson.JsonPrimitive)168 JsonArray (com.google.gson.JsonArray)103 JsonObject (com.google.gson.JsonObject)78 Test (org.testng.annotations.Test)56 JsonElement (com.google.gson.JsonElement)47 Test (org.junit.Test)12 Map (java.util.Map)9 Matchers.anyString (org.mockito.Matchers.anyString)8 JsonProcessorInjectionMap (com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap)7 Gson (com.google.gson.Gson)5 JsonParser (com.google.gson.JsonParser)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 GsonBuilder (com.google.gson.GsonBuilder)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Matcher (java.util.regex.Matcher)3 LobWrapper (angularBeans.io.LobWrapper)2 DatasetCreationSpec (co.cask.cdap.internal.dataset.DatasetCreationSpec)2 IRenderState (com.builtbroken.mc.client.json.imp.IRenderState)2