From 60f8236c6b8174a41b6af31f912315059df1cf56 Mon Sep 17 00:00:00 2001 From: Tommaso Fonda Date: Fri, 9 Aug 2024 16:36:16 +0200 Subject: [PATCH] xtext: XtextValidator: Allow fragments in unordered groups Fixes #3068 Signed-off-by: Tommaso Fonda --- .../xtext/xtext/XtextValidationTest.java | 17 +++++++++++++++++ .../org/eclipse/xtext/xtext/XtextValidator.java | 2 ++ 2 files changed, 19 insertions(+) diff --git a/org.eclipse.xtext.tests/src/org/eclipse/xtext/xtext/XtextValidationTest.java b/org.eclipse.xtext.tests/src/org/eclipse/xtext/xtext/XtextValidationTest.java index 76768a8c6b0..7b10d2ada83 100644 --- a/org.eclipse.xtext.tests/src/org/eclipse/xtext/xtext/XtextValidationTest.java +++ b/org.eclipse.xtext.tests/src/org/eclipse/xtext/xtext/XtextValidationTest.java @@ -1342,6 +1342,23 @@ public boolean apply(Diagnostic input) { messageAcceptor.validate(); } + @Test public void testCheckFragmentCallInUnorderedGroup() throws Exception { + XtextValidator validator = get(XtextValidator.class); + UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup(); + RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall(); + TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef(); + typeRef.setClassifier(EcorePackage.Literals.EOBJECT); + ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); + parserRule.setType(typeRef); + parserRule.setFragment(true); + ruleCall.setRule(parserRule); + unorderedGroup.getElements().add(ruleCall); + ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false); + validator.setMessageAcceptor(messageAcceptor); + validator.checkRuleCallInUnorderedGroup(ruleCall); + messageAcceptor.validate(); + } + @Test public void testCheckRuleCallInUnorderedGroup_01() throws Exception { XtextValidator validator = get(XtextValidator.class); UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup(); diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/xtext/XtextValidator.java b/org.eclipse.xtext/src/org/eclipse/xtext/xtext/XtextValidator.java index 61e26dc1a64..d70f4aefba8 100644 --- a/org.eclipse.xtext/src/org/eclipse/xtext/xtext/XtextValidator.java +++ b/org.eclipse.xtext/src/org/eclipse/xtext/xtext/XtextValidator.java @@ -1136,6 +1136,8 @@ public void checkRuleCallInUnorderedGroup(final RuleCall call) { return; if (GrammarUtil.isAssigned(call)) return; + if (GrammarUtil.isEObjectFragmentRuleCall(call)) + return; if (EcoreUtil2.getContainerOfType(call, UnorderedGroup.class) != null) error( "Unassigned rule calls may not be used in unordered groups.",