Skip to content

Commit

Permalink
Mark org as Pure Reserved Keyword (#2387)
Browse files Browse the repository at this point in the history
Set org as a Reserved keyword
  • Loading branch information
mrudula-gs authored Oct 27, 2023
1 parent 0b21b21 commit 27ff539
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<access.private>> 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] |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ meta::pure::mapping::modelToModel::test::alloy::constraints::testQueryOnTypeWith
assert(jsonEquivalent('{"name":"FirmX"}'->parseJSON(), $result.values->toOne()->parseJSON()));
}

function <<meta::pure::profiles::test.Test, meta::pure::profiles::test.AlloyOnly>>
{ 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 <<meta::pure::profiles::test.Test, meta::pure::profiles::test.AlloyOnly>>
{ serverVersion.start='v1_19_0' }
meta::pure::mapping::modelToModel::test::alloy::constraints::testQueryOnSourceTypeWithFailingConstraintSucceedsWithConstraintsDisabled():Boolean[1]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,13 +1038,18 @@ function meta::external::language::java::transform::newConventions(extensions :

function <<access.private>> 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 <<access.private>> meta::external::language::java::transform::buildJavaKeywordReplacementMap():Map<String, String>[1]
function <<access.private>> meta::external::language::java::transform::buildReservedKeywordReplacementMap():Map<String, String>[1]
{
javaKeywords()->map(kw | pair($kw, '_' + $kw))->newMap()
reservedKeywords()->buildKeywordReplacementMap()
}

function meta::external::language::java::transform::buildKeywordReplacementMap(Keywords: String[*]):Map<String, String>[1]
{
$Keywords->map(kw | pair($kw, '_' + $kw))->newMap()
}

function meta::external::language::java::transform::setBasePackageName(conventions:Conventions[1], name:String[1]): Conventions[1]
Expand Down Expand Up @@ -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 <<access.private>> meta::external::language::java::transform::replaceIllegalSymbols(symbol: String[1]): String[1]
Expand Down Expand Up @@ -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 <<access.private>> meta::external::language::java::transform::startsWithNumber(s: String[1]): Boolean[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 27ff539

Please sign in to comment.