All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.umd.cs.findbugs.sarif.Message Maven / Gradle / Ivy

There is a newer version: 4.8.6
Show newest version
package edu.umd.cs.findbugs.sarif;

import edu.umd.cs.findbugs.annotations.NonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonArray;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * Object which represents {@code message} property.
 * @see 3.11 message object
 */
final class Message {
    String text;

    @NonNull
    final List arguments;

    Message(@NonNull List arguments) {
        this.arguments = Collections.unmodifiableList(Objects.requireNonNull(arguments));
    }

    JsonObject toJsonObject() {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("id", "default");

        if (text != null) {
            jsonObject.addProperty("text", text);
        }

        JsonArray jsonArray = new JsonArray();
        for (String arg : arguments) {
            jsonArray.add(arg);
        }
        if (jsonArray.size() > 0) {
            jsonObject.add("arguments", jsonArray);
        }
        return jsonObject;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy