From 726afc00dcc86c204bb353ff177e24fa920d6b10 Mon Sep 17 00:00:00 2001 From: HoshinoTented Date: Wed, 8 Jan 2025 04:26:36 +0800 Subject: [PATCH] pragma: use ImmutableSeq --- .../src/main/java/org/aya/producer/AyaProducer.java | 11 ++++------- .../main/java/org/aya/prettier/ConcretePrettier.java | 3 +-- .../org/aya/syntax/concrete/stmt/decl/PragmaInfo.java | 4 ++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/producer/src/main/java/org/aya/producer/AyaProducer.java b/producer/src/main/java/org/aya/producer/AyaProducer.java index 565bd906c..d3d71de80 100644 --- a/producer/src/main/java/org/aya/producer/AyaProducer.java +++ b/producer/src/main/java/org/aya/producer/AyaProducer.java @@ -9,10 +9,7 @@ import com.intellij.psi.tree.TokenSet; import kala.collection.SeqView; import kala.collection.immutable.ImmutableSeq; -import kala.collection.mutable.MutableEnumSet; -import kala.collection.mutable.MutableList; -import kala.collection.mutable.MutableSet; -import kala.collection.mutable.MutableSinglyLinkedList; +import kala.collection.mutable.*; import kala.control.Either; import kala.control.Option; import kala.function.BooleanObjBiFunction; @@ -304,7 +301,7 @@ private void pragma(GenericNode node, Decl decl) { switch (name) { case Constants.PRAGMA_SUPPRESS -> { // TODO: use MutableEnumSet - MutableSet> sups = MutableSet.create(); + MutableList> sups = FreezableMutableList.create(); for (var arg : args) { var resolved = Arrays.stream(Suppress.values()) @@ -315,11 +312,11 @@ private void pragma(GenericNode node, Decl decl) { if (resolved == null) { reporter.report(new BadXWarn.BadWarnWarn(sourcePosOf(arg), arg.tokenText().toString())); } else { - sups.add(new WithPos<>(sourcePosOf(arg), resolved)); + sups.append(new WithPos<>(sourcePosOf(arg), resolved)); } } - decl.pragmaInfo.suppressWarn = new PragmaInfo.SuppressWarn(namePos, sups.toImmutableSet()); + decl.pragmaInfo.suppressWarn = new PragmaInfo.SuppressWarn(namePos, sups.toImmutableSeq()); } default -> reporter.report(new BadXWarn.BadPragmaWarn(namePos, name)); } diff --git a/syntax/src/main/java/org/aya/prettier/ConcretePrettier.java b/syntax/src/main/java/org/aya/prettier/ConcretePrettier.java index c36fec14b..36dfd12e6 100644 --- a/syntax/src/main/java/org/aya/prettier/ConcretePrettier.java +++ b/syntax/src/main/java/org/aya/prettier/ConcretePrettier.java @@ -331,8 +331,7 @@ private Doc visitAccess(@NotNull Accessibility acc, @Nullable Accessibility theD if (info.suppressWarn != null) { var args = info.suppressWarn.args().view() - .map(x -> Doc.plain(x.data().name())) - .toImmutableSeq(); + .map(x -> Doc.plain(x.data().name())); lines.append(doPragma(Doc.styled(KEYWORD, Constants.PRAGMA_SUPPRESS), Doc.commaList(args))); } diff --git a/syntax/src/main/java/org/aya/syntax/concrete/stmt/decl/PragmaInfo.java b/syntax/src/main/java/org/aya/syntax/concrete/stmt/decl/PragmaInfo.java index 9504cea36..f48f37dea 100644 --- a/syntax/src/main/java/org/aya/syntax/concrete/stmt/decl/PragmaInfo.java +++ b/syntax/src/main/java/org/aya/syntax/concrete/stmt/decl/PragmaInfo.java @@ -2,7 +2,7 @@ // Use of this source code is governed by the MIT license that can be found in the LICENSE.md file. package org.aya.syntax.concrete.stmt.decl; -import kala.collection.immutable.ImmutableSet; +import kala.collection.immutable.ImmutableSeq; import org.aya.generic.Suppress; import org.aya.util.error.SourcePos; import org.aya.util.error.WithPos; @@ -12,7 +12,7 @@ public class PragmaInfo { /// @param sourcePos the name, not the whole pragma - public record SuppressWarn(@NotNull SourcePos sourcePos, @NotNull ImmutableSet> args) { + public record SuppressWarn(@NotNull SourcePos sourcePos, @NotNull ImmutableSeq> args) { } public @Nullable SuppressWarn suppressWarn = null;