installation
play

Installation Grab a USB key Install Eclipse Save the zip files to - PowerPoint PPT Presentation

Installation Grab a USB key Install Eclipse Save the zip files to your disk host_workspace.zip runtime_workspace.zip Montag, 25. Mrz 13 for Beginners Moritz Eysholdt, Jan Khnlein, Holger Schill Montag, 25. Mrz 13


  1. Installation ๏ Grab a USB key ๏ Install Eclipse ๏ Save the zip files to your disk ๏ host_workspace.zip ๏ runtime_workspace.zip Montag, 25. März 13

  2. for Beginners Moritz Eysholdt, Jan Köhnlein, Holger Schill Montag, 25. März 13

  3. Outline ๏ Example Application ๏ Build your DSL with Xtext ๏ Generate Code with Xtend ๏ Validate Models ๏ Introduce Cross-references ๏ Outlook Montag, 25. März 13

  4. Outline ๏ Example Application ๏ Build your DSL with Xtext ๏ Generate Code with Xtend ๏ Validate Models ๏ Introduce Cross-references ๏ Outlook Montag, 25. März 13

  5. Demo Montag, 25. März 13

  6. Example: Surveys ๏ A web-based app for surveys ๏ online answering ๏ multiple pages ๏ different types of questions ๏ online evaluation Montag, 25. März 13

  7. Architecture ๏ HTML forms ๏ Twitter Bootstrap CSS / JavaScript ๏ Jetty server ๏ Simple pageflow engine ๏ In memory persistence Montag, 25. März 13

  8. API View Montag, 25. März 13

  9. Challenges ๏ A heterogeneous platform ๏ Java, HTML, maybe a Database ๏ Difficult to extend ๏ more questions, multiple surveys ๏ other front ends ๏ Hard to maintain Montag, 25. März 13

  10. The Domain ๏ The application is about Surveys . ๏ A Survey consists of Pages . ๏ A Page holds a couple of Questions . ๏ Questions can be answered with FreeText or predefined Choices . ๏ Some Choices are exclusive . ๏ A page defines its FollowUp pages ๏ FollowUps may depend on on given answers. Montag, 25. März 13

  11. DSL Approach ๏ Create a domain-specific language ๏ Describes the data formally ๏ Generate code from its models Montag, 25. März 13

  12. survey tutorial "EclipseCon 2013 Tutorial Survey" Survey page Start ( Page text name 'Your name' TextQuestion single choice like "Do you like the tutorial?" ( ChoiceQuestion (single) yes "Yes" Choice no "No" Choice ) FollowUp if like=yes -> Like FollowUp if like=no -> Dislike ) Page page Like ( ChoiceQuestion choice particular "What do you like in particular?" ( Choice xtext 'Xtext is awesome' Choice excercises 'The funny exercises' tutors 'The handsome tutors' Choice ) ) Page page Dislike ( choice particular "What do you hate in particular?" ( ChoiceQuestion xtext 'Xtext sucks' Choice excercises 'The boring exercises' Choice tutors 'The tutors stink' Choice ) ) Montag, 25. März 13

  13. Advantages ๏ Addresses heterogeneity ๏ Easy design of surveys ๏ Easy to add new front ends ๏ Separation of roles during development ๏ Speedup for development ๏ Improved maintainability Montag, 25. März 13

  14. Outline ๏ Example Application ๏ Build your DSL with Xtext ๏ Generate Code with Xtend ๏ Validate Models ๏ Introduce Cross-references ๏ Outlook Montag, 25. März 13

  15. Reference Grammar Model Runtime Superclass Subclass Class ecore meta model LL(*) Parser editor Montag, 25. März 13

  16. Grammar Namespace grammar org.eclipse.xtext.tutorial.Grammar with org.eclipse.xtext.common.Terminals Parser Rule generate survey "http://www.eclipse.org/xtext/tutorial/Grammar" Cardinality 0..* Model: Optional Simple assignment entities+=Entity*; Boolean assignment Entity: abstract?="abstract" "entity" name=ID (tableName=ID)?"{" attributes+=Attribute+ Cardinality 1..* "}"; Multivalue assignment Attribute: StringAttribute | IntAttribute; Alternative StringAttribute: Keyword "string" value=STRING ; IntAttribute: "int" value=INT abstract entity Person tab_person { ; int 42 string "Some String" } Montag, 25. März 13

  17. Outline ๏ Example Application ๏ Build your DSL with Xtext ๏ Generate Code with Xtend ๏ Validate Models ๏ Introduce Cross-references ๏ Outlook Montag, 25. März 13

  18. Montag, 25. März 13

  19. Xtend: Templates def example(List<String> elements) ''' Usually a template consists mainly of text spanning multiple lines. If you want to evaluate an expression you have to write it in french quotes «7*3*2». Code assist inserts a pair of these. You can also iterate a collection with FOR «FOR element: elements» Found another element: «element» «ENDFOR» For decisions there is the IF statement «IF elements.isEmpty()» no elements. «ENDIF» ''' Montag, 25. März 13

  20. Xtend: Dispatch Methods // Xtend code def dispatch area(Rectangle r) { r.width * r.height } def dispatch area(Circle c) { c.radius * c.radius * Math::PI } // generated Java code (dispatcher) def someCalculation(Object o) { public double area(final Object c) { area(o) // polymorphic call if (c instanceof Circle) { } return _area((Circle)c); } else if (c instanceof Rectangle) { return _area((Rectangle)c); } else { throw new IllegalArgumentException(); } } Montag, 25. März 13

  21. Outline ๏ Example Application ๏ Build your DSL with Xtext ๏ Generate Code with Xtend ๏ Validate Models ๏ Introduce Cross-references ๏ Outlook Montag, 25. März 13

  22. Validator class SurveyValidator extends AbstractSurveyValidator { @Check def textMustNotBeEmpty(Question question) { if(question.getText().isEmpty()) { error("Empty question is illegal", question, QUESTION__TEXT) } } Montag, 25. März 13

  23. Outline ๏ Example Application ๏ Build your DSL with Xtext ๏ Generate Code with Xtend ๏ Validate Models ๏ Introduce Cross-references ๏ Outlook Montag, 25. März 13

  24. Cross References page Start ( single choice like "Do you like the tutorial?" ( yes "Yes" no "No" ) if like=yes -> Like ) page Like ( choice particular "What do you like in particular?" ( xtext 'Xtext is awesome' excercises 'The funny exercises' tutors 'The handsome tutors' ) ) Montag, 25. März 13

  25. Grammar Page: 'page' name=ID '(' // questions '->' next=[Page|ID] ')'; Montag, 25. März 13

  26. Scoping referable Questions (d ns (default scoping) page Start ( text name 'Your name' global scope local scope single choice like "..." ( yes "Yes" Start.name name no "No" ) Start.like like if like=yes -> Like ) Like.particular page Like ( choice particular "..." ( referable Choices xtext '...' excercises '...' custom scope tutors '...' ) ... yes no Montag, 25. März 13

  27. Outline ๏ Example Application ๏ Build your DSL with Xtext ๏ Generate Code with Xtend ๏ Validate Models ๏ Introduce Cross-references ๏ Outlook Montag, 25. März 13

  28. Outlook ๏ Enhance generator ๏ Customize IDE ๏ Outline, Formatter, Labels, ... ๏ Add more expressions Montag, 25. März 13

  29. More on Xtext/Xtend at EclipseCon 2013 ๏ DSLs for Java ๏ Xtext Best Practices ๏ Xtext in the Web (Orion Symposium) ๏ Executable Specification for Xtext (Modeling Symposium) ๏ Getting Started With Xtend ๏ Internal DSLs With Xtend ๏ Xtended JavaFX Montag, 25. März 13

  30. Thank You ... and don‘t forget the evaluation! Montag, 25. März 13

  31. for beginners Tutorial Preparations ! 2 Setting up Eclipse and your Workspace ! 2 Exercises ! 3 Exercise 0: Create a New Xtext Project ! 3 Exercise 1: Write a Grammar for an Example File ! 4 Exercise 2: Implement a Code Generator ! 6 Exercise 3: Implement a Custom Validation Rule ! 9 Exercise 4: Customize Linking and Content Assist via Scoping ! 10 1 / 10

  32. Tutorial Preparations Setting up Eclipse and your Workspace 1. Copy the Eclipse application from the provided USB thumb drive to your hard drive. We provide Eclipse Versions for Windows, OS X and Linux. Launch Eclipse and select a folder on your hard drive for your workspace. This is the folder in which the files that you work with will be stored. 2. In Eclipse, close the welcome screen (if it opens), go to the Java Perspective and choose “Import...” from the context menu. A wizard pops up, in which you select “General” -> “Existing Projects into Workspace” 3. On the next page of the wizard, select the archive file “host-workbench.zip” from the USB stick. This will create a new project called “Resources” in your workspace which contains this document, the slides and the solutions for the exercises. You may use it for inspiration in case you get stuck. 2 / 10

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend