Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
nimakarimipour committed Oct 4, 2024
2 parents be0eac8 + a60d7d2 commit 63d4303
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ public void analyzeDownstreamDependencies() {
.stream()
.map(
location ->
new Fix(
new AddMarkerAnnotation(location, context.config.nullableAnnot), "null"))
new Fix(new AddMarkerAnnotation(location, context.config.nullableAnnot)))
.collect(ImmutableSet.toImmutableSet());
DownstreamImpactEvaluator evaluator = new DownstreamImpactEvaluator(supplier);
ImmutableSet<Report> reports = evaluator.evaluate(fixes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ public void suppressRemainingErrors(AnnotationInjector injector) {

// Collect NullAway.Init SuppressWarnings
Set<AddAnnotation> initializationSuppressWarningsAnnotations =
remainingFixes.stream()
remainingErrors.stream()
.filter(
fix ->
fix.isOnField()
&& (fix.reasons.contains("METHOD_NO_INIT")
|| fix.reasons.contains("FIELD_NO_INIT")))
e ->
e.messageType.equals("METHOD_NO_INIT") || e.messageType.equals("FIELD_NO_INIT"))
.flatMap(e -> e.getFixes().stream())
.filter(Fix::isOnField)
// Filter nodes annotated with SuppressWarnings("NullAway")
.filter(fix -> !fieldsWithSuppressWarnings.contains(fix.toField()))
.map(
Expand Down Expand Up @@ -355,8 +355,12 @@ public void preprocess(AnnotationInjector injector) {
// nonnull at all exit paths.
// Collect uninitialized fields.
Set<OnField> uninitializedFields =
Utility.readFixesFromOutputDirectory(context, context.targetModuleInfo).stream()
.filter(fix -> fix.isOnField() && fix.reasons.contains("FIELD_NO_INIT"))
Utility.readErrorsFromOutputDirectory(
context, context.targetModuleInfo, NullAwayError.class)
.stream()
.filter(e -> e.messageType.equals("FIELD_NO_INIT"))
.flatMap(e -> e.getFixes().stream())
.filter(Fix::isOnField)
.map(Fix::toField)
.collect(Collectors.toSet());
FieldInitializationStore fieldInitializationStore = new FieldInitializationStore(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public NullAwayError(
protected Set<Fix> computeFixesFromAnnotations(Set<AddAnnotation> annotations) {
// In NullAway inference, each annotation is examined individually. Thus, we create a separate
// fix instance for each annotation.
return annotations.stream()
.map(annot -> new Fix(annot, messageType))
.collect(Collectors.toSet());
return annotations.stream().map(Fix::new).collect(Collectors.toSet());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ protected Set<Fix> getTriggeredFixesFromDownstreamErrors(Node node) {
error ->
new Fix(
new AddMarkerAnnotation(
error.toResolvingLocation(), context.config.nullableAnnot),
"PASSING_NULLABLE"))
error.toResolvingLocation(), context.config.nullableAnnot)))
.collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,13 @@ public class Fix {

/** Suggested change. */
public final Set<AddAnnotation> changes;
/** Reasons this fix is suggested by NullAway in string. */
public final ImmutableSet<String> reasons;

public Fix(AddAnnotation change, String reason) {
this(change, ImmutableSet.of(reason));
public Fix(AddAnnotation change) {
this(ImmutableSet.of(change));
}

public Fix(AddAnnotation change, ImmutableSet<String> reasons) {
this(ImmutableSet.of(change), reasons);
}

public Fix(ImmutableSet<AddAnnotation> change, ImmutableSet<String> reasons) {
public Fix(ImmutableSet<AddAnnotation> change) {
this.changes = change;
this.reasons = reasons;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ public ImmutableSet<Fix> extendForGeneratedFixes(Set<Fix> fixes) {
new Fix(
new AddMarkerAnnotation(
getterMethod.location,
change.getAnnotationName().fullName),
fix.reasons));
change.getAnnotationName().fullName)));
}
}))));
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

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

import com.google.common.collect.ImmutableSet;
import edu.ucr.cs.riple.core.registries.index.Error;
import edu.ucr.cs.riple.core.registries.index.Fix;
import edu.ucr.cs.riple.core.registries.region.Region;
Expand All @@ -46,8 +45,6 @@ public TError(Location location) {

@Override
protected Set<Fix> computeFixesFromAnnotations(Set<AddAnnotation> annotations) {
return annotations.stream()
.map(addAnnotation -> new Fix(addAnnotation, ImmutableSet.of(messageType)))
.collect(Collectors.toSet());
return annotations.stream().map(Fix::new).collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

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

import com.google.common.collect.ImmutableSet;
import edu.ucr.cs.riple.core.registries.index.Fix;
import edu.ucr.cs.riple.injector.location.Location;

Expand All @@ -36,6 +35,6 @@
public class TFix extends Fix {

public TFix(Location location) {
super(new DefaultAnnotation(location), ImmutableSet.of());
super(new DefaultAnnotation(location));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public TReport(Location root, int effect) {
}

public TReport(Location root, int effect, Tag tag) {
super(
new Fix(new AddMarkerAnnotation(root, "javax.annotation.Nullable"), ImmutableSet.of()),
effect);
super(new Fix(new AddMarkerAnnotation(root, "javax.annotation.Nullable")), effect);
this.expectedValue = effect;
if (tag != null) {
this.tag(tag);
Expand Down

0 comments on commit 63d4303

Please sign in to comment.