context-mapper-dsl icon indicating copy to clipboard operation
context-mapper-dsl copied to clipboard

Cannot use "with" keyword to define an Entity implements a trait

Open simonwfarrow opened this issue 1 year ago • 10 comments

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:

  1. Define a Trait Trait newTrait {}
  2. 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

simonwfarrow avatar Oct 24 '24 10:10 simonwfarrow

I'm experiencing the same on my side. Latest version to date of the VSCode extension.

CesarD avatar Oct 27 '24 11:10 CesarD

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.

astmuc avatar Nov 12 '24 17:11 astmuc

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

CesarD avatar Nov 12 '24 18:11 CesarD

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?

simonwfarrow avatar Nov 13 '24 09:11 simonwfarrow

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.

astmuc avatar Nov 13 '24 09:11 astmuc

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.

stefan-ka avatar Nov 13 '24 09:11 stefan-ka

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

simonwfarrow avatar Nov 13 '24 09:11 simonwfarrow

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.

astmuc avatar Dec 09 '24 08:12 astmuc

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).

stefan-ka avatar Dec 19 '24 13:12 stefan-ka

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.

CesarD avatar Dec 22 '24 15:12 CesarD