Java DSLs with Xtext
-
Upload
jan-koehnlein -
Category
Technology
-
view
553 -
download
4
description
Transcript of Java DSLs with Xtext
![Page 1: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/1.jpg)
Java DSLs with Xtext
Jan Koehnlein
Mittwoch, 27. März 13
![Page 2: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/2.jpg)
Mittwoch, 27. März 13
![Page 3: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/3.jpg)
Mittwoch, 27. März 13
![Page 4: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/4.jpg)
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
![Page 5: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/5.jpg)
@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
![Page 6: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/6.jpg)
Domain-Specific Languages
Mittwoch, 27. März 13
![Page 7: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/7.jpg)
@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; }}
entity Customer { name: String address: Address purchase: Item*}
CodeGeneration
DSL Java
Mittwoch, 27. März 13
![Page 8: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/8.jpg)
Methods Logic
ArithmeticsBehavior ?
Mittwoch, 27. März 13
![Page 9: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/9.jpg)
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
![Page 10: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/10.jpg)
Typesystem
Compiler / Interpreter
Complex Syntax
Expressions
Mittwoch, 27. März 13
![Page 11: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/11.jpg)
Integration Patterns
Generatedcode
Manually writtencode
Mittwoch, 27. März 13
![Page 12: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/12.jpg)
Reusable powerful expression library language
Java‘s Typesystem
Compile to Java Code
Access to Java-elements
Mittwoch, 27. März 13
![Page 13: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/13.jpg)
DSLs for
JavaMittwoch, 27. März 13
![Page 14: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/14.jpg)
Type System
Interpreter /
Debugger
Grammar (Parser, Lexer)Linker
Advanced Editor
Eclipse IntegrationJvm
Model
MyLanguage
grammar inheritance
JvmModelInferrer
Mittwoch, 27. März 13
![Page 15: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/15.jpg)
Model Inference
entity Customer { name: String address: Address purchasedItems: Item* double sales() { purchasedItems .map[price] .reduce[a,b|a+b] }}
Class Customer
parameter name
returnType String
Field name
Method getName
Method setName
type String
Mittwoch, 27. März 13
![Page 16: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/16.jpg)
Model Inference
entity Customer { name: String address: Address purchasedItems: Item* double sales() { purchasedItems .map[price] .reduce[a,b|a+b] }}
returnType double
Method sales
body Expression
Mittwoch, 27. März 13
![Page 17: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/17.jpg)
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
![Page 18: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/18.jpg)
The 7 LanguagesScripting Language
Http Routing Language
Templates Language
DSL for Guice
Build Language
Tortoise
DSL for MongoDB
Mittwoch, 27. März 13
![Page 19: Java DSLs with Xtext](https://reader034.fdocuments.in/reader034/viewer/2022052310/555e2371d8b42a6a4c8b4d3d/html5/thumbnails/19.jpg)
www.eclipse.org/Xtext/7languages.html
Find more at
Mittwoch, 27. März 13