context-mapper-dsl
context-mapper-dsl copied to clipboard
Cannot use "with" keyword to define an Entity implements a trait
Describe the bug
I have defined a Trait and I am trying to use the with keyword of an Entity definition to implement the Trait.
I get the following error mismatched input 'ith' expecting RULE_CLOSE(org.eclipse.xtext.diagnostics.Diagnostic.Syntax)
To Reproduce Steps to reproduce the behavior:
- Define a Trait
Trait newTrait {} - Define a Entity
Entity newEntity with newTrait {}
Expected behavior
An Entity can implement a Trait with the with keyword
Looking at the DSL java docs I can see a getTraits() function of the DomainObject type https://www.javadoc.io/doc/org.contextmapper/context-mapper-dsl/latest/org/contextmapper/tactic/dsl/tacticdsl/DomainObject.html
IDE and Plugin (please complete the following information): I am using the ContextMapper plugin for VSCode @ v6.12.0
I'm experiencing the same on my side. Latest version to date of the VSCode extension.
This snippet
BoundedContext PartyManagementContext {
Aggregate Party {
Trait Extensible {
String type_
String baseType
URI schemaLocation
}
Trait Addressable {
String id
BigDecimal href
}
Entity Individual {
aggregateRoot
String firstname size = "30"
String lastname
- List<Address> addresses
}
Entity Address with@Addressable with@Extensible {
String street
String city
}
}
}
works in my context-mapper 6.12.0 plugin. I did not yet investigate if the traits are really arriving in the model.
Is that syntax valid, though? Seems weird to me, but I can't find any reference in the website docs, only a single mention in the Freemarker Generator section. The code, however, displays as that's the syntax it's currently using, but I'd still like to know if that's the intended syntax or is an implementation error (I'd expect a space between "with" and the trait name): https://github.com/ContextMapper/context-mapper-dsl/blob/981d5beaea768787e5677a0e4091458264302d0b/org.contextmapper.dsl/src/org/contextmapper/tactic/dsl/TacticDDDLanguage.xtext#L209
Thank you @astmuc for uncovering the supported syntax. I agree with @CesarD that it looks a bit odd, especially given the extends @SomeEntity (with space before @) syntax.
But happy it works at least!
I can confirm it is exposed in the model.
Should I leave this issue open given the above suspicions?
I suggest to keep the ticket open as question about the right syntax. Sculpture documentation says the @ is needed for internal references. On the other hand it is optional in the xtext syntax definition.
It is optional, but then it is not a reference. With the @, the a validator actually checks that the type is modelled. Without the @ you can write any type without having to model it explicitely.
Ok thanks - will leave open.
I guess the outstanding question is , why is does the syntax differ between:
Entity NewEntity extends @SomeEntity
Entity NewEntity with@SomeTrait
The reason for this strange behavior seems to be a special meaning of 'with' inside of a DSL created by Xtext. If i replace 'with' by 'using' in the tactics language definition file, then one can use the space after 'using' as expected.
We took the syntax for the tactical DDD parts from the Sculptor project. I suggest to not change it at this point. The syntax takes some getting used to, agreed, but changes would need a new major Context Mapper release (breaking change).
But perhaps the main question to get an answer is: is it really correct to have such syntax "with@xxxxx" or it should have been "with @xxxxx" (emphasis in the separating space between "with" and "@") ??
I'm fine with either, but it looked like a typo, hence the question.