Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Pragmatic DSL Design with Xtext, Xbase and Xtend 2

on

  • 15,214 views

Tutorial at EclipseCon 2011 (Santa Clara)

Tutorial at EclipseCon 2011 (Santa Clara)
Sven Efftinge, Jan Koehnlein, Sebastian Zarnekow

Statistics

Views

Total Views
15,214
Views on SlideShare
9,374
Embed Views
5,840

Actions

Likes
15
Downloads
363
Comments
0

45 Embeds 5,840

http://www.eclipsecon.org 2774
http://koehnlein.blogspot.com 1175
http://java.dzone.com 896
http://eclipsecon.org 711
http://koehnlein.blogspot.de 104
https://www.eclipsecon.org 23
http://koehnlein.blogspot.in 16
http://koehnlein.blogspot.com.es 12
http://koehnlein.blogspot.fr 11
http://koehnlein.blogspot.co.at 9
http://translate.googleusercontent.com 8
url_unknown 8
http://koehnlein.blogspot.co.uk 7
http://koehnlein.blogspot.ch 7
http://koehnlein.blogspot.hu 7
http://webcache.googleusercontent.com 7
http://koehnlein.blogspot.ca 6
http://koehnlein.blogspot.it 5
http://www.geekgrade.com 5
http://koehnlein.blogspot.nl 5
http://eclipsesummit.org 4
http://koehnlein.blogspot.com.br 3
http://koehnlein.blogspot.be 3
http://koehnlein.blogspot.jp 3
http://koehnlein.blogspot.cz 3
http://www.newsblur.com 3
http://www.javaoracleblog.com 3
http://koehnlein.blogspot.kr 2
http://koehnlein.blogspot.ru 2
http://www.renren.it 2
http://myzomyia28.putangas.com 2
http://xss.yandex.net 1
http://koehnlein.blogspot.com.tr 1
http://koehnlein.blogspot.co.nz 1
http://myzomyia28.rssing.com 1
http://xss.yandex.ne 1
http://xss.yandex 1
http://koehnlein.blogspot.com.au 1
http://koehnlein.blogspot.dk 1
http://static.slidesharecdn.com 1
http://www.slideshare.net 1
http://blogs.itemis.de 1
http://koehnlein.blogspot.no 1
http://cache.baidu.com 1
http://koehnlein.blogspot.se 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Pragmatic DSL Design with Xtext, Xbase and Xtend 2 Presentation Transcript

  • 1. Pragmatic DSL Design withSven Efftinge (itemis) / Sebastian Zarnekow (itemis) / Jan Köhnlein (itemis)
  • 2. The plan for today :
  • 3. The plan for today :1. Xtext 2.0 What is Xtext and what’s new in 2.0? Hands-On : Develop a DSL.
  • 4. The plan for today :1. Xtext 2.0 What is Xtext and what’s new in 2.0? Hands-On : Develop a DSL.2. Xbase What’s that and why should I care? Hands-On : Play with it and integrate it in a DSL.
  • 5. The plan for today :1. Xtext 2.0 What is Xtext and what’s new in 2.0? Hands-On : Develop a DSL.2. Xbase What’s that and why should I care? Hands-On : Play with it and integrate it in a DSL.3. Xtend Yet another language? Are you serious? Hands-On :Write a codegenerator with Xtend.
  • 6. What is ?
  • 7. Eclipse Project
  • 8. IDE Framework
  • 9. Language Framework
  • 10. (Domain-Specific)Language Framework
  • 11. UsersUsers
  • 12. Eclipse IDE Framework (JFace Text, etc.)
  • 13. Java Development Tools (JDT)Eclipse IDE Framework (JFace Text, etc.)
  • 14. Java Development Tools (JDT)Eclipse IDE Framework (JFace Text, etc.)
  • 15. Java Development Tools (JDT)Eclipse IDE Framework (JFace Text, etc.) Eclipse Modeling Framework (EMF)
  • 16. Java Development Tools (JDT) Antlr Parser GeneratorEclipse IDE Framework (JFace Text, etc.) Eclipse Modeling Framework (EMF)
  • 17. is Highly Adaptable
  • 18. Advanced Language-Specific Editing Features by Default
  • 19. Advanced Language-Specific Editing Features by Default Syntax Coloring
  • 20. Advanced Language-Specific Editing Features by Default Syntax Coloring Wizards
  • 21. Advanced Language-Specific Editing Features by DefaultContent Assist Syntax Coloring Wizards
  • 22. Advanced Language-Specific Editing Features by DefaultContent Assist Syntax Coloring Code Folding Wizards
  • 23. Advanced Language-Specific Editing Features by DefaultContent Assist Find References Syntax Coloring Code Folding Wizards
  • 24. Advanced Language-Specific Editing Features by Default Global IndexingContent Assist Find References Syntax Coloring Code Folding Wizards
  • 25. Advanced Language-Specific Editing Features by Default Go To Declaration Global IndexingContent Assist Find References Syntax Coloring Code Folding Wizards
  • 26. Advanced Language-Specific Editing Features by Default Go To Declaration Global IndexingContent Assist Find References Syntax Coloring Code Folding Wizards Bracket Matching
  • 27. Advanced Language-Specific Editing Features by Default Go To Declaration Global IndexingContent Assist Find References Syntax Coloring Auto Editing Code Folding Wizards Bracket Matching
  • 28. Advanced Language-Specific Editing Features by Default Go To Declaration Global IndexingContent Assist Find References Syntax ColoringIncremental Builders Auto Editing Code Folding Wizards Bracket Matching
  • 29. Advanced Language-Specific Editing Features by Default Go To Declaration Global IndexingContent Assist Outline View Find References Syntax ColoringIncremental Builders Auto Editing Code Folding Wizards Bracket Matching
  • 30. Advanced Language-Specific Editing Features by Default Go To Declaration Global IndexingContent Assist Outline View Find ReferencesIncremental Builders Validation Syntax Coloring Auto Editing Code Folding Wizards Bracket Matching
  • 31. Advanced Language-Specific Editing Features by Default Go To Declaration Template Proposals Global IndexingContent Assist Outline View Find ReferencesIncremental Builders Validation Syntax Coloring Auto Editing Code Folding Wizards Bracket Matching
  • 32. Advanced Language-Specific Editing Features by Default Go To Declaration Template Proposals Global IndexingContent Assist Outline View Quick Fixes Find ReferencesIncremental Builders Validation Syntax Coloring Auto Editing Code Folding Wizards Bracket Matching
  • 33. Advanced Language-Specific Editing Features by Default Refactoring Go To Declaration Template Proposals Global IndexingContent Assist Outline View Quick Fixes Find ReferencesIncremental Builders Validation Syntax Coloring Auto Editing Code Folding Wizards Bracket Matching
  • 34. Advanced Language-Specific Editing Features by Default Refactoring Go To Declaration Template Proposals Global IndexingContent Assist Outline View Quick Fixes Find ReferencesIncremental Builders Validation Syntax Coloring Rich Hovers Auto Editing Code Folding Wizards Bracket Matching
  • 35. ... but there is a problem with external DSLs
  • 36. What aboutExpressions?
  • 37. Expressions are complicated !
  • 38. Protected Regions
  • 39. Protected Regions• generated and manually written code mixed up
  • 40. Protected Regions• generated and manually written code mixed up• manual deletion of artifacts
  • 41. Protected Regions• generated and manually written code mixed up• manual deletion of artifacts• platform dependent information
  • 42. Protected Regions• generated and manually written code mixed up• manual deletion of artifacts• platform dependent information• information is spreaded!
  • 43. Generation Gap Pattern
  • 44. Generation Gap Pattern technically required type hierarchies
  • 45. Generation Gap Pattern technically required type hierarchies additional complexity
  • 46. Generation Gap Pattern technically required type hierarchies additional complexity platform dependent information
  • 47. Generation Gap Pattern technically required type hierarchies additional complexity platform dependent information information spreaded!
  • 48. Black boxtarget language literals
  • 49. Black boxtarget language literals• bound to target platform
  • 50. Black boxtarget language literals• bound to target platform • no option for MDA friends
  • 51. Black boxtarget language literals• bound to target platform • no option for MDA friends• no tooling!
  • 52. Black boxtarget language literals• bound to target platform • no option for MDA friends• no tooling!• long turnarounds!
  • 53. base
  • 54. baseModern Expression Language
  • 55. baseModern Expression LanguageJVM-Integration
  • 56. baseModern Expression LanguageJVM-IntegrationStatically Typed
  • 57. baseModern Expression LanguageJVM-IntegrationStatically TypedHighly Reusable
  • 58. Your Language o.e.xtext.common.TerminalsEMF
  • 59. Your Language common.Types o.e.xtext.common.TerminalsJDT JVM EMF
  • 60. Your Language Xbase Ecore Xbase Grammar common.Types o.e.xtext.common.TerminalsJDT JVM EMF
  • 61. @Overrideprotected IScope createLocalVarScope(~) { if (context instanceof Operation) { IScope actualScope = super.createLocalVarScope(~); Operation operation = (Operation) context; return createScope(operation.getParams(), actualScope); } return super.createLocalVarScope(~);}
  • 62. Using Xbase
  • 63. Using XbaseMixin the Grammar
  • 64. Using XbaseMixin the GrammarJVM Model Inference
  • 65. Using XbaseMixin the GrammarJVM Model InferenceScoping
  • 66. Using XbaseMixin the GrammarJVM Model InferenceScopingType System
  • 67. Using XbaseMixin the GrammarJVM Model InferenceScopingType SystemCompiler / Interpreter
  • 68. A DSL for Generating Code
  • 69. Model Code Code Generator
  • 70. Model Code package base; public class Address { private String street; public String getStreet() { return street; } public void setStreet(String street) { this.street = street; } private String city; Code public String getCity() { return city; Generator } public void setCity(String city) { this.city = city; } private String state; public String getState() { return state; } public void setState(String state) { this.state = state; } private String postalCode; public String getPostalCode() { return postalCode; } public void setPostalCode(String postalCode) { this.postalCode = postalCode; } }
  • 71. BUT I CANDO THAT IN
  • 72. package example.codegen;import org.eclipse.xtext.common.types.JvmFormalParameter;import org.eclipse.xtext.common.types.JvmTypeReference;import org.eclipse.xtext.example.domainmodel.domainmodel.Entity;import org.eclipse.xtext.example.domainmodel.domainmodel.Feature;import org.eclipse.xtext.example.domainmodel.domainmodel.Operation;import org.eclipse.xtext.example.domainmodel.domainmodel.Property;public class JavaGenerator { public String compile(Entity e) { StringBuilder b = new StringBuilder(); b.append("package " + packageName(e) + "n"); b.append("n"); b.append("/**n"); b.append(" * Automatically generated. Direct modification is futile.n"); b.append(" */n"); b.append("public class ").append(e.getName()); if(e.getSuperType() != null) { b.append(" extends ").append(compile(e.getSuperType())); } b.append(" {n"); for(Feature f: e.getFeatures()) { if(f instanceof Property) feature((Property)f); else if(f instanceof Operation) feature((Operation)f); } b.append("}n"); return b.toString();
  • 73. package example.codegen;import org.eclipse.xtext.common.types.JvmFormalParameter;import org.eclipse.xtext.common.types.JvmTypeReference;import org.eclipse.xtext.example.domainmodel.domainmodel.Entity;import org.eclipse.xtext.example.domainmodel.domainmodel.Feature;import org.eclipse.xtext.example.domainmodel.domainmodel.Operation;import org.eclipse.xtext.example.domainmodel.domainmodel.Property;public class JavaGenerator { No Multiline public String compile(Entity e) { StringBuilder b = new StringBuilder(); String Literals b.append("package " + packageName(e) + "n"); b.append("n"); b.append("/**n"); b.append(" * Automatically generated. Direct modification is futile.n"); b.append(" */n"); b.append("public class ").append(e.getName()); if(e.getSuperType() != null) { b.append(" extends ").append(compile(e.getSuperType())); } b.append(" {n"); for(Feature f: e.getFeatures()) { if(f instanceof Property) feature((Property)f); else if(f instanceof Operation) feature((Operation)f); } b.append("}n"); return b.toString();
  • 74. public String compile(Entity e) { StringBuilder b = new StringBuilder(); b.append("package " + packageName(e) + "n"); b.append("n"); b.append("/**n"); b.append(" * Automatically generated. Direct modification is futile.n"); b.append(" */n"); b.append("public class ").append(e.getName()); if(e.getSuperType() != null) { b.append(" extends ").append(compile(e.getSuperType())); } b.append(" {n"); for(Feature f: e.getFeatures()) { if(f instanceof Property) feature((Property)f); Instanceof else if(f instanceof Operation) feature((Operation)f); Cascades } b.append("}n"); return b.toString(); } public String feature(Property property) { StringBuilder b = new StringBuilder(); String type = compile(property.getType()); String name = property.getName(); b.append("// property ").append(name).append("n"); b.append("private ").append(type).append(" ").append(name).append("n"); b.append("n"); b.append("public ").append(type).append("get").append(name).append("() {n"); b.append(" return ").append(name).append(";n");
  • 75. } b.append("}n"); return b.toString(); } public String feature(Property property) { StringBuilder b = new StringBuilder(); String type = compile(property.getType()); String name = property.getName(); b.append("// property ").append(name).append("n"); b.append("private ").append(type).append(" ").append(name).append("n"); b.append("n"); b.append("public ").append(type).append("get").append(name).append("() {n"); b.append(" return ").append(name).append(";n"); b.append("}n"); b.append("n"); b.append("public ").append("set").append(name) .append("(").append(type).append(" ").append(name).append("){n"); b.append(" this.").append(name).append(" = ").append(name).append(";n"); b.append("}n"); b.append("n"); return b.toString(); } Noisy String public String feature(Operation operation) { StringBuilder b = new StringBuilder(); Concatenation String name = operation.getName(); b.append("// operation ").append(name).append("n"); b.append(compile(operation.getType())).append(" ").append(name).append("("); boolean isFirst = true; for(JvmFormalParameter p: operation.getParams()) {
  • 76. Statically Typed
  • 77. Statically Xbase Typed Expressions
  • 78. « RICH STRINGS »
  • 79. POLYMORPHIC dispatch
  • 80. COMPILES TO
  • 81. DEPENDENCY@InjectION
  • 82. TOOLING
  • 83. Indigo - June 22nd