Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nimakarimipour committed Oct 9, 2024
1 parent 5e3437e commit 214f73b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public String toString() {
+ ", "
+ root
+ ", "
+ tree.stream().map(Fix::toLocations).collect(Collectors.toSet());
+ tree;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import edu.ucr.cs.riple.core.module.ModuleInfo;
import edu.ucr.cs.riple.core.registries.index.ErrorStore;
import edu.ucr.cs.riple.core.registries.index.Fix;
import edu.ucr.cs.riple.injector.changes.AddMarkerAnnotation;
import edu.ucr.cs.riple.injector.location.Location;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -68,19 +66,9 @@ public AbstractConflictGraphProcessor(Context context, CompilerRunner runner, Su
* @param node Node in process.
*/
protected Set<Fix> getTriggeredFixesFromDownstreamErrors(Node node) {
Set<Location> currentLocationsTargetedByTree =
node.tree.stream().flatMap(fix -> fix.toLocations().stream()).collect(Collectors.toSet());
return downstreamImpactCache.getTriggeredErrorsForCollection(node.tree).stream()
.filter(
error ->
error.isSingleAnnotationFix()
&& error.isFixableOnTarget(context)
&& !currentLocationsTargetedByTree.contains(error.toResolvingLocation()))
.map(
error ->
new Fix(
new AddMarkerAnnotation(
error.toResolvingLocation(), context.config.nullableAnnot)))
.filter(error -> error.isFixableOnTarget(context))
.flatMap(error -> error.getResolvingFixes().stream())
.collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.common.collect.ImmutableSet;
import edu.ucr.cs.riple.core.Context;
import edu.ucr.cs.riple.core.registries.field.FieldRegistry;
import edu.ucr.cs.riple.core.registries.index.Fix;
import edu.ucr.cs.riple.core.registries.index.NonnullStore;
import edu.ucr.cs.riple.core.registries.method.MethodRegistry;
import edu.ucr.cs.riple.core.registries.region.CompoundRegionRegistry;
Expand Down Expand Up @@ -156,10 +157,10 @@ public ImmutableSet<ModuleConfiguration> getModuleConfigurations() {
}

/**
* Checks if the passed location is declared in this moduleInfo's modules.
* Checks if the passed location is declared in containing modules.
*
* @param location The location to check.
* @return True if the passed location is declared in this moduleInfo's modules, false otherwise.
* @return True if the passed location is declared in containing modules., false otherwise.
*/
public boolean declaredInModule(Location location) {
if (location.isOnParameter()) {
Expand All @@ -174,6 +175,17 @@ public boolean declaredInModule(Location location) {
return methodRegistry.declaredInModule(location);
}

/**
* Checks if the passed fix contains only annotation changes on elements declared in the
* containing modules.
*
* @param fix The Fix to check.
* @return True if the passed fix contains annotation changes only on containing modules.
*/
public boolean declaredInModule(Fix fix) {
return fix.changes.stream().allMatch(annot -> declaredInModule(annot.getLocation()));
}

/**
* Creates a {@link edu.ucr.cs.riple.injector.location.OnClass} instance targeting the passed
* classes flat name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ public boolean equals(Object o) {
* @return true, if error is resolvable via fixes on target module.
*/
public boolean isFixableOnTarget(Context context) {
return this.resolvingFixes.stream()
.flatMap(fix -> fix.changes.stream())
.allMatch(change -> context.targetModuleInfo.declaredInModule(change.getLocation()));
return this.resolvingFixes.stream().allMatch(context.targetModuleInfo::declaredInModule);
}

@Override
Expand Down

0 comments on commit 214f73b

Please sign in to comment.