Skip to content

Commit

Permalink
Additional fallback handling of context selection in unparsable sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Jun 8, 2024
1 parent 8500614 commit db9960c
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.openrewrite.java.tree.Space;
import org.openrewrite.marker.Marker;
import org.openrewrite.marker.Range;
import software.coley.collections.Unchecked;
import software.coley.recaf.analytics.logging.DebuggingLogger;
import software.coley.recaf.analytics.logging.Logging;
import software.coley.recaf.util.StringDiff;
Expand Down Expand Up @@ -62,7 +63,7 @@ public static SortedMap<Range, Tree> computeRangeToTreeMapping(@Nonnull Tree tre
}
return cmp;
});
DiffHelper helper = backingText == null ? null : new DiffHelper(backingText, tree);
DiffHelper helper = backingText == null ? null : Unchecked.getOr(() -> new DiffHelper(backingText, tree), null);
PositionPrintOutputCapture ppoc = new PositionPrintOutputCapture(helper);
JavaPrinter<ExecutionContext> printer = new JavaPrinter<>() {
final JavaPrinter<ExecutionContext> spacePrinter = new JavaPrinter<>();
Expand All @@ -80,7 +81,10 @@ public J visit(@Nullable Tree tree, @Nonnull PrintOutputCapture<ExecutionContext
spacePrinter.visitSpace(t.getPrefix(), Space.Location.ANY, prefix);

Range.Position startPosition = new Range.Position(prefix.posInBacking, prefix.line, prefix.column);
t = super.visit(tree, outputCapture);
t = Unchecked.getOr(() ->super.visit(tree, outputCapture), null);
if (t == null) {
return null;
}
Range.Position endPosition = new Range.Position(ppoc.posInBacking, ppoc.line, ppoc.column);
Range range = new Range(randomId(), startPosition, endPosition);
rangeMap.put(range, t);
Expand Down

0 comments on commit db9960c

Please sign in to comment.