Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
nimakarimipour committed Jan 10, 2025
1 parent 7dfe19c commit b75f387
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
24 changes: 12 additions & 12 deletions annotator-core/src/main/java/edu/ucr/cs/riple/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
Expand Down Expand Up @@ -650,7 +649,7 @@ private <T> Config.OrElse<T> getValueFromKey(JsonObject json, String key, Class<
}

private <T> ListOrElse<T> getArrayValueFromKey(
JsonObject json, String key, Function<JsonObject, T> mapper, Class<T> klass) {
JsonObject json, String key, Function<JsonObject, T> mapper, Class<T> klass) {
if (json == null) {
return new ListOrElse<>(null, klass);
}
Expand All @@ -660,8 +659,10 @@ private <T> ListOrElse<T> getArrayValueFromKey(
} else {
if (jsonValue.value instanceof JsonArray) {
return new ListOrElse<>(
StreamSupport.stream(((JsonArray) jsonValue.value).spliterator(), false).map(JsonElement::getAsJsonObject).map(mapper), klass
);
StreamSupport.stream(((JsonArray) jsonValue.value).spliterator(), false)
.map(JsonElement::getAsJsonObject)
.map(mapper),
klass);
}
throw new IllegalStateException(
"Expected type to be json array, found: " + jsonValue.value.getClass());
Expand Down Expand Up @@ -765,14 +766,13 @@ public void write(Path path) {
json.addProperty("INFERENCE_ACTIVATION", inferenceActivated);
json.addProperty("LANGUAGE_LEVEL", languageLevel.name().split("_")[1]);
JsonArray configPathsJson = new JsonArray();
configPaths
.forEach(
info -> {
JsonObject res = new JsonObject();
res.addProperty("CHECKER", info.checkerConfig.toString());
res.addProperty("SCANNER", info.scannerConfig.toString());
configPathsJson.add(res);
});
configPaths.forEach(
info -> {
JsonObject res = new JsonObject();
res.addProperty("CHECKER", info.checkerConfig.toString());
res.addProperty("SCANNER", info.scannerConfig.toString());
configPathsJson.add(res);
});
json.add("CONFIG_PATHS", configPathsJson);
JsonObject downstreamDependency = new JsonObject();
downstreamDependency.addProperty("ACTIVATION", downStreamDependenciesAnalysisActivated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@

package edu.ucr.cs.riple.core.module;

import com.google.gson.JsonObject;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

import com.google.gson.JsonObject;

/** Container class to hold paths to checker and scanner config files. */
public class ModuleConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,21 @@ public static void writeReports(Context context, ImmutableSet<Report> reports) {
JsonObject result = new JsonObject();
JsonArray reportsJson = new JsonArray();
// Sort reports based on the overall effect in descending order.
List<Report> sorted = reports.stream().sorted((r1, r2) -> Integer.compare(r2.getOverallEffect(context.config), r1.getOverallEffect(context.config))).collect(Collectors.toList());
List<Report> sorted =
reports.stream()
.sorted(
(r1, r2) ->
Integer.compare(
r2.getOverallEffect(context.config), r1.getOverallEffect(context.config)))
.collect(Collectors.toList());
for (Report report : sorted) {
JsonObject reportJson = report.root.getJson();
reportJson.addProperty("LOCAL EFFECT", report.localEffect);
reportJson.addProperty("OVERALL EFFECT", report.getOverallEffect(context.config));
reportJson.addProperty("Upper Bound EFFECT", report.getUpperBoundEffectOnDownstreamDependencies());
reportJson.addProperty("Lower Bound EFFECT", report.getLowerBoundEffectOnDownstreamDependencies());
reportJson.addProperty(
"Upper Bound EFFECT", report.getUpperBoundEffectOnDownstreamDependencies());
reportJson.addProperty(
"Lower Bound EFFECT", report.getLowerBoundEffectOnDownstreamDependencies());
reportJson.addProperty("FINISHED", !report.requiresFurtherProcess(context.config));
JsonArray followUps = new JsonArray();
if (context.config.chain && report.localEffect < 1) {
Expand Down Expand Up @@ -299,12 +307,14 @@ public static List<String> readFileLines(Path path) {

/**
* Parses a file in json format and returns as a JsonObject.
*
* @param path The path to the file.
* @return The JsonObject parsed from the file.
*/
public static JsonObject parseJson(Path path) {
try {
return JsonParser.parseReader(Files.newBufferedReader(path, Charset.defaultCharset())).getAsJsonObject();
return JsonParser.parseReader(Files.newBufferedReader(path, Charset.defaultCharset()))
.getAsJsonObject();
} catch (Exception e) {
throw new RuntimeException("Error in reading/parsing context at path: " + path, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

package edu.ucr.cs.riple.injector.location;

import com.google.gson.JsonObject;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

/** A visitor that converts a location to a JSON object. */
public class LocationToJsonVisitor implements LocationVisitor<JsonObject, Void> {
Expand Down Expand Up @@ -81,7 +81,9 @@ public JsonObject visitClass(OnClass onClass, Void unused) {
@Override
public JsonObject visitLocalVariable(OnLocalVariable onLocalVariable, Void unused) {
JsonObject res = defaultAction(onLocalVariable);
res.addProperty(KEYS.METHOD.name(), onLocalVariable.encMethod == null ? "" : onLocalVariable.encMethod.method);
res.addProperty(
KEYS.METHOD.name(),
onLocalVariable.encMethod == null ? "" : onLocalVariable.encMethod.method);
res.addProperty(KEYS.VARIABLES.name(), onLocalVariable.varName);
return res;
}
Expand Down

0 comments on commit b75f387

Please sign in to comment.