Skip to content

Commit

Permalink
resolves #71
Browse files Browse the repository at this point in the history
  • Loading branch information
nimakarimipour committed Sep 15, 2022
1 parent 5f57920 commit acad35b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/edu/ucr/cs/riple/core/Annotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* The main class of the core module. Responsible for analyzing the target module and injecting the
Expand Down Expand Up @@ -185,7 +184,7 @@ private void executeNextIteration(
Set<Fix> selectedFixes =
latestReports.stream()
.filter(Report::approved)
.flatMap(report -> config.chain ? report.tree.stream() : Stream.of(report.root))
.flatMap(report -> report.getSelectedFixes(config))
.collect(Collectors.toSet());
injector.injectFixes(selectedFixes);

Expand Down
25 changes: 25 additions & 0 deletions core/src/main/java/edu/ucr/cs/riple/core/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Container class to store information regarding effectiveness of a fix, its associated fix tree
Expand Down Expand Up @@ -247,4 +248,28 @@ public boolean isInProgress(Config config) {
return (!finished && (!config.bailout || localEffect > 0))
|| triggeredFixes.stream().anyMatch(input -> !input.fixSourceIsInTarget);
}

/**
* Returns the stream of fixes that needs to be applied to source code if report is tagged as
* {@link Tag#APPROVE}.
*
* @param config Annotator config.
* @return Stream of selected fixes.
*/
public Stream<Fix> getSelectedFixes(Config config) {
return tree.stream()
.filter(
input -> {
// If chain is active, add all fixes
if (config.chain) {
return true;
}
// Add all fixes reported from downstream
if (!input.fixSourceIsInTarget) {
return true;
}
// Add root.
return input.equals(root);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ public void updateTriggered(Collection<Fix> fixes) {
/** Merges triggered fixes to the tree, to prepare the analysis for the next depth. */
public void mergeTriggered() {
this.tree.addAll(this.triggeredFixes);
this.tree.forEach(fix -> fix.fixSourceIsInTarget = true);
this.triggeredFixes.clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class CoreTestHelper {
private boolean downstreamDependencyAnalysisActivated = false;
private AnalysisMode mode = AnalysisMode.LOCAL;
private Config config;
private boolean chain = true;

public CoreTestHelper(Path projectPath, Path outDirPath, List<String> modules) {
this.projectPath = projectPath;
Expand Down Expand Up @@ -150,6 +151,11 @@ public CoreTestHelper enableDownstreamDependencyAnalysis() {
return enableDownstreamDependencyAnalysis(AnalysisMode.LOWER_BOUND);
}

public CoreTestHelper applyRootFixOnly() {
this.chain = false;
return this;
}

public void start() {
Path configPath = outDirPath.resolve("config.json");
createFiles();
Expand Down Expand Up @@ -264,7 +270,7 @@ private void makeAnnotatorConfigFile(Path configPath) {
builder.outputDir = outDirPath.toString();
builder.depth = depth;
builder.bailout = !disableBailout;
builder.chain = true;
builder.chain = chain;
builder.outerLoopActivation = requestCompleteLoop;
builder.optimized = true;
builder.downStreamDependenciesAnalysisActivated = downstreamDependencyAnalysisActivated;
Expand Down

0 comments on commit acad35b

Please sign in to comment.