use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class CustomPreview method value2JSON.
public static Object value2JSON(DebugValue value, InspectorExecutionContext context) {
if (value.isArray()) {
JSONArray json = new JSONArray();
List<DebugValue> array = value.getArray();
if (array.size() == 2 && array.get(0).isReadable() && array.get(1).isReadable() && "object".equals(array.get(0).asString()) && array.get(1).getProperty("config") != null) {
// Child object:
json.put(value2JSON(array.get(0), context));
DebugValue child = array.get(1);
DebugValue object = child.getProperty("object");
DebugValue config = child.getProperty("config");
RemoteObject remoteConfig = context.getRemoteObjectsHandler().getRemote(object);
JSONObject childJSON = remoteConfig.toJSON();
JSONObject customPreview = create(object, config, object.getOriginalLanguage(), context);
if (customPreview != null) {
childJSON.put("customPreview", customPreview);
}
json.put(childJSON);
} else {
for (DebugValue element : array) {
if (element.isReadable()) {
json.put(value2JSON(element, context));
} else {
json.put(InspectorExecutionContext.VALUE_NOT_READABLE);
}
}
}
return json;
} else {
Collection<DebugValue> properties = value.getProperties();
if (properties != null) {
JSONObject json = new JSONObject();
for (DebugValue property : properties) {
try {
if (property.isReadable() && !property.canExecute() && !property.isInternal()) {
Object rawValue = getPrimitiveValue(property);
// Do not allow inner objects
if (rawValue != null) {
json.put(property.getName(), rawValue);
}
}
} catch (DebugException ex) {
if (ex.isInternalError()) {
PrintWriter err = context.getErr();
if (err != null) {
ex.printStackTrace(err);
}
} else {
throw ex;
}
}
}
return json;
} else {
return getPrimitiveValue(value);
}
}
}
use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class Params method createConsoleAPICalled.
public static Params createConsoleAPICalled(String type, Object text, long contextId) {
JSONObject params = new JSONObject();
params.put("type", type);
JSONArray args = new JSONArray();
if (text != null) {
JSONObject outObject = new JSONObject();
if (InteropLibrary.getUncached().isString(text)) {
outObject.put("type", "string");
} else if (text instanceof Number) {
outObject.put("type", "number");
}
outObject.put("value", text);
args.put(outObject);
}
params.put("args", args);
params.put("executionContextId", contextId);
params.put("timestamp", System.nanoTime() / 1000_000.0);
return new Params(params);
}
use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class WorkspaceEdit method getChanges.
/**
* Holds changes to existing resources.
*/
public Map<String, List<TextEdit>> getChanges() {
final JSONObject json = jsonData.optJSONObject("changes");
if (json == null) {
return null;
}
final Map<String, List<TextEdit>> map = new HashMap<>(json.length());
for (String key : json.keySet()) {
final JSONArray jsonArr = json.getJSONArray(key);
final List<TextEdit> list = new ArrayList<>(jsonArr.length());
for (int i = 0; i < json.length(); i++) {
list.add(new TextEdit(jsonArr.getJSONObject(i)));
}
map.put(key, Collections.unmodifiableList(list));
}
return map;
}
use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class WorkspaceEditClientCapabilities method getResourceOperations.
/**
* The resource operations the client supports. Clients should at least support 'create',
* 'rename' and 'delete' files and folders.
*
* @since 3.13.0
*/
public List<ResourceOperationKind> getResourceOperations() {
final JSONArray json = jsonData.optJSONArray("resourceOperations");
if (json == null) {
return null;
}
final List<ResourceOperationKind> list = new ArrayList<>(json.length());
for (int i = 0; i < json.length(); i++) {
list.add(ResourceOperationKind.get(json.getString(i)));
}
return Collections.unmodifiableList(list);
}
use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class WorkspaceEditClientCapabilities method setResourceOperations.
public WorkspaceEditClientCapabilities setResourceOperations(List<ResourceOperationKind> resourceOperations) {
if (resourceOperations != null) {
final JSONArray json = new JSONArray();
for (ResourceOperationKind resourceOperationKind : resourceOperations) {
json.put(resourceOperationKind.getStringValue());
}
jsonData.put("resourceOperations", json);
}
return this;
}
Aggregations