use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class ObjectPreview method create.
private static JSONObject create(DebugValue debugValue, TYPE type, SUBTYPE subtype, boolean allowToStringSideEffects, LanguageInfo language, PrintWriter err, boolean isMapEntryKV) {
JSONObject json = new JSONObject();
json.put("type", type.getId());
if (subtype != null) {
json.put("subtype", subtype.getId());
}
boolean isArray = debugValue.isArray();
boolean isMap = debugValue.hasHashEntries();
if (isMapEntryKV) {
String valueStr = RemoteObject.toString(debugValue, allowToStringSideEffects, err);
json.putOpt("description", valueStr);
} else {
DebugValue metaObject = RemoteObject.getMetaObject(debugValue, language, err);
String metaType = null;
if (metaObject != null) {
metaType = RemoteObject.toMetaName(metaObject, err);
if (isArray) {
metaType += "(" + debugValue.getArray().size() + ")";
} else if (isMap) {
metaType += "(" + debugValue.getHashSize() + ")";
}
}
json.putOpt("description", metaType);
}
boolean overflow;
JSONArray properties = new JSONArray();
JSONArray entries = new JSONArray();
if (isArray) {
List<DebugValue> array = debugValue.getArray();
int size = array.size();
overflow = size > OVERFLOW_LIMIT_ARRAY_ELEMENTS;
int n = Math.min(size, OVERFLOW_LIMIT_ARRAY_ELEMENTS);
for (int i = 0; i < n; i++) {
try {
properties.put(createPropertyPreview(array.get(i), allowToStringSideEffects, language, err));
} catch (DebugException ex) {
overflow = true;
break;
}
}
} else if (isMap && !isMapEntryKV) {
DebugValue entriesIter = debugValue.getHashEntriesIterator();
overflow = false;
while (entriesIter.hasIteratorNextElement()) {
DebugValue entry = entriesIter.getIteratorNextElement();
JSONObject entryPreview;
try {
entryPreview = createEntryPreview(entry, allowToStringSideEffects, language, err);
} catch (DebugException ex) {
overflow = true;
break;
}
if (entryPreview != null) {
if (entries.length() == OVERFLOW_LIMIT_PROPERTIES) {
overflow = true;
break;
}
entries.put(entryPreview);
}
}
} else {
Collection<DebugValue> valueProperties = debugValue.getProperties();
if (valueProperties != null) {
Iterator<DebugValue> propertyIterator = valueProperties.iterator();
overflow = false;
while (propertyIterator.hasNext()) {
DebugValue property = propertyIterator.next();
if (!property.isInternal() && !property.hasReadSideEffects() && property.isReadable()) {
if (properties.length() == OVERFLOW_LIMIT_PROPERTIES) {
overflow = true;
break;
}
try {
properties.put(createPropertyPreview(property, allowToStringSideEffects, language, err));
} catch (DebugException ex) {
overflow = true;
break;
}
}
}
} else {
overflow = false;
}
}
json.put("overflow", overflow);
json.put("properties", properties);
if (isMap && !isMapEntryKV) {
json.put("entries", entries);
}
return json;
}
use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class ProfileNode method toJSON.
private JSONObject toJSON() {
JSONObject json = new JSONObject();
json.put("id", id);
json.put("callFrame", callFrame.toJSON());
json.put("hitCount", hitCount);
JSONArray array = new JSONArray();
children.forEach(i -> {
array.put(i.intValue());
});
json.put("children", array);
return json;
}
use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class WorkspaceEdit method getDocumentChanges.
/**
* Depending on the client capability `workspace.workspaceEdit.resourceOperations` document
* changes are either an array of `TextDocumentEdit`s to express changes to n different text
* documents where each text document edit addresses a specific version of a text document. Or
* it can contain above `TextDocumentEdit`s mixed with create, rename and delete file / folder
* operations.
*
* Whether a client supports versioned document edits is expressed via
* `workspace.workspaceEdit.documentChanges` client capability.
*
* If a client neither supports `documentChanges` nor
* `workspace.workspaceEdit.resourceOperations` then only plain `TextEdit`s using the `changes`
* property are supported.
*/
public List<Object> getDocumentChanges() {
final JSONArray json = jsonData.optJSONArray("documentChanges");
if (json == null) {
return null;
}
final List<Object> list = new ArrayList<>(json.length());
for (int i = 0; i < json.length(); i++) {
list.add(json.get(i));
}
return Collections.unmodifiableList(list);
}
use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class WorkspaceEdit method setDocumentChanges.
public WorkspaceEdit setDocumentChanges(List<Object> documentChanges) {
if (documentChanges != null) {
final JSONArray json = new JSONArray();
for (Object object : documentChanges) {
json.put(object);
}
jsonData.put("documentChanges", json);
}
return this;
}
use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class WorkspaceEdit method setChanges.
public WorkspaceEdit setChanges(Map<String, List<TextEdit>> changes) {
if (changes != null) {
final JSONObject json = new JSONObject();
for (Map.Entry<String, List<TextEdit>> entry : changes.entrySet()) {
final JSONArray jsonArr = new JSONArray();
for (TextEdit textEdit : entry.getValue()) {
jsonArr.put(textEdit.jsonData);
}
json.put(entry.getKey(), jsonArr);
}
jsonData.put("changes", json);
}
return this;
}
Aggregations