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);
}
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations