From 27ff539b60858511b5a2b12db0610449986d4220 Mon Sep 17 00:00:00 2001 From: mrudula-gs <89876341+mrudula-gs@users.noreply.github.com> Date: Fri, 27 Oct 2023 13:06:33 -0400 Subject: [PATCH] Mark org as Pure Reserved Keyword (#2387) Set org as a Reserved keyword --- .../core_protocol_generation/generation.pure | 8 +++++- .../store/m2m/tests/legend/constraints.pure | 25 ++++++++++++++++++- .../generation/conventions.pure | 15 +++++++---- .../metamodel.pure | 10 ++++++++ 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/legend-engine-core/legend-engine-core-language-pure/legend-engine-protocol-generation-pure/src/main/resources/core_protocol_generation/generation.pure b/legend-engine-core/legend-engine-core-language-pure/legend-engine-protocol-generation-pure/src/main/resources/core_protocol_generation/generation.pure index ed2a6a417fa..83e534eebb8 100644 --- a/legend-engine-core/legend-engine-core-language-pure/legend-engine-protocol-generation-pure/src/main/resources/core_protocol_generation/generation.pure +++ b/legend-engine-core/legend-engine-core-language-pure/legend-engine-protocol-generation-pure/src/main/resources/core_protocol_generation/generation.pure @@ -513,12 +513,18 @@ function meta::protocols::generation::java::conventions(purePackage:String[1], j | '.' + $packageStr; ); pair( - $c->identifier($package), + javaIdentifier($package), $c->identifier($x.name->toOne())->toUpperFirstCharacter()->toOne() );} ); } +function <> meta::protocols::generation::java::javaIdentifier(name: String[1]):String[1] +{ + let keywordMap = javaKeywords()->buildKeywordReplacementMap(); + $name->sanitizeIdentifier($keywordMap); +} + function meta::protocols::generation::java::addProvidedTypesFromDependencies(conventions: Conventions[1], dependencies: Configuration[*]): Conventions[1] { $dependencies->fold({config: Configuration[1], c1: Conventions[1] | diff --git a/legend-engine-pure/legend-engine-pure-code/legend-engine-pure-code-compiled-core/src/main/resources/core/store/m2m/tests/legend/constraints.pure b/legend-engine-pure/legend-engine-pure-code/legend-engine-pure-code-compiled-core/src/main/resources/core/store/m2m/tests/legend/constraints.pure index 5655669e235..f82278765af 100644 --- a/legend-engine-pure/legend-engine-pure-code/legend-engine-pure-code-compiled-core/src/main/resources/core/store/m2m/tests/legend/constraints.pure +++ b/legend-engine-pure/legend-engine-pure-code/legend-engine-pure-code-compiled-core/src/main/resources/core/store/m2m/tests/legend/constraints.pure @@ -63,6 +63,26 @@ meta::pure::mapping::modelToModel::test::alloy::constraints::testQueryOnTypeWith assert(jsonEquivalent('{"name":"FirmX"}'->parseJSON(), $result.values->toOne()->parseJSON())); } +function <> +{ serverVersion.start='v1_19_0' } +meta::pure::mapping::modelToModel::test::alloy::constraints::testGraphFetchWithPackageConflictingPropertyName():Boolean[1] +{ + let result = execute( |Firm.all()->graphFetchChecked(#{Firm {organization} }#)->serialize(#{Firm {organization} }#), + m2mconstraintmapping1, + ^Runtime( + connectionStores = ^ConnectionStore( + element=^ModelStore(), + connection= ^JsonModelConnection( + class=_Firm, + url='data:application/json,{"name":"FirmX","org":"orgA"}' + ) + ) + ), + meta::pure::extension::defaultExtensions() + ); + assert(jsonEquivalent('{"defects":[{"path":[],"enforcementLevel":"Error","ruleType":"ClassConstraint","externalId":null,"id":"0","ruleDefinerPath":"meta::pure::mapping::modelToModel::test::alloy::constraints::Firm","message":"Constraint :[0] violated in the Class Firm"}],"source":{"defects":[],"source":{"number":1,"record":"{\\"name\\":\\"FirmX\\",\\"org\\":\\"orgA\\"}"},"value":{"org":"orgA","employees":[]}},"value":{"organization":"orgA"}}'->parseJSON(), $result.values->toOne()->parseJSON())); +} + function <> { serverVersion.start='v1_19_0' } meta::pure::mapping::modelToModel::test::alloy::constraints::testQueryOnSourceTypeWithFailingConstraintSucceedsWithConstraintsDisabled():Boolean[1] @@ -386,6 +406,7 @@ Class meta::pure::mapping::modelToModel::test::alloy::constraints::Firm { name: String[1]; employees: meta::pure::mapping::modelToModel::test::alloy::constraints::Person[*]; + organization: String[1]; } Class meta::pure::mapping::modelToModel::test::alloy::constraints::Firm2 @@ -403,6 +424,7 @@ Class meta::pure::mapping::modelToModel::test::alloy::constraints::_Firm { name: String[1]; employees:meta::pure::mapping::modelToModel::test::alloy::constraints::_Person[*]; + org: String[1]; } Class meta::pure::mapping::modelToModel::test::alloy::constraints::_Firm2 @@ -680,7 +702,8 @@ Mapping meta::pure::mapping::modelToModel::test::alloy::constraints::m2mconstrai { ~src meta::pure::mapping::modelToModel::test::alloy::constraints::_Firm name: $src.name, - employees: $src.employees + employees: $src.employees, + organization: $src.org } meta::pure::mapping::modelToModel::test::alloy::constraints::Person: Pure diff --git a/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/generation/conventions.pure b/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/generation/conventions.pure index cd9b5d2d9b8..099831f1ae1 100644 --- a/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/generation/conventions.pure +++ b/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/generation/conventions.pure @@ -1038,13 +1038,18 @@ function meta::external::language::java::transform::newConventions(extensions : function <> meta::external::language::java::transform::buildIdentifierFactory():Function<{String[1]->String[1]}>[1] { - let keywordMap = buildJavaKeywordReplacementMap(); + let keywordMap = buildReservedKeywordReplacementMap(); {name:String[1] | $name->sanitizeIdentifier($keywordMap)}; } -function <> meta::external::language::java::transform::buildJavaKeywordReplacementMap():Map[1] +function <> meta::external::language::java::transform::buildReservedKeywordReplacementMap():Map[1] { - javaKeywords()->map(kw | pair($kw, '_' + $kw))->newMap() + reservedKeywords()->buildKeywordReplacementMap() +} + +function meta::external::language::java::transform::buildKeywordReplacementMap(Keywords: String[*]):Map[1] +{ + $Keywords->map(kw | pair($kw, '_' + $kw))->newMap() } function meta::external::language::java::transform::setBasePackageName(conventions:Conventions[1], name:String[1]): Conventions[1] @@ -1265,7 +1270,7 @@ function meta::external::language::java::transform::sanitizeIdentifier(name: Str function meta::external::language::java::transform::sanitizeIdentifier(name: String[1]): String[1] { - $name->sanitizeIdentifier(buildJavaKeywordReplacementMap()) + $name->sanitizeIdentifier(buildReservedKeywordReplacementMap()) } function <> meta::external::language::java::transform::replaceIllegalSymbols(symbol: String[1]): String[1] @@ -1293,7 +1298,7 @@ function meta::external::language::java::transform::sanitizeJavaKeywords(name: S function meta::external::language::java::transform::sanitizeJavaKeywords(name: String[1]): String[1] { - $name->sanitizeJavaKeywords(buildJavaKeywordReplacementMap()); + $name->sanitizeJavaKeywords(buildReservedKeywordReplacementMap()); } function <> meta::external::language::java::transform::startsWithNumber(s: String[1]): Boolean[1] diff --git a/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/metamodel.pure b/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/metamodel.pure index d41a89a0d0e..9ce339c3451 100644 --- a/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/metamodel.pure +++ b/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/metamodel.pure @@ -799,6 +799,16 @@ function meta::external::language::java::metamodel::javaKeywords(): String[*] ]; } +function meta::external::language::java::metamodel::modelPropertyKeywords(): String[*] +{ + ['com', 'org']; +} + +function meta::external::language::java::metamodel::reservedKeywords(): String[*] +{ + javaKeywords()->concatenate(modelPropertyKeywords()); +} + function meta::external::language::java::metamodel::isJavaLang(pkg: meta::external::language::java::metamodel::Package[1]):Boolean[1] { $pkg.name == 'lang'