Skip to content

Commit

Permalink
enable metadata key as path elements
Browse files Browse the repository at this point in the history
set meta key on objects
  • Loading branch information
david.al-kanani authored and davidalk committed Jan 31, 2025
1 parent 98d63bd commit 14cfd66
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ result string (1..1)
assertEquals(expected, result);
}


//TODO: read key from an object

@Disabled //TODO: is this syntax needed? if so we need to find a way to get key as a feature from a Data type
@Test
void canSetExternalKeyOnFunctionObjectOutput() {
var model = """
Expand All @@ -204,10 +205,24 @@ myReference string (1..1)
output:
result Foo (1..1)
set result -> a: "someA"
set result -> key: myReference
""";

var code = generatorTestHelper.generateCode(model);
var classes = generatorTestHelper.compileToClasses(code);
var myFunc = functionGeneratorHelper.createFunc(classes, "MyFunc");

var result = functionGeneratorHelper.invokeFunc(myFunc, FieldWithMeta.class, "someExternalReference");

var expected = generatorTestHelper.createInstanceUsingBuilder(classes, new RosettaJavaPackages.RootPackage("com.rosetta.test.model.metafields"), "FieldWithMetaFoo", Map.of(
"value", generatorTestHelper.createInstanceUsingBuilder(classes, new RosettaJavaPackages.RootPackage("com.rosetta.test.model"), "Foo", Map.of(
"a", "someA"
)),
"meta", MetaFields.builder().setExternalKey("someExternalReference")
));

assertEquals(expected, result);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion rosetta-lang/model/RosettaSimple.xcore
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Attribute extends RosettaTypedFeature, RosettaDefinable, Annotated, Refere
}


class Data extends RosettaType, RootElement, References {
class Data extends RosettaType, RootElement, References, Annotated {
refers Data superType
contains RosettaClassSynonym[] synonyms
contains Attribute[] attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ class FunctionGenerator {
return switch(seg.name) {
case "reference": "externalReference"
case "id": "externalKey"
case "key": "externalKey"
case "address": "reference"
default: seg.name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,16 @@ class RosettaTypeProvider extends RosettaExpressionSwitch<RMetaAnnotatedType, Ma
}
}
if (symbol instanceof Annotated) {
return symbol.annotations.RMetaAttributes
var List<RMetaAttribute> typeMetaAttributes = #[]

if (symbol instanceof Attribute) {
val attributeType = symbol.typeCall.typeCallToRType
if (attributeType instanceof RDataType) {
typeMetaAttributes = attributeType.metaAttributes
}
}

return (symbol.annotations.RMetaAttributes + typeMetaAttributes).toList
}
#[]
}
Expand Down

0 comments on commit 14cfd66

Please sign in to comment.