Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nimakarimipour committed Oct 3, 2024
1 parent 494ada5 commit 3c1a276
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public Node(Fix root) {
public void setOrigins(ErrorStore errorStore) {
this.origins =
ImmutableSet.copyOf(
errorStore.getRegionsForElements(
error -> error.getFixes() != null && error.getFixes().equals(root)));
errorStore.getRegionsForElements(error -> error.getFixes().contains(root)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
import edu.ucr.cs.riple.injector.changes.AddMarkerAnnotation;
import edu.ucr.cs.riple.injector.location.Location;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/** Base class for conflict graph processors. */
public abstract class AbstractConflictGraphProcessor implements ConflictGraphProcessor {
Expand Down Expand Up @@ -71,9 +69,7 @@ public AbstractConflictGraphProcessor(Context context, CompilerRunner runner, Su
*/
protected Set<Fix> getTriggeredFixesFromDownstreamErrors(Node node) {
Set<Location> currentLocationsTargetedByTree =
node.tree.stream()
.flatMap((Function<Fix, Stream<Location>>) fix -> fix.toLocations().stream())
.collect(Collectors.toSet());
node.tree.stream().flatMap(fix -> fix.toLocations().stream()).collect(Collectors.toSet());
return downstreamImpactCache.getTriggeredErrorsForCollection(node.tree).stream()
.filter(
error ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ public Error(

protected abstract Set<Fix> computeFixesFromAnnotations(Set<AddAnnotation> annotations);

/**
* Checks if error is resolvable.
*
* @return true if error is resolvable and false otherwise.
*/
public boolean hasFix() {
return this.fixes != null;
}

public Set<Fix> getFixes() {
return this.fixes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,42 +87,43 @@ public ImmutableSet<Fix> extendForGeneratedFixes(Set<Fix> fixes) {
ImmutableSet.Builder<Fix> builder = ImmutableSet.builder();
fixes.forEach(
fix ->
fix.ifOnField(
onField ->
onField.variables.forEach(
name -> {
// Expected getter method signature.
String getterSignature =
"get"
+ Character.toUpperCase(name.charAt(0))
+ name.substring(1)
+ "()";
// Check if method is lombok generated.
MethodRecord getterMethod =
moduleInfo
.getMethodRegistry()
.findMethodByName(onField.clazz, getterSignature);
if (getterMethod == null) {
// Getter method is not declared. skip.
// Note: If the getter method is generated, it should still be in the
// registry.
return;
}
if (isLombokGenerated(getterMethod.annotations)) {
// Method is lombok generated, add a fix to add the annotation on the
// method.
if (!(fix.changes instanceof AnnotationChange)) {
// Only annotation changes are supported for now.
return;
}
AnnotationChange change = (AnnotationChange) fix.changes;
builder.add(
new Fix(
new AddMarkerAnnotation(
getterMethod.location, change.getAnnotationName().fullName),
fix.reasons));
}
})));
fix.changes.forEach(
addAnnotation ->
addAnnotation
.getLocation()
.ifField(
onField ->
onField.variables.forEach(
name -> {
// Expected getter method signature.
String getterSignature =
"get"
+ Character.toUpperCase(name.charAt(0))
+ name.substring(1)
+ "()";
// Check if method is lombok generated.
MethodRecord getterMethod =
moduleInfo
.getMethodRegistry()
.findMethodByName(onField.clazz, getterSignature);
if (getterMethod == null) {
// Getter method is not declared. skip.
// Note: If the getter method is generated, it should still
// be in the registry.
return;
}
if (isLombokGenerated(getterMethod.annotations)) {
// Method is lombok generated, add a fix to add the
// annotation on the method.
AnnotationChange change = (AnnotationChange) addAnnotation;
builder.add(
new Fix(
new AddMarkerAnnotation(
getterMethod.location,
change.getAnnotationName().fullName),
fix.reasons));
}
}))));
return builder.build();
}

Expand Down

0 comments on commit 3c1a276

Please sign in to comment.