@RunWith(XtextRunner) @InjectWith(DomainmodelInjectorProvider) class DomainmodelDotGeneratorTest { ... @Test def test13() { ''' import java.util.List entity Blog { title: String posts: List<Post> op addPost(Post post) : void { } op getPosts() : List<Post> {} } entity HasAuthor { author: String op getAuthor() { author } op setAuthor() : void {} } entity Post extends HasAuthor { title: String content: String comments: List<Comment> } entity Comment extends HasAuthor { content: String } '''.assertCompilesTo(''' digraph { // layout=sfdp nodesep=1.2 rankdir=BT node [shape=record style="filled, bold" color="#CE970D" fillcolor="#FAEAC1" fontcolor="#CE970D"] // nodes Blog [ label = "{ Blog| title : String\l| addPost(Post post) : void\lgetPosts() : List\<Post\>\l }" ] HasAuthor [ label = "{ HasAuthor| author : String\l| getAuthor() : String\lsetAuthor() : void\l }" ] Post [ label = "{ Post| title : String\lcontent : String\l| }" ] Comment [ label = "{ Comment| content : String\l| }" ] // inheritance edges edge[arrowhead=onormal color="#CE970D" fontcolor="#CE970D"] Post -> HasAuthor Comment -> HasAuthor // association edges edge[arrowhead=normal arrowtail=diamond dir=both constraint=false] Blog -> Post [headlabel="posts\n[0..*]"] Post -> Comment [headlabel="comments\n[0..*]"] } ''') } ... }
class DomainmodelDotGenerator extends JvmModelGenerator { ... override void doGenerate(Resource input, IFileSystemAccess fsa) { fsa.generateFile(input.fileName, (input.contents.head as DomainModel).toDot) } def toDot(DomainModel it) ''' digraph { // layout=sfdp nodesep=1.2 rankdir=BT «generateEntities» «generateInheritanceConnections» «generateAssociationConnections» } ''' private def generateEntities(DomainModel it) ''' node [shape=record style="filled, bold" color="#CE970D" fillcolor="#FAEAC1" fontcolor="#CE970D"] // nodes «FOR entity : entities» «entity.generate» «ENDFOR» ''' private def generate(Entity it) ''' «name» [ label = "{ «name»| «generateProperties»| «generateOperations» }" ] ''' ... private def generateInheritanceConnections(DomainModel it) ''' // inheritance edges edge[arrowhead=onormal color="#CE970D" fontcolor="#CE970D"] «FOR entity : entities» «IF entity.superType!==null» «entity.name» -> «entity.superType.simpleName» «ENDIF» «ENDFOR» ''' private def generateAssociationConnections(DomainModel it) ''' // association edges edge[arrowhead=normal arrowtail=diamond dir=both constraint=false] «FOR entity : entities» «FOR property : entity.associationProperties» «entity.name» -> «property.type.determineType.simpleName» [headlabel="«property.associationLabel»"] «ENDFOR» «ENDFOR» ''' ... }
The Xtext State-Machine Example describes a languages for State-Machine definitions. A state machine consists of certain commands, events, states and transitions.
On the graphical view, the states are presented by nodes, the transitions by edges. The commands are attached to the corresponding nodes, while the events are described on the corresponding edge label.
All these examples are available on the corresponding GitHub repository. For further information, watch the recorded GEF DOT session on the EclipseCon Europe 2018, study the GEF DOT User Guide and take a look at the Getting started with GEF 5.0 Online Tutorial.