Search in sources :

Example 51 with JSONArray

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;
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) DebugValue(com.oracle.truffle.api.debug.DebugValue) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) Iterator(java.util.Iterator) Collection(java.util.Collection) DebugException(com.oracle.truffle.api.debug.DebugException)

Example 52 with JSONArray

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;
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray)

Example 53 with JSONArray

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);
}
Also used : JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) ArrayList(java.util.ArrayList) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Example 54 with JSONArray

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;
}
Also used : JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Example 55 with JSONArray

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;
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

JSONArray (com.oracle.truffle.tools.utils.json.JSONArray)195 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)85 ArrayList (java.util.ArrayList)74 DebugValue (com.oracle.truffle.api.debug.DebugValue)8 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)8 Collection (java.util.Collection)7 List (java.util.List)7 DebugException (com.oracle.truffle.api.debug.DebugException)6 Source (com.oracle.truffle.api.source.Source)5 SourceSection (com.oracle.truffle.api.source.SourceSection)4 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)4 HashMap (java.util.HashMap)4 Location (com.oracle.truffle.tools.chromeinspector.types.Location)3 Script (com.oracle.truffle.tools.chromeinspector.types.Script)3 CPUSampler (com.oracle.truffle.tools.profiler.CPUSampler)3 CPUSamplerData (com.oracle.truffle.tools.profiler.CPUSamplerData)3 PrintWriter (java.io.PrintWriter)3 Map (java.util.Map)3 TruffleContext (com.oracle.truffle.api.TruffleContext)2 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)2