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

Story/3511/with meta set key #916

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -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
Loading