Skip to content

Commit

Permalink
java: use Java 21 features
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Dec 13, 2023
1 parent ee300d7 commit 451a843
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion base/src/main/java/org/aya/concrete/desugar/Desugarer.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static class DesugarInterruption extends Exception {}
},
// do not desugar
right -> arrayExpr);
case Expr.LetOpen(var $, var $$, var $$$, var body) -> pre(body);
case Expr.LetOpen(_, _, _, var body) -> pre(body);
case Expr misc -> StmtConsumer.super.pre(misc);
};
}
Expand Down
4 changes: 2 additions & 2 deletions base/src/main/java/org/aya/core/term/FormulaTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public record FormulaTerm(@NotNull Formula<Term> asFormula) implements Term {

public @NotNull SeqView<Term> view() {
return switch (asFormula) {
case Formula.Conn(var $, var l, var r) -> Seq.of(l, r).view();
case Formula.Conn(_, var l, var r) -> Seq.of(l, r).view();

Check warning on line 48 in base/src/main/java/org/aya/core/term/FormulaTerm.java

View check run for this annotation

Codecov / codecov/patch

base/src/main/java/org/aya/core/term/FormulaTerm.java#L48

Added line #L48 was not covered by tests
case Formula.Inv(var i) -> SeqView.of(i);
case Formula.Lit<?> $ -> SeqView.empty();
case Formula.Lit<?> _ -> SeqView.empty();

Check warning on line 50 in base/src/main/java/org/aya/core/term/FormulaTerm.java

View check run for this annotation

Codecov / codecov/patch

base/src/main/java/org/aya/core/term/FormulaTerm.java#L50

Added line #L50 was not covered by tests
};
}
}
8 changes: 4 additions & 4 deletions base/src/main/java/org/aya/prettier/ConcretePrettier.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ yield visitCalls(null, fn, (nc, l) -> l.toDoc(options), outer,
}
case Expr.Lift expr -> Doc.sep(Seq
.from(IntRange.closed(1, expr.lift()).iterator()).view()
.map($ -> Doc.styled(KEYWORD, Doc.symbol("ulift")))
.map(_ -> Doc.styled(KEYWORD, Doc.symbol("ulift")))

Check warning on line 158 in base/src/main/java/org/aya/prettier/ConcretePrettier.java

View check run for this annotation

Codecov / codecov/patch

base/src/main/java/org/aya/prettier/ConcretePrettier.java#L158

Added line #L158 was not covered by tests
.appended(term(Outer.Lifted, expr.expr())));
case Expr.PartEl el -> Doc.sep(Doc.symbol("{|"),
partial(el),
Expand Down Expand Up @@ -260,17 +260,17 @@ private Doc partial(Expr.PartEl el) {
public @NotNull Doc pattern(@NotNull Pattern pattern, boolean licit, Outer outer) {
return switch (pattern) {
case Pattern.Tuple tuple -> Doc.licit(licit, patterns(tuple.patterns()));
case Pattern.Absurd $ -> Doc.bracedUnless(Doc.styled(KEYWORD, "()"), licit);
case Pattern.Absurd _ -> Doc.bracedUnless(Doc.styled(KEYWORD, "()"), licit);

Check warning on line 263 in base/src/main/java/org/aya/prettier/ConcretePrettier.java

View check run for this annotation

Codecov / codecov/patch

base/src/main/java/org/aya/prettier/ConcretePrettier.java#L263

Added line #L263 was not covered by tests
case Pattern.Bind bind -> Doc.bracedUnless(linkDef(bind.bind()), licit);
case Pattern.CalmFace $ -> Doc.bracedUnless(Doc.plain(Constants.ANONYMOUS_PREFIX), licit);
case Pattern.CalmFace _ -> Doc.bracedUnless(Doc.plain(Constants.ANONYMOUS_PREFIX), licit);
case Pattern.Number number -> Doc.bracedUnless(Doc.plain(String.valueOf(number.number())), licit);
case Pattern.Ctor ctor -> {
var name = linkRef(ctor.resolved().data(), CON);
var ctorDoc = ctor.params().isEmpty() ? name : Doc.sep(name, visitMaybeCtorPatterns(ctor.params(), Outer.AppSpine, Doc.ALT_WS));
yield ctorDoc(outer, licit, ctorDoc, ctor.params().isEmpty());
}
case Pattern.QualifiedRef qref -> Doc.bracedUnless(Doc.plain(qref.qualifiedID().join()), licit);
case Pattern.BinOpSeq(var pos, var param) -> {
case Pattern.BinOpSeq(_, var param) -> {
if (param.sizeEquals(1)) {
yield pattern(param.getFirst(), outer);
}
Expand Down
2 changes: 1 addition & 1 deletion base/src/main/java/org/aya/prettier/CorePrettier.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ yield visitCalls(null, fn, (nest, t) -> t.toDoc(options), outer,
options.map.get(AyaPrettierOptions.Key.ShowImplicitArgs)
);
}
case IntervalTerm $ -> Doc.styled(PRIM, "I");
case IntervalTerm _ -> Doc.styled(PRIM, "I");
case NewTerm(var inner) -> visitCalls(null, Doc.styled(KEYWORD, "new"), (nest, t) -> t.toDoc(options), outer,
SeqView.of(new Arg<>(o -> term(Outer.AppSpine, inner), true)),
options.map.get(AyaPrettierOptions.Key.ShowImplicitArgs)
Expand Down
10 changes: 5 additions & 5 deletions base/src/main/java/org/aya/tyck/unify/TermComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ private boolean doCompareTyped(@NotNull Term type, @NotNull Term lhs, @NotNull T
}
yield true;
}
case LamTerm $ -> throw new InternalException("LamTerm is never type");
case ConCall $ -> throw new InternalException("ConCall is never type");
case TupTerm $ -> throw new InternalException("TupTerm is never type");
case NewTerm $ -> throw new InternalException("NewTerm is never type");
case ErrorTerm $ -> true;
case LamTerm _ -> throw new InternalException("LamTerm is never type");
case ConCall _ -> throw new InternalException("ConCall is never type");
case TupTerm _ -> throw new InternalException("TupTerm is never type");
case NewTerm _ -> throw new InternalException("NewTerm is never type");
case ErrorTerm _ -> true;

Check warning on line 285 in base/src/main/java/org/aya/tyck/unify/TermComparator.java

View check run for this annotation

Codecov / codecov/patch

base/src/main/java/org/aya/tyck/unify/TermComparator.java#L281-L285

Added lines #L281 - L285 were not covered by tests
case SigmaTerm(var paramsSeq) -> {
var params = paramsSeq.view();
for (int i = 1, size = paramsSeq.size(); i <= size; i++) {
Expand Down
12 changes: 6 additions & 6 deletions base/src/test/java/org/aya/literate/HighlighterTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public HighlighterTester(@NotNull String sourceCode, @NotNull ImmutableSeq<Highl

public void runTest() {
var sortedActual = actual.view().distinct().sorted().toImmutableSeq().view();
if (sortedActual.getLast() instanceof HighlightInfo.Lit(var $, var kind) && kind == HighlightInfo.LitKind.Eol)
if (sortedActual.getLast() instanceof HighlightInfo.Lit(_, var kind) && kind == HighlightInfo.LitKind.Eol)
// Remove the last Eol
sortedActual = sortedActual.dropLast(1);
runTest(sortedActual.toImmutableSeq(), Seq.of(expected));
Expand Down Expand Up @@ -120,13 +120,13 @@ public void runTest(@NotNull ImmutableSeq<HighlightInfo> actuals, @NotNull Seq<E
assertEquals(expectedText, actualText, "at " + sourcePos);

switch (actual) {
case HighlightInfo.Lit(var $, var ty)
case HighlightInfo.Lit(_, var ty)
when ty == HighlightInfo.LitKind.Keyword && expected.expected() instanceof ExpectedHighlightType.Keyword -> {
}
case HighlightInfo.Lit(var $, var ty)
case HighlightInfo.Lit(_, var ty)
when ty == HighlightInfo.LitKind.Int && expected.expected() instanceof LitInt -> {
}
case HighlightInfo.Lit(var $, var ty)
case HighlightInfo.Lit(_, var ty)
when ty == HighlightInfo.LitKind.String && expected.expected() instanceof ExpectedHighlightType.LitString -> {
}

Expand All @@ -138,7 +138,7 @@ public void runTest(@NotNull ImmutableSeq<HighlightInfo> actuals, @NotNull Seq<E
when expected.expected() instanceof ExpectedHighlightType.Ref expectedRef ->
assertRef(sourcePos, ref, expectedRef);

case HighlightInfo.Err err -> throw new UnsupportedOperationException("TODO"); // TODO
case HighlightInfo.Err _ -> throw new UnsupportedOperationException("TODO"); // TODO

default ->
fail("expected: " + expected.getClass().getSimpleName() + ", but actual: " + actual.getClass().getSimpleName());
Expand Down Expand Up @@ -213,7 +213,7 @@ public static void highlightAndTest(@Language("Aya") @NotNull String code, @Null
Stmt.resolve(stmts, resolveInfo, EmptyModuleLoader.INSTANCE);

var result = SyntaxHighlight.highlight(null, Option.some(sourceFile), stmts)
.filterNot(it -> it instanceof HighlightInfo.Lit(var $, var kind)
.filterNot(it -> it instanceof HighlightInfo.Lit(_, var kind)
&& ignored.contains(kind));
new HighlighterTester(code, result, expected).runTest();
}
Expand Down
10 changes: 5 additions & 5 deletions cli-impl/src/main/java/org/aya/cli/literate/SyntaxHighlight.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ else if (SPECIAL_SYMBOL.contains(tokenType))
@Override
public @NotNull MutableList<HighlightInfo> fold(@NotNull MutableList<HighlightInfo> acc, @NotNull Pattern pat) {
return switch (pat) {
case Pattern.Number(var pos, var $) -> add(acc, LitKind.Int.toLit(pos));
case Pattern.Number(var pos, _) -> add(acc, LitKind.Int.toLit(pos));
default -> StmtFolder.super.fold(acc, pat);
};
}
Expand All @@ -147,15 +147,15 @@ else if (SPECIAL_SYMBOL.contains(tokenType))
}

private @NotNull HighlightInfo linkRef(@NotNull SourcePos sourcePos, @NotNull AnyVar var, @Nullable AyaDocile type) {
if (var instanceof LocalVar(var $, var $$, GenerateKind.Generalized(var origin)))
if (var instanceof LocalVar(var _, var _, GenerateKind.Generalized(var origin)))
return linkRef(sourcePos, origin, type);
return kindOf(var).toRef(sourcePos, BasePrettier.linkIdOf(currentFileModule, var), type);
}

@SuppressWarnings("unused")
public static @NotNull DefKind kindOf(@NotNull AnyVar var) {
return switch (var) {
case GeneralizedVar ignored -> DefKind.Generalized;
case GeneralizedVar _ -> DefKind.Generalized;
case DefVar<?, ?> defVar -> {
if (defVar.concrete instanceof TeleDecl.FnDecl || defVar.core instanceof FnDef)
yield DefKind.Fn;
Expand All @@ -171,8 +171,8 @@ else if (defVar.concrete instanceof ClassDecl || defVar.core instanceof ClassDef
yield DefKind.Clazz;
else throw new InternalException(STR."unknown def type: \{defVar}");

Check warning on line 172 in cli-impl/src/main/java/org/aya/cli/literate/SyntaxHighlight.java

View check run for this annotation

Codecov / codecov/patch

cli-impl/src/main/java/org/aya/cli/literate/SyntaxHighlight.java#L172

Added line #L172 was not covered by tests
}
case LocalVar(var $, var $$, GenerateKind.Generalized(var $$$)) -> DefKind.Generalized;
case LocalVar ignored -> DefKind.LocalVar;
case LocalVar(_, _, GenerateKind.Generalized(_)) -> DefKind.Generalized;
case LocalVar _ -> DefKind.LocalVar;
default -> DefKind.Unknown;
};
}
Expand Down
2 changes: 1 addition & 1 deletion cli-impl/src/main/java/org/aya/cli/parse/AyaProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ private interface LicitParser<T> extends BooleanObjBiFunction<GenericNode<?>, T>
: newBody.childrenOfType(NEW_ARG).map(arg -> {
var id = newArgField(arg.child(NEW_ARG_FIELD));
var bindings = arg.childrenOfType(TELE_PARAM_NAME).map(this::teleParamName)
.map(b -> b.map($ -> LocalVar.from(b)))
.map(b -> b.map(_ -> LocalVar.from(b)))
.toImmutableSeq();
var body = expr(arg.child(EXPR));
return new Expr.Field<>(sourcePosOf(arg), id, bindings, body, MutableValue.create());
Expand Down
4 changes: 2 additions & 2 deletions ide-lsp/src/main/java/org/aya/lsp/models/HighlightResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public record Symbol(
case Prim -> Option.some(Kind.PrimRef);
case Unknown -> Option.none();
};
case HighlightInfo.Lit $ -> Option.none(); // handled by client
case HighlightInfo.Err $ -> Option.none(); // handled by client
case HighlightInfo.Lit _ -> Option.none(); // handled by client
case HighlightInfo.Err _ -> Option.none(); // handled by client
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public ClassedPreset(@NotNull ClosingStylist delegate) {
case Curly -> "text-decoration-style: wavy;";
};
var colorRef = switch (color) {
case Style.ColorHex(var rgb, var $) -> cssColor(rgb);
case Style.ColorName(var name, var $) -> "var(%s)".formatted(cssVar(name));
case Style.ColorHex(var rgb, _) -> cssColor(rgb);

Check warning on line 80 in pretty/src/main/java/org/aya/pretty/backend/html/Html5Stylist.java

View check run for this annotation

Codecov / codecov/patch

pretty/src/main/java/org/aya/pretty/backend/html/Html5Stylist.java#L80

Added line #L80 was not covered by tests
case Style.ColorName(var name, _) -> "var(%s)".formatted(cssVar(name));
case null -> null;
};
var decoColor = colorRef != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public ClassedPreset(@NotNull ClosingStylist delegate) {
case Italic -> Tuple.of("\\textit{", "}");
case Bold -> Tuple.of("\\textbf{", "}");
};
case Style.LineThrough(var pos, var $, var $$) -> switch (pos) {
case Style.LineThrough(var pos, _, _) -> switch (pos) {
case Strike -> Tuple.of("\\sout{", "}");
case Underline -> Tuple.of("\\underline{", "}");
case Overline -> null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected void renderDoc(@NotNull Cursor cursor, @NotNull Doc doc, EnumSet<Outer
case Doc.InlineMath inlineMath -> renderInlineMath(cursor, inlineMath, outer);
case Doc.MathBlock mathBlock -> renderMathBlock(cursor, mathBlock, outer);
case Doc.Tooltip tooltip -> renderTooltip(cursor, tooltip, outer);
case Doc.Empty $ -> {}
case Doc.Empty _ -> {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public BaseMdParser(@NotNull SourceFile file, @NotNull Reporter reporter, @NotNu
return switch (node) {
case Text text -> new Literate.Raw(Doc.plain(text.getLiteral()));
case Emphasis emphasis -> new Literate.Many(Style.italic(), mapChildren(emphasis));
case HardLineBreak $ -> new Literate.Raw(Doc.line());
case SoftLineBreak $ -> new Literate.Raw(Doc.line());
case HardLineBreak _ -> new Literate.Raw(Doc.line());
case SoftLineBreak _ -> new Literate.Raw(Doc.line());
case StrongEmphasis emphasis -> new Literate.Many(Style.bold(), mapChildren(emphasis));
case Paragraph p -> new Literate.Many(MdStyle.GFM.Paragraph, mapChildren(p));
case BlockQuote b -> new Literate.Many(MdStyle.GFM.BlockQuote, mapChildren(b));
Expand Down Expand Up @@ -125,7 +125,7 @@ public BaseMdParser(@NotNull SourceFile file, @NotNull Reporter reporter, @NotNu
case Code inlineCode -> {
var spans = inlineCode.getSourceSpans();
if (spans != null && spans.size() == 1) {
var sourceSpan = spans.get(0);
var sourceSpan = spans.getFirst();
var lineIndex = linesIndex.get(sourceSpan.getLineIndex());
var startFrom = lineIndex + sourceSpan.getColumnIndex();
var sourcePos = fromSourceSpans(file, startFrom, Seq.of(sourceSpan));
Expand Down

0 comments on commit 451a843

Please sign in to comment.