From 4d10ea1a5912000ac5f131dd66765880cfabc091 Mon Sep 17 00:00:00 2001 From: Yuri Blankenstein Date: Wed, 2 Sep 2026 15:35:31 +0200 Subject: [PATCH] [#421] Validating mandatory asserts --- .../ProductIdeProposalProvider.xtend | 7 ++++- .../nl/esi/comma/assertthat/AssertThat.xtext | 4 +-- .../validation/AssertThatValidator.xtend | 29 +++++++++---------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/bundles/nl.asml.matala.product.ide/src/nl/asml/matala/product/ide/contentassist/ProductIdeProposalProvider.xtend b/bundles/nl.asml.matala.product.ide/src/nl/asml/matala/product/ide/contentassist/ProductIdeProposalProvider.xtend index a83106d3..2d9b5f6a 100644 --- a/bundles/nl.asml.matala.product.ide/src/nl/asml/matala/product/ide/contentassist/ProductIdeProposalProvider.xtend +++ b/bundles/nl.asml.matala.product.ide/src/nl/asml/matala/product/ide/contentassist/ProductIdeProposalProvider.xtend @@ -31,6 +31,7 @@ import org.eclipse.xtext.EcoreUtil2 import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext import static extension nl.esi.xtext.actions.utilities.ActionsUtilities.* +import nl.esi.comma.assertthat.assertThat.DataAssertions /** * See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#content-assist @@ -49,7 +50,7 @@ class ProductIdeProposalProvider extends AbstractProductIdeProposalProvider { case expressionGrammarAccess.expressionLevel8Access.fieldRecordFieldCrossReference_1_0_2_0, case actionsGrammarAccess.fieldAccessExpAccess.fieldRecordFieldCrossReference_1_2_0: [ val field = EObjectOrProxy as RecordField - return context.isReferenceUpdate + return context.isReferenceUpdate || context.isAssertion ? !context.suppressedFields.contains(field) : field.kind != RecordFieldKind.SYMBOLIC ] @@ -77,6 +78,10 @@ class ProductIdeProposalProvider extends AbstractProductIdeProposalProvider { return EcoreUtil2.getContainerOfType(context.currentModel, DataReferences) !== null } + protected def boolean isAssertion(ContentAssistContext context) { + return EcoreUtil2.getContainerOfType(context.currentModel, DataAssertions) !== null + } + protected def getSuppressedFields(ContentAssistContext context) { val suppressedVarFields = EcoreUtil2.getContainerOfType(context.currentModel, UpdateOutVar)?.suppress?. varFields ?: Collections.emptyList diff --git a/bundles/nl.esi.comma.assertthat/src/nl/esi/comma/assertthat/AssertThat.xtext b/bundles/nl.esi.comma.assertthat/src/nl/esi/comma/assertthat/AssertThat.xtext index dab47ab4..e9da582e 100644 --- a/bundles/nl.esi.comma.assertthat/src/nl/esi/comma/assertthat/AssertThat.xtext +++ b/bundles/nl.esi.comma.assertthat/src/nl/esi/comma/assertthat/AssertThat.xtext @@ -18,8 +18,8 @@ import "http://www.esi.nl/xtext/expressions/Expression" as expr DataAssertions: {DataAssertions} 'assertions' name = ID '{' - constr += DataAssertionItem+ - '}' + constr += DataAssertionItem* + '}' ; DataAssertionItem: diff --git a/bundles/nl.esi.comma.assertthat/src/nl/esi/comma/assertthat/validation/AssertThatValidator.xtend b/bundles/nl.esi.comma.assertthat/src/nl/esi/comma/assertthat/validation/AssertThatValidator.xtend index 688ddf42..64d6e256 100644 --- a/bundles/nl.esi.comma.assertthat/src/nl/esi/comma/assertthat/validation/AssertThatValidator.xtend +++ b/bundles/nl.esi.comma.assertthat/src/nl/esi/comma/assertthat/validation/AssertThatValidator.xtend @@ -1,13 +1,13 @@ /** * Copyright (c) 2024, 2025 TNO-ESI - * + * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. - * + * * This program and the accompanying materials are made available * under the terms of the MIT License which is available at * https://opensource.org/licenses/MIT - * + * * SPDX-License-Identifier: MIT */ /* @@ -15,23 +15,20 @@ */ package nl.esi.comma.assertthat.validation +import nl.esi.comma.assertthat.assertThat.AssertThatPackage +import nl.esi.comma.assertthat.assertThat.DataAssertions +import org.eclipse.xtext.validation.Check /** * This class contains custom validation rules. - * + * * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation */ class AssertThatValidator extends AbstractAssertThatValidator { - -// public static val INVALID_NAME = 'invalidName' -// -// @Check -// def checkGreetingStartsWithCapital(Greeting greeting) { -// if (!Character.isUpperCase(greeting.name.charAt(0))) { -// warning('Name should start with a capital', -// AssertThatPackage.Literals.GREETING__NAME, -// INVALID_NAME) -// } -// } - + @Check + def checkGreetingStartsWithCapital(DataAssertions dataAssertions) { + if (dataAssertions.constr.isNullOrEmpty) { + error('At least 1 assertion is required', AssertThatPackage.Literals.DATA_ASSERTIONS__CONSTR) + } + } }