From 9d6ce282c7f0fcc7bd6fed71d8cd446362ebca7f Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 20 Feb 2024 09:48:53 +0100 Subject: [PATCH] feat: format upper bound of type parameters (#898) ### Summary of Changes Add missing formatting for the upper bound of type parameters. --- .../safe-ds-lang/src/language/lsp/safe-ds-formatter.ts | 1 + .../bounded contravariant optional type parameter.sdstest | 5 +++++ .../bounded contravariant required type parameter.sdstest | 5 +++++ ...travariant type parameter with annotation call.sdstest | 8 ++++++++ .../bounded covariant optional type parameter.sdstest | 5 +++++ .../bounded covariant required type parameter.sdstest | 5 +++++ ... covariant type parameter with annotation call.sdstest | 8 ++++++++ .../bounded invariant optional type parameter.sdstest | 5 +++++ .../bounded invariant required type parameter.sdstest | 5 +++++ ... invariant type parameter with annotation call.sdstest | 8 ++++++++ ...bounded contravariant optional type parameter.sdstest} | 0 ...bounded contravariant required type parameter.sdstest} | 0 ...ravariant type parameter with annotation call.sdstest} | 0 ...> unbounded covariant optional type parameter.sdstest} | 0 ...> unbounded covariant required type parameter.sdstest} | 0 ...covariant type parameter with annotation call.sdstest} | 0 ...> unbounded invariant optional type parameter.sdstest} | 0 ...> unbounded invariant required type parameter.sdstest} | 0 ...invariant type parameter with annotation call.sdstest} | 0 ...-bounded contravariant optional type parameter.sdstest | 3 +++ ...-bounded contravariant required type parameter.sdstest | 3 +++ ...good-bounded covariant optional type parameter.sdstest | 3 +++ ...good-bounded covariant required type parameter.sdstest | 3 +++ ...good-bounded invariant optional type parameter.sdstest | 3 +++ ...good-bounded invariant required type parameter.sdstest | 3 +++ ...bounded contravariant optional type parameter.sdstest} | 0 ...bounded contravariant required type parameter.sdstest} | 0 ...d-unbounded covariant optional type parameter.sdstest} | 0 ...d-unbounded covariant required type parameter.sdstest} | 0 ...d-unbounded invariant optional type parameter.sdstest} | 0 ...d-unbounded invariant required type parameter.sdstest} | 0 31 files changed, 73 insertions(+) create mode 100644 packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded contravariant optional type parameter.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded contravariant required type parameter.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded contravariant type parameter with annotation call.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded covariant optional type parameter.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded covariant required type parameter.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded covariant type parameter with annotation call.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded invariant optional type parameter.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded invariant required type parameter.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded invariant type parameter with annotation call.sdstest rename packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/{contravariant optional type parameter.sdstest => unbounded contravariant optional type parameter.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/{contravariant required type parameter.sdstest => unbounded contravariant required type parameter.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/{contravariant type parameter with annotation call.sdstest => unbounded contravariant type parameter with annotation call.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/{covariant optional type parameter.sdstest => unbounded covariant optional type parameter.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/{covariant required type parameter.sdstest => unbounded covariant required type parameter.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/{covariant type parameter with annotation call.sdstest => unbounded covariant type parameter with annotation call.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/{invariant optional type parameter.sdstest => unbounded invariant optional type parameter.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/{invariant required type parameter.sdstest => unbounded invariant required type parameter.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/{invariant type parameter with annotation call.sdstest => unbounded invariant type parameter with annotation call.sdstest} (100%) create mode 100644 packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded contravariant optional type parameter.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded contravariant required type parameter.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded covariant optional type parameter.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded covariant required type parameter.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded invariant optional type parameter.sdstest create mode 100644 packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded invariant required type parameter.sdstest rename packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/{good-contravariant optional type parameter.sdstest => good-unbounded contravariant optional type parameter.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/{good-contravariant required type parameter.sdstest => good-unbounded contravariant required type parameter.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/{good-covariant optional type parameter.sdstest => good-unbounded covariant optional type parameter.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/{good-covariant required type parameter.sdstest => good-unbounded covariant required type parameter.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/{good-invariant optional type parameter.sdstest => good-unbounded invariant optional type parameter.sdstest} (100%) rename packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/{good-invariant required type parameter.sdstest => good-unbounded invariant required type parameter.sdstest} (100%) diff --git a/packages/safe-ds-lang/src/language/lsp/safe-ds-formatter.ts b/packages/safe-ds-lang/src/language/lsp/safe-ds-formatter.ts index 11f75ba83..b4b5112b7 100644 --- a/packages/safe-ds-lang/src/language/lsp/safe-ds-formatter.ts +++ b/packages/safe-ds-lang/src/language/lsp/safe-ds-formatter.ts @@ -915,6 +915,7 @@ export class SafeDsFormatter extends AbstractFormatter { } formatter.property('variance').append(oneSpace()); + formatter.keyword('sub').surround(oneSpace()); formatter.keyword('=').surround(oneSpace()); } diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded contravariant optional type parameter.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded contravariant optional type parameter.sdstest new file mode 100644 index 000000000..1116629c6 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded contravariant optional type parameter.sdstest @@ -0,0 +1,5 @@ +fun myFunction< in T sub Int = Int >() + +// ----------------------------------------------------------------------------- + +fun myFunction() diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded contravariant required type parameter.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded contravariant required type parameter.sdstest new file mode 100644 index 000000000..149652aaa --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded contravariant required type parameter.sdstest @@ -0,0 +1,5 @@ +fun myFunction< in T sub Int >() + +// ----------------------------------------------------------------------------- + +fun myFunction() diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded contravariant type parameter with annotation call.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded contravariant type parameter with annotation call.sdstest new file mode 100644 index 000000000..30d427696 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded contravariant type parameter with annotation call.sdstest @@ -0,0 +1,8 @@ +fun myFunction< @Annotation in T sub Int > ( ) + +// ----------------------------------------------------------------------------- + +fun myFunction< + @Annotation + in T sub Int +>() diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded covariant optional type parameter.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded covariant optional type parameter.sdstest new file mode 100644 index 000000000..b094ae5ef --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded covariant optional type parameter.sdstest @@ -0,0 +1,5 @@ +fun myFunction< out T sub Int = Int >() + +// ----------------------------------------------------------------------------- + +fun myFunction() diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded covariant required type parameter.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded covariant required type parameter.sdstest new file mode 100644 index 000000000..21fd25627 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded covariant required type parameter.sdstest @@ -0,0 +1,5 @@ +fun myFunction< out T sub Int >() + +// ----------------------------------------------------------------------------- + +fun myFunction() diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded covariant type parameter with annotation call.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded covariant type parameter with annotation call.sdstest new file mode 100644 index 000000000..dad5d360d --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded covariant type parameter with annotation call.sdstest @@ -0,0 +1,8 @@ +fun myFunction< @Annotation out T sub Int > ( ) + +// ----------------------------------------------------------------------------- + +fun myFunction< + @Annotation + out T sub Int +>() diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded invariant optional type parameter.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded invariant optional type parameter.sdstest new file mode 100644 index 000000000..ad13a8277 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded invariant optional type parameter.sdstest @@ -0,0 +1,5 @@ +fun myFunction< T sub Int = Int >() + +// ----------------------------------------------------------------------------- + +fun myFunction() diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded invariant required type parameter.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded invariant required type parameter.sdstest new file mode 100644 index 000000000..5693a20b0 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded invariant required type parameter.sdstest @@ -0,0 +1,5 @@ +fun myFunction< T sub Int >() + +// ----------------------------------------------------------------------------- + +fun myFunction() diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded invariant type parameter with annotation call.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded invariant type parameter with annotation call.sdstest new file mode 100644 index 000000000..9935c0278 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/bounded invariant type parameter with annotation call.sdstest @@ -0,0 +1,8 @@ +fun myFunction< @Annotation T sub Int >() + +// ----------------------------------------------------------------------------- + +fun myFunction< + @Annotation + T sub Int +>() diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/contravariant optional type parameter.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded contravariant optional type parameter.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/contravariant optional type parameter.sdstest rename to packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded contravariant optional type parameter.sdstest diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/contravariant required type parameter.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded contravariant required type parameter.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/contravariant required type parameter.sdstest rename to packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded contravariant required type parameter.sdstest diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/contravariant type parameter with annotation call.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded contravariant type parameter with annotation call.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/contravariant type parameter with annotation call.sdstest rename to packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded contravariant type parameter with annotation call.sdstest diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/covariant optional type parameter.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded covariant optional type parameter.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/covariant optional type parameter.sdstest rename to packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded covariant optional type parameter.sdstest diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/covariant required type parameter.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded covariant required type parameter.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/covariant required type parameter.sdstest rename to packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded covariant required type parameter.sdstest diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/covariant type parameter with annotation call.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded covariant type parameter with annotation call.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/covariant type parameter with annotation call.sdstest rename to packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded covariant type parameter with annotation call.sdstest diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/invariant optional type parameter.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded invariant optional type parameter.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/invariant optional type parameter.sdstest rename to packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded invariant optional type parameter.sdstest diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/invariant required type parameter.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded invariant required type parameter.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/invariant required type parameter.sdstest rename to packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded invariant required type parameter.sdstest diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/invariant type parameter with annotation call.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded invariant type parameter with annotation call.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/invariant type parameter with annotation call.sdstest rename to packages/safe-ds-lang/tests/resources/formatting/declarations/type parameters/unbounded invariant type parameter with annotation call.sdstest diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded contravariant optional type parameter.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded contravariant optional type parameter.sdstest new file mode 100644 index 000000000..243f63661 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded contravariant optional type parameter.sdstest @@ -0,0 +1,3 @@ +// $TEST$ no_syntax_error + +fun myFunction() diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded contravariant required type parameter.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded contravariant required type parameter.sdstest new file mode 100644 index 000000000..68af9baf8 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded contravariant required type parameter.sdstest @@ -0,0 +1,3 @@ +// $TEST$ no_syntax_error + +fun myFunction() diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded covariant optional type parameter.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded covariant optional type parameter.sdstest new file mode 100644 index 000000000..0e364d12c --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded covariant optional type parameter.sdstest @@ -0,0 +1,3 @@ +// $TEST$ no_syntax_error + +fun myFunction() diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded covariant required type parameter.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded covariant required type parameter.sdstest new file mode 100644 index 000000000..613f0926f --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded covariant required type parameter.sdstest @@ -0,0 +1,3 @@ +// $TEST$ no_syntax_error + +fun myFunction() diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded invariant optional type parameter.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded invariant optional type parameter.sdstest new file mode 100644 index 000000000..93a5eb3db --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded invariant optional type parameter.sdstest @@ -0,0 +1,3 @@ +// $TEST$ no_syntax_error + +fun myFunction() diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded invariant required type parameter.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded invariant required type parameter.sdstest new file mode 100644 index 000000000..e7ce31827 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-bounded invariant required type parameter.sdstest @@ -0,0 +1,3 @@ +// $TEST$ no_syntax_error + +fun myFunction() diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-contravariant optional type parameter.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-unbounded contravariant optional type parameter.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-contravariant optional type parameter.sdstest rename to packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-unbounded contravariant optional type parameter.sdstest diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-contravariant required type parameter.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-unbounded contravariant required type parameter.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-contravariant required type parameter.sdstest rename to packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-unbounded contravariant required type parameter.sdstest diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-covariant optional type parameter.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-unbounded covariant optional type parameter.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-covariant optional type parameter.sdstest rename to packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-unbounded covariant optional type parameter.sdstest diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-covariant required type parameter.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-unbounded covariant required type parameter.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-covariant required type parameter.sdstest rename to packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-unbounded covariant required type parameter.sdstest diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-invariant optional type parameter.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-unbounded invariant optional type parameter.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-invariant optional type parameter.sdstest rename to packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-unbounded invariant optional type parameter.sdstest diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-invariant required type parameter.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-unbounded invariant required type parameter.sdstest similarity index 100% rename from packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-invariant required type parameter.sdstest rename to packages/safe-ds-lang/tests/resources/grammar/declarations/type parameters/good-unbounded invariant required type parameter.sdstest