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

edu.umd.cs.findbugs.sarif.Result 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 result object in {@code run.results} property. (§3.14.23)
 * @see 3.27 result object
 */
final class Result {
    final String ruleId;
    final int ruleIndex;
    final Message message;
    final List locations;
    @NonNull
    final Level level;

    Result(@NonNull String ruleId, int ruleIndex, Message message, List locations, @NonNull Level level) {
        this.ruleId = Objects.requireNonNull(ruleId);
        this.ruleIndex = ruleIndex;
        this.message = Objects.requireNonNull(message);
        this.locations = Collections.unmodifiableList(Objects.requireNonNull(locations));
        this.level = Objects.requireNonNull(level);
    }

    JsonObject toJsonObject() {
        JsonObject result = new JsonObject();
        result.addProperty("ruleId", ruleId);
        result.addProperty("ruleIndex", ruleIndex);
        result.add("message", message.toJsonObject());
        result.addProperty("level", level.toJsonString());

        JsonArray locationArray = new JsonArray();
        locations.stream().map(Location::toJsonObject).forEach(location -> locationArray.add(location));
        if (locationArray.size() > 0) {
            result.add("locations", locationArray);
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy