Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some N&N related to my chances and others' changes #47

Merged
merged 11 commits into from
May 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ As you might have recognized, the number of people contributing to Xtext & Xtend

## Relevant changes

## Initial support for Java 21

See the corresponding section in Xtext release notes.

### Normalization of EOLs in Xbase multi-line strings

See the corresponding section in Xtext release notes.
Expand Down
51 changes: 50 additions & 1 deletion xtext-website/_posts/releasenotes/2024-05-28-version-2-35-0.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ As you might have recognized, the number of people contributing to Xtext on a re

## Relevant changes

### Initial support for Java 21

In Eclipse, using a recent JDT version, Xbase languages, including Xtend, can access Java 21 generated byte-code and can refer to Java records.

For Maven/Tycho builds, e.g., `xtext-maven-plugin` and `xtend-maven-plugin`, a new version of `jdt.core`, e.g., 3.37.0, must be forced (currently, in the BOM, we still use an older version of JDT).
This can be achieved by passing the system property `-Djava-21` when running Maven (our BOM will automatically activate the new version of JDT).
Alternatively, you can place the line `-Djava-21` in your `.mvn/maven.config` file in the root folder.

For Gradle, you need to force the dependency of the new version of `jdt.core`, e.g., 3.37.0.

### Normalization of EOLs in Xbase multi-line strings

In Xbase languages (including Xtend), multi-line strings (that is, strings that span several lines, NOT Xtend template expressions) are now normalized concerning end-of-line characters, following the same strategies of [Normalization Of Line Terminators in Java Text Blocks](https://docs.oracle.com/en/java/javase/21/text-blocks/index.html#normalization-of-line-terminators): Windows CR in the DSL textual sources will not be part of the string in the generated Java code, which will only contain Unix LF.
Expand All @@ -40,16 +50,49 @@ String s = "a multi\r\nline string";

Note that the behavior for explicit escape sequences (`\\r`) will remain the same as before.

### Testing
### Automatic validation for Xbase languages

The new `JvmGenericTypeValidator` was introduced to automatically perform several Java-related checks in the hierarchy of the inferred `JvmGenericType`s of an Xbase language, with the corresponding error reporting.
For example, cycles in a hierarchy, extension of a final class, proper extension of an abstract class (do you implement all the abstract methods or declare the inferred class as abstract?), proper method overriding, etc. It also performs duplicate elements checks, like duplicate parameter names, duplicate fields and duplicate methods (keeping the type-erasure into consideration when using types with arguments).

This mechanism assumes that you implement the `JvmModelInferrer` "correctly".
It only checks the first inferred `JvmGenericType` for the same DSL element (i.e., if for an element `Entity` you infer two `JvmGenericType`s, `t1` and `t2`, only the first one will be checked).
Moreover, it only checks Jvm model elements with an associated source element.
Concerning intended classes to extend and interfaces to extend/implement, it assumes the model inferrer uses the new `JvmTypesBuilder#setSuperClass(JvmDeclaredType, JvmTypeReference)` and `JvmTypesBuilder#addSuperInterface(JvmDeclaredType, JvmTypeReference)`, respectively.

Currently, this validator must be enabled explicitly through the `composedCheck` in the MWE2 file or the `@ComposedChecks` annotation in the validator, e.g., `@ComposedChecks(validators = JvmGenericTypeValidator.class)`.

The Domainmodel example now uses this validator.
The Xtend validator has been refactored to also use this validator.

### Maven building

When using `xtext-maven-plugin` for Xbase languages, relative paths (instead of absolute paths) are now generated in the `._trace` files.

The configuration option `writeStorageResources` has been added to `xtext-maven-plugin` to write the semantic model, the resource description, and optionally the node model to a ResourceStorage (`.bin` files).
See [this integration test](https://github.com/eclipse/xtext/tree/main/org.eclipse.xtext.maven.plugin/src/test/resources/it/generate/simple-lang-write-storage-resources) for an example.

### Runtime Testing

The `AbstractFormatterTest` base class has been added to the `org.eclipse.xtext.testing` package to provide a convenient way to test the formatter capabilities. The Xtext Domainmodel example project and the Xtend code base have been extended by concrete formatter test cases to demonstrate the usage of this framework class.

The generated `InjectorProvider` for runtime tests has been improved to make customizations easier w.r.t. OSGI/Maven environments (see [https://github.com/eclipse/xtext/pull/3042](https://github.com/eclipse/xtext/pull/3042)).

The base class `AbstractXtextTests`, for "old"-style testing, is now part of `org.eclipse.xtext.testing`. (See also the removal notice below.)

Two new methods were added `org.eclipse.xtext.xbase.testing.CompilationTestHelper.Result.assertNoErrors()`/`assertNoIssues()` for checking whether during the compilation of the input sources errors, respectively, errors or warnings, were detected.

### UI Testing

The `AbstractContentAssistTest` class has been extended by API methods to provide a convenient way to test proposals from several resources. The `StatemachineContentAssistTest` test class of the Xtext Statemachine example project demonstrates the usage of these new API methods.

## Upgrades

* GSON is now on 2.11
* Guava was update to 33.2
* lsp4j is now on 0.23.x
* MWE(2) is now on 1.12/2.18

## Deprecations

The method `org.eclipse.xtext.xbase.lib.IterableExtensions.last(Iterable<T>)` has been deprecated in favor of the new `org.eclipse.xtext.xbase.lib.IterableExtensions.lastOrNull(Iterable<T>)`.
Expand All @@ -60,6 +103,12 @@ The problem is that our extension method `last` returns null when the collection
We encourage everyone to pay attention to such deprecations and switch to the new `lastOrNull`, which retains the semantics of `last`, **before** switching to Java 21.
To keep the consistency between `IterableExtensions` and `IteratorExtensions` we also deprecated `last` in the latter and introduced `lastOrNull` in `IteratorExtensions`.

## Future removals notice

In the next release, 2.36.0, the long time deprecated `org.eclipse.xtext.junit4` and `org.eclipse.xtext.xbase.junit` will be removed.
The projects `org.eclipse.xtext.testing`, `org.eclipse.xtext.ui.testing`, `org.eclipse.xtext.xbase.testing` and `org.eclipse.xtext.xbase.ui.testing` already provide replacements for the above deprecated projects.
Note that the old base class `AbstractXtextTests` is now part of `org.eclipse.xtext.testing`.

## Credits

The Xtext project is thankful for the dedication of each committer and contributor. This release has been made possible by the following persons (in order of the number of contributed commits to this release).
Expand Down
14 changes: 14 additions & 0 deletions xtext-website/documentation/305_xbase.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,20 @@ The Xbase framework will automatically switch between the JVM element or the DSL

By default, the inferred model is [indexed](303_runtime_concepts.html#global-scopes), so it can be cross referenced from other models.

### Validation

Besides your custom validations, you can use [JvmGenericTypeValidator]({{site.src.xtext}}/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/validation/JvmGenericTypeValidator.java), introduced in version 2.35.0. This automatically perform several Java-related checks in the hierarchy of the inferred [JvmGenericType]({{site.src.xtext}}/org.eclipse.xtext.common.types/emf-gen/org/eclipse/xtext/common/types/JvmGenericType.java)s of an Xbase language, with the corresponding error reporting.
For example, cycles in a hierarchy, extension of a final class, proper extension of an abstract class (do you implement all the abstract methods or declare the inferred class as abstract?), proper method overriding, etc. It also performs duplicate elements checks, like duplicate parameter names, duplicate fields and duplicate methods (keeping the type-erasure into consideration when using types with arguments).

This mechanism assumes that you implement the [IJvmModelInferrer]({{site.src.xtext}}/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/jvmmodel/IJvmModelInferrer.java) "correctly".
It only checks the first inferred `JvmGenericType` for the same DSL element (i.e., if for an element `Entity` you infer two `JvmGenericType`s, `t1` and `t2`, only the first one will be checked).
Moreover, it only checks Jvm model elements with an associated source element.
Concerning intended classes to extend and interfaces to extend/implement, it assumes the model inferrer uses the [JvmTypesBuilder]({{site.src.xtext}}/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/jvmmodel/JvmTypesBuilder.java) methods `setSuperClass(JvmDeclaredType, JvmTypeReference)` and `addSuperInterface(JvmDeclaredType, JvmTypeReference)`, respectively.

Currently, this validator must be enabled explicitly through the `composedCheck` in the MWE2 file or the `@ComposedChecks` annotation in the validator, e.g., `@ComposedChecks(validators = JvmGenericTypeValidator.class)`.

The Domainmodel example uses this validator.

## Using Xbase Expressions {#xbase-expressions}

Xbase is an expression language that can be embedded into Xtext languages. Its syntax is close to Java, but it additionally offers type inference, lambda expressions, a powerful switch expression and a lot more. For details on this expression language, please consult the [reference documentation](#xbase-language-ref-introduction) and the Xbase tutorial *(File &rarr; New &rarr; Example &rarr; Xtext Examples &rarr; Xbase Tutorial)*.
Expand Down
Loading