SlideShare a Scribd company logo
Java DSLs
                        with Xtext
                           Jan Koehnlein




Mittwoch, 27. März 13
Mittwoch, 27. März 13
Mittwoch, 27. März 13
public class Customer implements Serializable {

                        	   private String name;
                        	   private Address address;
                        	   private List<Item> purchase;

                        	   public String getName() {
                        	   	   return name;
                        	   }
                        	   public void setName(String name) {
                        	   	   this.name = name;
                        	   }

                        	   public Address getAddress() {
                        	   	   return address;
                        	   }
                        	   public void setAddress(Address address) {
                        	   	   this.address = address;
                        	   }
                        	
                        	   public List<Item> getPurchase() {
                        	   	   return purchase;
                        	   }
                        	   public void setPurchase(List<Item> items) {
                        	   	   this.purchase = purchase;
                        	   }
                        }




Mittwoch, 27. März 13
@Entity
                        public class Customer implements Serializable {
                        	   @Id
                        	   private String name;
                        	   private Address address;
                        	   private List<Item> purchase;

                        	   public String getName() {
                        	   	   return name;
                        	   }
                        	   public void setName(String name) {
                        	   	   this.name = name;
                        	   }
                        	   @Column(name="ADDR", nullable=false)
                        	   public Address getAddress()
                        	   	   return address;
                        	   }
                        	   public void setAddress(Address address) {
                        	   	   this.address = address;
                        	   }
                        	   @ManyToMany
                        	   public List<Item> getPurchase() {
                        	   	   return purchase;
                        	   }
                        	   public void setPurchase(List<Item> items) {
                        	   	   this.purchase = purchase;
                        	   }
                        }




Mittwoch, 27. März 13
Domain-Specific Languages




Mittwoch, 27. März 13
DSL                        Java
            entity Customer {
                                 @Entity
              name: String       public class Customer implements Serializable {
                                 	   @Id
              address: Address   	   private String name;
              purchase: Item*    	
                                 	
                                     private Address address;
                                     private List<Item> purchase;
            }
                                 	   public String getName() {
                                 	   	   return name;
                                 	   }
                                 	   public void setName(String name) {
                                 	   	   this.name = name;
                                 	   }
                                 	   @Column(name="ADDR", nullable=false)


            Code                 	
                                 	
                                 	
                                 	
                                     public Address getAddress() {
                                     	
                                     }
                                         return address;

                                     public void setAddress(Address address) {



          Generation
                                 	   	   this.address = address;
                                 	   }
                                 	   @ManyToMany
                                 	   public List<Item> getPurchase() {
                                 	   	   return purchase;
                                 	   }
                                 	   public void setPurchase(List<Item> items) {
                                 	   	   this.purchase = purchase;
                                 	   }
                                 }



Mittwoch, 27. März 13
?
                         Methods
                           Logic
                        Arithmetics
                         Behavior



Mittwoch, 27. März 13
entity Customer {
                          name: String
                          address: Address
                          purchase: Item*
                          double sales() {
                            double result = 0.0;
                            for(Item item: purchase)
                              result += item.getPrice();
                            return result;
                          }
                        }




Mittwoch, 27. März 13
Expressions



                          Complex Syntax
                             Typesystem
                        Compiler / Interpreter

Mittwoch, 27. März 13
Integration Patterns
                         Manually
                         written
                           code




                            Generated
                              code



Mittwoch, 27. März 13
Reusable powerful expression
                                    library language


                        Java‘s Typesystem


                            Access to Java-elements

                                       Compile to Java Code


Mittwoch, 27. März 13
DSLs
                         for
                        Java
Mittwoch, 27. März 13
grammar inheritance

                               Grammar (Parser, Lexer)
                                           Linker
                                           Type System




                                JvmModel
              MyLanguage                   Interpreter /
                                           Advanced Editor
                                           Eclipse Integration
                                           Debugger


                                      JvmModelInferrer



Mittwoch, 27. März 13
Model Inference
                                             Class Customer
                   entity Customer {
                     name: String               Field name
                     address: Address
                     purchasedItems: Item*      Method getName
                     double sales() {
                       purchasedItems
                                                   returnType String
                         .map[price]
                         .reduce[a,b|a+b]
                     }                         Method setName
                   }
                                                   parameter name

                                                       type String


Mittwoch, 27. März 13
Model Inference
                   entity Customer {
                     name: String
                     address: Address
                     purchasedItems: Item*
                     double sales() {        Method sales
                       purchasedItems
                         .map[price]           returnType double
                         .reduce[a,b|a+b]
                     }
                                                body Expression
                   }




Mittwoch, 27. März 13
class ScriptingJvmModelInferrer extends AbstractModelInferrer {
                        	
                           	
                           @Inject extension JvmTypesBuilder

                             	
                             def dispatch void infer(Script script,
                                    IJvmDeclaredTypeAcceptor acceptor,
                                    boolean isPreIndexingPhase) {
                             	
                             	 acceptor.accept(script.toClass('MyClass'))
                                    .initializeLater [
                             	
                             	 	 // the class gets one main method
                             	
                             	 	 members += script.toMethod(
                                           'main',
                                           script.newTypeRef(Void::TYPE)) [
                             	
                             	 	 	 parameters += script.toParameter("args",
                                           script.newTypeRef(typeof(String))
                                                  .addArrayTypeDimension)
                             	
                             	 	 	 static = true
                             	
                             	 	 	 varArgs = true
                             	
                             	 	 	 // Associate the script as the body of the main method
                             	
                             	 	 	 body = script
                             	
                             	 	 ]	
                             	
                             	 ]
                            	}
                        }




Mittwoch, 27. März 13
The 7 Languages
                            Scripting Language
                           DSL for MongoDB
                          Http Routing Language
                           Templates Language
                             DSL for Guice
                             Build Language
                                Tortoise

Mittwoch, 27. März 13
Find more at
                        www.eclipse.org/Xtext/7languages.html




Mittwoch, 27. März 13

More Related Content

PPT
Spring data
명철 강
 
PDF
Partial ordering in soft set context
Alexander Decker
 
PDF
Groovy
congcong wang
 
PDF
Nl2422102215
IJERA Editor
 
PPT
Dic hash
ppreeta
 
PDF
Java script objects 1
H K
 
PPTX
Chap1 array
raksharao
 
Spring data
명철 강
 
Partial ordering in soft set context
Alexander Decker
 
Nl2422102215
IJERA Editor
 
Dic hash
ppreeta
 
Java script objects 1
H K
 
Chap1 array
raksharao
 

Viewers also liked (20)

PPTX
Building Your Own DSL with Xtext
GlobalLogic Ukraine
 
PDF
Executable specifications for xtext
meysholdt
 
KEY
Xtext Best Practices
Sebastian Zarnekow
 
PDF
Using Xcore with Xtext
Holger Schill
 
PDF
Xtext, diagrams and ux
Dr. Jan Köhnlein
 
PDF
Language Engineering With Xtext
Sven Efftinge
 
PDF
Scoping
Dr. Jan Köhnlein
 
PDF
Scoping Tips and Tricks
Sebastian Zarnekow
 
KEY
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Dr. Jan Köhnlein
 
PDF
Extending the Xbase Typesystem
Sebastian Zarnekow
 
PDF
Future of Xtext
Sven Efftinge
 
PDF
Introduction to Xbase
Holger Schill
 
PDF
Graphical Views For Xtext
Dr. Jan Köhnlein
 
PPTX
Enhancing Xtext for General Purpose Languages
University of York
 
PDF
Eclipse DemoCamp in Paris: Language Development with Xtext
Sebastian Zarnekow
 
PDF
From Stairway to Heaven onto the Highway to Hell with Xtext
Karsten Thoms
 
PDF
Parsing Expression With Xtext
Sven Efftinge
 
KEY
Java Performance MythBusters
Sebastian Zarnekow
 
PDF
Xtext's new Formatter API
meysholdt
 
PDF
What's Cooking in Xtext 2.0
Dr. Jan Köhnlein
 
Building Your Own DSL with Xtext
GlobalLogic Ukraine
 
Executable specifications for xtext
meysholdt
 
Xtext Best Practices
Sebastian Zarnekow
 
Using Xcore with Xtext
Holger Schill
 
Xtext, diagrams and ux
Dr. Jan Köhnlein
 
Language Engineering With Xtext
Sven Efftinge
 
Scoping Tips and Tricks
Sebastian Zarnekow
 
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Dr. Jan Köhnlein
 
Extending the Xbase Typesystem
Sebastian Zarnekow
 
Future of Xtext
Sven Efftinge
 
Introduction to Xbase
Holger Schill
 
Graphical Views For Xtext
Dr. Jan Köhnlein
 
Enhancing Xtext for General Purpose Languages
University of York
 
Eclipse DemoCamp in Paris: Language Development with Xtext
Sebastian Zarnekow
 
From Stairway to Heaven onto the Highway to Hell with Xtext
Karsten Thoms
 
Parsing Expression With Xtext
Sven Efftinge
 
Java Performance MythBusters
Sebastian Zarnekow
 
Xtext's new Formatter API
meysholdt
 
What's Cooking in Xtext 2.0
Dr. Jan Köhnlein
 
Ad

Similar to Java DSLs with Xtext (6)

PDF
Pitfalls In Aspect Mining
kim.mens
 
PPT
Introduction à Dart
SOAT
 
PDF
High performance JPA with Oracle Coherence
Markus Eisele
 
PPTX
Implementing CQRS and Event Sourcing with RavenDB
Oren Eini
 
PDF
Combatendo code smells em Java
Emmanuel Neri
 
PDF
3. Объекты, классы и пакеты в Java
DEVTYPE
 
Pitfalls In Aspect Mining
kim.mens
 
Introduction à Dart
SOAT
 
High performance JPA with Oracle Coherence
Markus Eisele
 
Implementing CQRS and Event Sourcing with RavenDB
Oren Eini
 
Combatendo code smells em Java
Emmanuel Neri
 
3. Объекты, классы и пакеты в Java
DEVTYPE
 
Ad

More from Dr. Jan Köhnlein (20)

PDF
The Eclipse Layout Kernel sirius con 2017
Dr. Jan Köhnlein
 
PDF
A New Approach Towards Web-based IDEs
Dr. Jan Köhnlein
 
PDF
Responsiveness
Dr. Jan Köhnlein
 
PDF
Getting rid of backtracking
Dr. Jan Köhnlein
 
PDF
Graphical Views For Xtext With FXDiagram
Dr. Jan Köhnlein
 
PDF
XRobots
Dr. Jan Köhnlein
 
PDF
Diagrams, Xtext and UX
Dr. Jan Köhnlein
 
PDF
Diagram Editors - The FXed Generation
Dr. Jan Köhnlein
 
PDF
Code Generation With Xtend
Dr. Jan Köhnlein
 
PDF
The Xtext Grammar Language
Dr. Jan Köhnlein
 
PDF
Eclipse Diagram Editors - An Endangered Species
Dr. Jan Köhnlein
 
PDF
DSLs for Java Developers
Dr. Jan Köhnlein
 
PDF
A fresh look at graphical editing
Dr. Jan Köhnlein
 
PDF
A fresh look at graphical editing
Dr. Jan Köhnlein
 
KEY
A fresh look at graphical editing
Dr. Jan Köhnlein
 
PDF
Android tutorial - Xtext slides
Dr. Jan Köhnlein
 
KEY
Eclipse meets e4
Dr. Jan Köhnlein
 
KEY
Combining Text and Graphics in Eclipse-based Modeling Tools
Dr. Jan Köhnlein
 
KEY
Combining Graphical and Textual
Dr. Jan Köhnlein
 
KEY
Domain Specific Languages With Eclipse Modeling
Dr. Jan Köhnlein
 
The Eclipse Layout Kernel sirius con 2017
Dr. Jan Köhnlein
 
A New Approach Towards Web-based IDEs
Dr. Jan Köhnlein
 
Responsiveness
Dr. Jan Köhnlein
 
Getting rid of backtracking
Dr. Jan Köhnlein
 
Graphical Views For Xtext With FXDiagram
Dr. Jan Köhnlein
 
Diagrams, Xtext and UX
Dr. Jan Köhnlein
 
Diagram Editors - The FXed Generation
Dr. Jan Köhnlein
 
Code Generation With Xtend
Dr. Jan Köhnlein
 
The Xtext Grammar Language
Dr. Jan Köhnlein
 
Eclipse Diagram Editors - An Endangered Species
Dr. Jan Köhnlein
 
DSLs for Java Developers
Dr. Jan Köhnlein
 
A fresh look at graphical editing
Dr. Jan Köhnlein
 
A fresh look at graphical editing
Dr. Jan Köhnlein
 
A fresh look at graphical editing
Dr. Jan Köhnlein
 
Android tutorial - Xtext slides
Dr. Jan Köhnlein
 
Eclipse meets e4
Dr. Jan Köhnlein
 
Combining Text and Graphics in Eclipse-based Modeling Tools
Dr. Jan Köhnlein
 
Combining Graphical and Textual
Dr. Jan Köhnlein
 
Domain Specific Languages With Eclipse Modeling
Dr. Jan Köhnlein
 

Recently uploaded (20)

PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
The Future of Artificial Intelligence (AI)
Mukul
 

Java DSLs with Xtext

  • 1. Java DSLs with Xtext Jan Koehnlein Mittwoch, 27. März 13
  • 4. public class Customer implements Serializable { private String name; private Address address; private List<Item> purchase; public String getName() { return name; } public void setName(String name) { this.name = name; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } public List<Item> getPurchase() { return purchase; } public void setPurchase(List<Item> items) { this.purchase = purchase; } } Mittwoch, 27. März 13
  • 5. @Entity public class Customer implements Serializable { @Id private String name; private Address address; private List<Item> purchase; public String getName() { return name; } public void setName(String name) { this.name = name; } @Column(name="ADDR", nullable=false) public Address getAddress() return address; } public void setAddress(Address address) { this.address = address; } @ManyToMany public List<Item> getPurchase() { return purchase; } public void setPurchase(List<Item> items) { this.purchase = purchase; } } Mittwoch, 27. März 13
  • 7. DSL Java entity Customer { @Entity name: String public class Customer implements Serializable { @Id address: Address private String name; purchase: Item* private Address address; private List<Item> purchase; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Column(name="ADDR", nullable=false) Code public Address getAddress() { } return address; public void setAddress(Address address) { Generation this.address = address; } @ManyToMany public List<Item> getPurchase() { return purchase; } public void setPurchase(List<Item> items) { this.purchase = purchase; } } Mittwoch, 27. März 13
  • 8. ? Methods Logic Arithmetics Behavior Mittwoch, 27. März 13
  • 9. entity Customer { name: String address: Address purchase: Item* double sales() { double result = 0.0; for(Item item: purchase) result += item.getPrice(); return result; } } Mittwoch, 27. März 13
  • 10. Expressions Complex Syntax Typesystem Compiler / Interpreter Mittwoch, 27. März 13
  • 11. Integration Patterns Manually written code Generated code Mittwoch, 27. März 13
  • 12. Reusable powerful expression library language Java‘s Typesystem Access to Java-elements Compile to Java Code Mittwoch, 27. März 13
  • 13. DSLs for Java Mittwoch, 27. März 13
  • 14. grammar inheritance Grammar (Parser, Lexer) Linker Type System JvmModel MyLanguage Interpreter / Advanced Editor Eclipse Integration Debugger JvmModelInferrer Mittwoch, 27. März 13
  • 15. Model Inference Class Customer entity Customer { name: String Field name address: Address purchasedItems: Item* Method getName double sales() { purchasedItems returnType String .map[price] .reduce[a,b|a+b] } Method setName } parameter name type String Mittwoch, 27. März 13
  • 16. Model Inference entity Customer { name: String address: Address purchasedItems: Item* double sales() { Method sales purchasedItems .map[price] returnType double .reduce[a,b|a+b] } body Expression } Mittwoch, 27. März 13
  • 17. class ScriptingJvmModelInferrer extends AbstractModelInferrer { @Inject extension JvmTypesBuilder def dispatch void infer(Script script, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) { acceptor.accept(script.toClass('MyClass')) .initializeLater [ // the class gets one main method members += script.toMethod( 'main', script.newTypeRef(Void::TYPE)) [ parameters += script.toParameter("args", script.newTypeRef(typeof(String)) .addArrayTypeDimension) static = true varArgs = true // Associate the script as the body of the main method body = script ] ] } } Mittwoch, 27. März 13
  • 18. The 7 Languages Scripting Language DSL for MongoDB Http Routing Language Templates Language DSL for Guice Build Language Tortoise Mittwoch, 27. März 13
  • 19. Find more at www.eclipse.org/Xtext/7languages.html Mittwoch, 27. März 13