Skip to content

Commit 829b50f

Browse files
authored
Fix parser generation exception caused by unmodifiable collections usages from com.intellij.util.containers.ContainerUtil (#389)
1 parent e2c1860 commit 829b50f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/org/intellij/grammar/analysis/BnfFirstNextAnalyzer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,15 @@ else if (GrammarUtil.isExternalReference(expression)) {
429429
private static @NotNull Set<BnfExpression> exprSetIntersection(@NotNull Set<BnfExpression> a, @NotNull Set<BnfExpression> b) {
430430
Set<BnfExpression> filter = newExprSet(a);
431431
filter.retainAll(newExprSet(b));
432-
Set<BnfExpression> result = union(a, b);
432+
Set<BnfExpression> result = new HashSet<>(union(a, b));
433433
result.retainAll(filter);
434434
return result;
435435
}
436436

437437
private static @NotNull Set<BnfExpression> exprSetDifference(@NotNull Set<BnfExpression> a, @NotNull Set<BnfExpression> b) {
438438
Set<BnfExpression> filter = newExprSet(a);
439439
filter.removeAll(newExprSet(b));
440-
Set<BnfExpression> result = union(a, b);
440+
Set<BnfExpression> result = new HashSet<>(union(a, b));
441441
result.retainAll(filter);
442442
return result;
443443
}

src/org/intellij/grammar/diagram/BnfDiagramProvider.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ public String getElementTitle(BnfRule o) {
107107
@Override
108108
public Object @NotNull [] getNodeItems(BnfRule element) {
109109
Map<PsiElement, RuleGraphHelper.Cardinality> map = myGraphHelper.getFor(element);
110-
List<Item> entries = ContainerUtil.mapNotNull(map.entrySet(), p -> p.getKey() instanceof BnfRule o ? new Item(o, p.getValue()) : null);
111-
Collections.sort(entries, (o, o1) -> Comparing.compare(o.rule.getName(), o1.rule.getName()));
112-
return entries.toArray();
110+
return map.entrySet().stream()
111+
.map(p -> p.getKey() instanceof BnfRule o ? new Item(o, p.getValue()) : null)
112+
.filter(Objects::nonNull)
113+
.sorted((o, o1) -> Comparing.compare(o.rule.getName(), o1.rule.getName()))
114+
.toArray();
113115
}
114116

115117
@Override

0 commit comments

Comments
 (0)