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

[new-parser] Set namespace of qualified declared types #5947

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3071,6 +3071,20 @@ public void parse_TypeDeclarationWithFields() throws Exception {

}

@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" );
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,12 @@ public BaseDescr visitDeclaredef(DRLParser.DeclaredefContext ctx) {

@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);
}
Expand All @@ -257,9 +260,12 @@ public TypeDeclarationDescr visitTypeDeclaration(DRLParser.TypeDeclarationContex

@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);
Expand Down
Loading