This is an automated email from the ASF dual-hosted git repository.

mariofusco pushed a commit to branch dev-new-parser
in repository https://gitbox.apache.org/repos/asf/incubator-kie-drools.git


The following commit(s) were added to refs/heads/dev-new-parser by this push:
     new bf72a00900 Set namespace of qualified declared types (#5947)
bf72a00900 is described below

commit bf72a00900cfb01ea6e745859f860607f207b578
Author: Jiří Locker <[email protected]>
AuthorDate: Wed May 15 08:11:38 2024 +0200

    Set namespace of qualified declared types (#5947)
---
 .../drl/parser/antlr4/MiscDRLParserTest.java       | 14 +++++++++++
 .../parser/antlr4/qualified_type_declaration.drl   | 27 ++++++++++++++++++++++
 .../drools/drl/parser/antlr4/DRLVisitorImpl.java   | 10 ++++++--
 3 files changed, 49 insertions(+), 2 deletions(-)

diff --git 
a/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java
 
b/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java
index 8b220177df..8075c89aed 100644
--- 
a/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java
+++ 
b/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java
@@ -3071,6 +3071,20 @@ class MiscDRLParserTest {
 
     }
 
+    @Test
+    public void parse_QualifiedTypeDeclaration() throws Exception {
+        final PackageDescr pkg = parseAndGetPackageDescrFromFile(
+                                                               
"qualified_type_declaration.drl" );
+
+        TypeDeclarationDescr someFact = pkg.getTypeDeclarations().get( 0 );
+        assertThat(someFact.getTypeName()).isEqualTo("SomeFact");
+        assertThat(someFact.getNamespace()).isEqualTo("com.sample1");
+
+        EnumDeclarationDescr color = pkg.getEnumDeclarations().get( 0 );
+        assertThat(color.getTypeName()).isEqualTo("Color");
+        assertThat(color.getNamespace()).isEqualTo("com.sample2");
+    }
+
     @Test
     public void parenthesesOneLevelNestWithThreeSiblings() throws Exception {
         final PackageDescr pkg = parseAndGetPackageDescrFromFile( 
"Rule_with_nested_LHS.drl" );
diff --git 
a/drools-drl/drools-drl-parser-tests/src/test/resources/org/drools/drl/parser/antlr4/qualified_type_declaration.drl
 
b/drools-drl/drools-drl-parser-tests/src/test/resources/org/drools/drl/parser/antlr4/qualified_type_declaration.drl
new file mode 100644
index 0000000000..0eaa706711
--- /dev/null
+++ 
b/drools-drl/drools-drl-parser-tests/src/test/resources/org/drools/drl/parser/antlr4/qualified_type_declaration.drl
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
See the License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.drools.compiler.test;
+
+declare com.sample1.SomeFact
+    name : String
+    age: Integer
+end
+
+declare enum com.sample2.Color
+    WHITE;
+end
diff --git 
a/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java
 
b/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java
index 4b0036e669..49a527612a 100644
--- 
a/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java
+++ 
b/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java
@@ -235,9 +235,12 @@ public class DRLVisitorImpl extends 
DRLParserBaseVisitor<Object> {
 
     @Override
     public TypeDeclarationDescr 
visitTypeDeclaration(DRLParser.TypeDeclarationContext ctx) {
-        TypeDeclarationDescr typeDeclarationDescr = 
BaseDescrFactory.builder(new TypeDeclarationDescr(ctx.name.getText()))
+        TypeDeclarationDescr typeDeclarationDescr = 
BaseDescrFactory.builder(new TypeDeclarationDescr())
                 .withParserRuleContext(ctx)
                 .build();
+
+        typeDeclarationDescr.setTypeName(ctx.name.getText());
+
         if (ctx.DRL_TRAIT() != null) {
             typeDeclarationDescr.setTrait(true);
         }
@@ -257,9 +260,12 @@ public class DRLVisitorImpl extends 
DRLParserBaseVisitor<Object> {
 
     @Override
     public EnumDeclarationDescr 
visitEnumDeclaration(DRLParser.EnumDeclarationContext ctx) {
-        EnumDeclarationDescr enumDeclarationDescr = 
BaseDescrFactory.builder(new EnumDeclarationDescr(ctx.name.getText()))
+        EnumDeclarationDescr enumDeclarationDescr = 
BaseDescrFactory.builder(new EnumDeclarationDescr())
                 .withParserRuleContext(ctx)
                 .build();
+
+        enumDeclarationDescr.setTypeName(ctx.name.getText());
+
         ctx.drlAnnotation().stream()
                 .map(this::visitDrlAnnotation)
                 .forEach(enumDeclarationDescr::addAnnotation);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to