Skip to content

Commit

Permalink
Fix parser generation exception caused by unmodifiable collections us…
Browse files Browse the repository at this point in the history
…ages from com.intellij.util.containers.ContainerUtil (#389)
  • Loading branch information
dtsaryov authored Jan 8, 2025
1 parent e2c1860 commit 829b50f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/org/intellij/grammar/analysis/BnfFirstNextAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,15 @@ else if (GrammarUtil.isExternalReference(expression)) {
private static @NotNull Set<BnfExpression> exprSetIntersection(@NotNull Set<BnfExpression> a, @NotNull Set<BnfExpression> b) {
Set<BnfExpression> filter = newExprSet(a);
filter.retainAll(newExprSet(b));
Set<BnfExpression> result = union(a, b);
Set<BnfExpression> result = new HashSet<>(union(a, b));
result.retainAll(filter);
return result;
}

private static @NotNull Set<BnfExpression> exprSetDifference(@NotNull Set<BnfExpression> a, @NotNull Set<BnfExpression> b) {
Set<BnfExpression> filter = newExprSet(a);
filter.removeAll(newExprSet(b));
Set<BnfExpression> result = union(a, b);
Set<BnfExpression> result = new HashSet<>(union(a, b));
result.retainAll(filter);
return result;
}
Expand Down
8 changes: 5 additions & 3 deletions src/org/intellij/grammar/diagram/BnfDiagramProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ public String getElementTitle(BnfRule o) {
@Override
public Object @NotNull [] getNodeItems(BnfRule element) {
Map<PsiElement, RuleGraphHelper.Cardinality> map = myGraphHelper.getFor(element);
List<Item> entries = ContainerUtil.mapNotNull(map.entrySet(), p -> p.getKey() instanceof BnfRule o ? new Item(o, p.getValue()) : null);
Collections.sort(entries, (o, o1) -> Comparing.compare(o.rule.getName(), o1.rule.getName()));
return entries.toArray();
return map.entrySet().stream()
.map(p -> p.getKey() instanceof BnfRule o ? new Item(o, p.getValue()) : null)
.filter(Objects::nonNull)
.sorted((o, o1) -> Comparing.compare(o.rule.getName(), o1.rule.getName()))
.toArray();
}

@Override
Expand Down

0 comments on commit 829b50f

Please sign in to comment.