java dsls with xtext
Post on 22-May-2015
552 Views
Preview:
DESCRIPTION
TRANSCRIPT
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
@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
Methods Logic
ArithmeticsBehavior ?
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
Typesystem
Compiler / Interpreter
Complex Syntax
Expressions
Mittwoch, 27. März 13
Integration Patterns
Generatedcode
Manually writtencode
Mittwoch, 27. März 13
Reusable powerful expression library language
Java‘s Typesystem
Compile to Java Code
Access to Java-elements
Mittwoch, 27. März 13
DSLs for
JavaMittwoch, 27. März 13
Type System
Interpreter /
Debugger
Grammar (Parser, Lexer)Linker
Advanced Editor
Eclipse IntegrationJvm
Model
MyLanguage
grammar inheritance
JvmModelInferrer
Mittwoch, 27. März 13
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
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
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 LanguagesScripting Language
Http Routing Language
Templates Language
DSL for Guice
Build Language
Tortoise
DSL for MongoDB
Mittwoch, 27. März 13
www.eclipse.org/Xtext/7languages.html
Find more at
Mittwoch, 27. März 13
top related