SlideShare uma empresa Scribd logo
1 de 78
Codegeneration
    Goodies
   Moritz.Eysholdt@itemis.de



 These slides have been presented at the EclipseCon 2011 conference in Santa Clara:
 http://www.eclipsecon.org/2011/sessions/?page=sessions&id=2253

 They have been modified for slideshare.net to contain additional explanatory comments.

 The source code of the demos is available at
 http://github.com/meysholdt/codegeneration-goodies-demos
Generate Code...
 ...customize?
We can edit the generated source code!
We can edit the generated source code!
             actually, NO.
We can edit the generated source code!
                      actually, NO.




• complicated to merge generated/handwritten code
We can edit the generated source code!
                       actually, NO.




• complicated to merge generated/handwritten code
• handwritten code “gets lost” within generated code
We can edit the generated source code!
                       actually, NO.




• complicated to merge generated/handwritten code
• handwritten code “gets lost” within generated code
• requires to put generated source code under version control
We can edit the generated source code!
                       actually, NO.




• complicated to merge generated/handwritten code
• handwritten code “gets lost” within generated code
• requires to put generated source code under version control
• generated version of source code is lost once modified
JMerge
JMerge



• Unneeded files are not removed
JMerge



• Unneeded files are not removed
• easy to forget to remove @Generated
JMerge



• Unneeded files are not removed
• easy to forget to remove @Generated
• Handwritten, but orphaned code can
  easily be forgotten
JMerge



• Unneeded files are not removed
• easy to forget to remove @Generated
• Handwritten, but orphaned code can
  easily be forgotten

• Import statements are not organized
JMerge



• Unneeded files are not removed
• easy to forget to remove @Generated
• Handwritten, but orphaned code can
  easily be forgotten

• Import statements are not organized
• etc.
Solution: Generation Gap
Solution: Generation Gap



•   inheritance + Java’s @Override instead of @Generated
Solution: Generation Gap



•   inheritance + Java’s @Override instead of @Generated

•   two folders: “src”and “src-gen”
Solution: Generation Gap



•   inheritance + Java’s @Override instead of @Generated

•   two folders: “src”and “src-gen”

•   use MWE’s EcoreGenerator instead of JMerge
This is the
famous library-
example that
ships with EMF.
- interfaces
                  - impl-classes
                  - util
                  (all generated)



This is the
famous library-
example that
ships with EMF.
- interfaces
                  - impl-classes
                  - util
                  (all generated)



This is the       - Ecore Model
famous library-
example that      - Genmodel
ships with EMF.
- interfaces
                  - impl-classes
                  - util
                  (all generated)



This is the       - Ecore Model
famous library-
example that      - Genmodel
ships with EMF.
- interfaces
                  - impl-classes
                  - util
                  (all generated)



This is the        - Ecore Model
famous library-
example that       - Genmodel
ships with EMF.




                  Impl implements
                     interface
unmodified library-   library-example with
example from EMF     Generation Gap
unmodified library-   library-example with
example from EMF     Generation Gap
unmodified library-   library-example with
example from EMF     Generation Gap
unmodified library-   library-example with
example from EMF     Generation Gap
unmodified library-   library-example with
example from EMF     Generation Gap
unmodified library-   library-example with
example from EMF     Generation Gap
unmodified library-   library-example with
example from EMF     Generation Gap
Form the “Library”-EClass, EMF generates a
“Library”-Interface and a “LibraryImpl”-Class.
With the GenerationGap-Pattern, we
additionally have a “LibraryImplCustom”-Class
Form the “Library”-EClass, EMF generates a
“Library”-Interface and a “LibraryImpl”-Class.
With the GenerationGap-Pattern, we
additionally have a “LibraryImplCustom”-Class
Form the “Library”-EClass, EMF generates a
“Library”-Interface and a “LibraryImpl”-Class.
With the GenerationGap-Pattern, we
additionally have a “LibraryImplCustom”-Class
Form the “Library”-EClass, EMF generates a
“Library”-Interface and a “LibraryImpl”-Class.
With the GenerationGap-Pattern, we
additionally have a “LibraryImplCustom”-Class
generated code refers to “custom” classes

as super types


 In the code that is generated by EMF, the
 “Custom”-Classes are automatically used
 instead of the “Impl”-Classes, when
 - another “Impl” class extends them.
 - the EFactory instantiated them.
generated code refers to “custom” classes

as super types


 In the code that is generated by EMF, the
 “Custom”-Classes are automatically used
 instead of the “Impl”-Classes, when
 - another “Impl” class extends them.
 - the EFactory instantiated them.




                                             in the EFactory
JMerge                                generation
                                         gap




               files in VCS
                          results of
                  “git clean -fdX && tree”



         Here we can see which files need to be put under version
         control.

         - on the left-hand side, the unmodified library-example.
         - on the right-hand side, the example with generation
         gap. Please note that here no generated source code is
         being put under version control.
How does this work?


hack’ed EMFGen’s ImportManager


   The EMF-Generator has an ImportManaged that returns a
   SimpleName for each QualifiedName of a Java-Element that is
   used within the generated source code. Now, if there is a
   “Custom”-Class/Interface for a certain generated Java Class/
   Interface, the name of the “Custom”-Class/Interface is
   returned instead.
Generating Code...
   ...without a
Template Language
hey, we can generate this!
hey, we can generate this!


                 yes! I know a good template
                           language.
hey, we can generate this!


                  yes! I know a good template
                            language.


   yeah, let’s do it.
hey, we can generate this!


                    yes! I know a good template
                              language.


   yeah, let’s do it.




                !       not so fast...
code generation == map models to text
code generation == map models to text
code generation == map models to text



Template
code generation == map models to text



Template



             XML Schema
code generation == map models to text



Template
                                Grammar


             XML Schema
code generation == map models to text



Template
                                Grammar


             XML Schema
EMF provides a wizard to convert XML-Schema to Ecore.


                                                                XSD




Ecore
EMF provides a wizard to convert XML-Schema to Ecore.


                                                                XSD




Ecore
EMF provides a wizard to convert XML-Schema to Ecore.


                                                                XSD




Ecore
EMF provides a wizard to convert XML-Schema to Ecore.


                                                                XSD




Ecore
The Package Explorer shows a minimal example that
generates RSS, which is in fact XML. rss-2.0.xsd has
been downloaded from the internet and ecore/
genmodel have been derived from it.

The Java code shows is a complete example of what is
needed to run the code generation.

The Console shows the output of this this example.
The Package Explorer shows a minimal example that
generates RSS, which is in fact XML. rss-2.0.xsd has
been downloaded from the internet and ecore/
genmodel have been derived from it.

The Java code shows is a complete example of what is
needed to run the code generation.

The Console shows the output of this this example.
The Package Explorer shows a minimal example that
generates RSS, which is in fact XML. rss-2.0.xsd has
been downloaded from the internet and ecore/
genmodel have been derived from it.

The Java code shows is a complete example of what is
needed to run the code generation.

The Console shows the output of this this example.
what you get for free if you generate code via...

template       v.s.    XSD
what you get for free if you generate code via...

template       v.s.    XSD
                       • well-formed-ness
                       • xsd-compliance
                       • formatting
                       • escaping
                       • typed Java-model
                       • headers
                       • namespaces
Grammar

Text                                                              Model




       Most people probably know Xtext as a technology that can parse text into models.
       But it also works the other way around - models can be serialized into text!
parse


                      Grammar

Text                                                              Model




       Most people probably know Xtext as a technology that can parse text into models.
       But it also works the other way around - models can be serialized into text!
parse


                      Grammar

Text                                                              Model

             serialize

       Most people probably know Xtext as a technology that can parse text into models.
       But it also works the other way around - models can be serialized into text!
parse


                      Grammar

Text                                                              Model

             serialize

       Most people probably know Xtext as a technology that can parse text into models.
       But it also works the other way around - models can be serialized into text!
This example is a modified version of the arithmetics-
example that ships with Xtext. It has been extended to allow
serialization. The new*-Methods in the java code are
utilities that simplify constructing a model. They delegate to
the generated EFactory.
This example is a modified version of the arithmetics-
example that ships with Xtext. It has been extended to allow
serialization. The new*-Methods in the java code are
utilities that simplify constructing a model. They delegate to
the generated EFactory.
This example is a modified version of the arithmetics-
example that ships with Xtext. It has been extended to allow
serialization. The new*-Methods in the java code are
utilities that simplify constructing a model. They delegate to
the generated EFactory.
what you get for free if you generate code via...


template      v.s.     Grammar
what you get for free if you generate code via...


template      v.s.     Grammar
                       • correct syntax
                       • error messages for
                         invalid models
                       • good separation of
                         concerns (see next slide)
                       • typed Java-model
                       • an Xtext-editor ;)
serialization - separation of concerns
serialization - separation of concerns

model:   Ecore (can be derived from grammar)
serialization - separation of concerns

model:     Ecore (can be derived from grammar)
syntactical structure:   Xtext Grammar
serialization - separation of concerns

model:     Ecore (can be derived from grammar)
syntactical structure:   Xtext Grammar
transient values:   ITransientValueService
serialization - separation of concerns

model:     Ecore (can be derived from grammar)
syntactical structure:   Xtext Grammar
transient values:   ITransientValueService
token syntax:   IValueConverter
serialization - separation of concerns

model:     Ecore (can be derived from grammar)
syntactical structure:   Xtext Grammar
transient values:   ITransientValueService
token syntax:   IValueConverter
formatting:   IFormatter
serialization - separation of concerns

model:     Ecore (can be derived from grammar)
syntactical structure:   Xtext Grammar
transient values:   ITransientValueService
token syntax:   IValueConverter
formatting:   IFormatter
identifiers:   IQualifiedNameProvider,
serialization - separation of concerns

model:     Ecore (can be derived from grammar)
syntactical structure:   Xtext Grammar
transient values:   ITransientValueService
token syntax:   IValueConverter
formatting:   IFormatter
identifiers:   IQualifiedNameProvider,
              IScopeProvider
Xtext’s serializer: status


 Xtext 1.0 (Helios)                Xtext 2.0 (Indigo)
• algorithm: backtracking   • algorithm: object-tree-parser
                            • improves:
                              • customizability
                              • error messages         new
                              • performance
Xtext’s serializer: status


 Xtext 1.0 (Helios)                Xtext 2.0 (Indigo)
• algorithm: backtracking   • algorithm: object-tree-parser
                            • improves:
                              • customizability
                              • error messages         new
                              • performance

                                        complete
                                   re-implementation
Questions?




Moritz.Eysholdt@itemis.de

Mais conteúdo relacionado

Mais procurados

Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)mircodotta
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingRichardWarburton
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript BasicsMindfire Solutions
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming LanguageRaghavan Mohan
 
Java best practices
Java best practicesJava best practices
Java best practicesRay Toal
 
Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987乐群 陈
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)jeffz
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptWalid Ashraf
 
What I Love About Ruby
What I Love About RubyWhat I Love About Ruby
What I Love About RubyKeith Bennett
 
Functional solid
Functional solidFunctional solid
Functional solidMatt Stine
 
Enriching Your Models with OCL
Enriching Your Models with OCLEnriching Your Models with OCL
Enriching Your Models with OCLEdward Willink
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelRamrao Desai
 

Mais procurados (20)

Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)Effective Scala (SoftShake 2013)
Effective Scala (SoftShake 2013)
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
 
Javascript
JavascriptJavascript
Javascript
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
 
Java Performance MythBusters
Java Performance MythBustersJava Performance MythBusters
Java Performance MythBusters
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Java best practices
Java best practicesJava best practices
Java best practices
 
Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
What I Love About Ruby
What I Love About RubyWhat I Love About Ruby
What I Love About Ruby
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
OCL in EMF
OCL in EMFOCL in EMF
OCL in EMF
 
Functional solid
Functional solidFunctional solid
Functional solid
 
Enriching Your Models with OCL
Enriching Your Models with OCLEnriching Your Models with OCL
Enriching Your Models with OCL
 
Groovy Programming Language
Groovy Programming LanguageGroovy Programming Language
Groovy Programming Language
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Quick swift tour
Quick swift tourQuick swift tour
Quick swift tour
 

Destaque

Parsing Expression With Xtext
Parsing Expression With XtextParsing Expression With Xtext
Parsing Expression With XtextSven Efftinge
 
Language Engineering With Xtext
Language Engineering With XtextLanguage Engineering With Xtext
Language Engineering With XtextSven Efftinge
 
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2Dr. Jan Köhnlein
 
Building Your Own DSL with Xtext
Building Your Own DSL with XtextBuilding Your Own DSL with Xtext
Building Your Own DSL with XtextGlobalLogic Ukraine
 
Executable specifications for xtext
Executable specifications for xtextExecutable specifications for xtext
Executable specifications for xtextmeysholdt
 
Introduction to Xbase
Introduction to XbaseIntroduction to Xbase
Introduction to XbaseHolger Schill
 
Lightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT WidgetsLightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT Widgetsmeysholdt
 
Recipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with XtendRecipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with XtendKarsten Thoms
 
Graphical Views For Xtext With FXDiagram
Graphical Views For Xtext With FXDiagramGraphical Views For Xtext With FXDiagram
Graphical Views For Xtext With FXDiagramDr. Jan Köhnlein
 
Xtend - A Language Made for Java Developers
Xtend - A Language Made for Java DevelopersXtend - A Language Made for Java Developers
Xtend - A Language Made for Java DevelopersSebastian Zarnekow
 
Jazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipseJazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipsePeter Friese
 

Destaque (20)

Future of Xtext
Future of XtextFuture of Xtext
Future of Xtext
 
Xtext Best Practices
Xtext Best PracticesXtext Best Practices
Xtext Best Practices
 
Parsing Expression With Xtext
Parsing Expression With XtextParsing Expression With Xtext
Parsing Expression With Xtext
 
What's Cooking in Xtext 2.0
What's Cooking in Xtext 2.0What's Cooking in Xtext 2.0
What's Cooking in Xtext 2.0
 
Language Engineering With Xtext
Language Engineering With XtextLanguage Engineering With Xtext
Language Engineering With Xtext
 
Scoping
ScopingScoping
Scoping
 
Scoping Tips and Tricks
Scoping Tips and TricksScoping Tips and Tricks
Scoping Tips and Tricks
 
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
 
Building Your Own DSL with Xtext
Building Your Own DSL with XtextBuilding Your Own DSL with Xtext
Building Your Own DSL with Xtext
 
Executable specifications for xtext
Executable specifications for xtextExecutable specifications for xtext
Executable specifications for xtext
 
Java DSLs with Xtext
Java DSLs with XtextJava DSLs with Xtext
Java DSLs with Xtext
 
Introduction to Xbase
Introduction to XbaseIntroduction to Xbase
Introduction to Xbase
 
Lightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT WidgetsLightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT Widgets
 
The Xtext Grammar Language
The Xtext Grammar LanguageThe Xtext Grammar Language
The Xtext Grammar Language
 
Recipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with XtendRecipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with Xtend
 
EMF - Beyond The Basics
EMF - Beyond The BasicsEMF - Beyond The Basics
EMF - Beyond The Basics
 
Graphical Views For Xtext With FXDiagram
Graphical Views For Xtext With FXDiagramGraphical Views For Xtext With FXDiagram
Graphical Views For Xtext With FXDiagram
 
DSLs for Java Developers
DSLs for Java DevelopersDSLs for Java Developers
DSLs for Java Developers
 
Xtend - A Language Made for Java Developers
Xtend - A Language Made for Java DevelopersXtend - A Language Made for Java Developers
Xtend - A Language Made for Java Developers
 
Jazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipseJazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with Eclipse
 

Semelhante a Codegeneration Goodies

Xcore meets IncQuery: How the New Generation of DSLs are Made
Xcore meets IncQuery: How the New Generation of DSLs are MadeXcore meets IncQuery: How the New Generation of DSLs are Made
Xcore meets IncQuery: How the New Generation of DSLs are MadeIstvan Rath
 
02 java programming basic
02  java programming basic02  java programming basic
02 java programming basicZeeshan-Shaikh
 
YAPC::NA 2007 - Epic Perl Coding
YAPC::NA 2007 - Epic Perl CodingYAPC::NA 2007 - Epic Perl Coding
YAPC::NA 2007 - Epic Perl Codingjoshua.mcadams
 
Econ11 weaving
Econ11 weavingEcon11 weaving
Econ11 weavingt_ware
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaWO Community
 
EMF - The off beat path
EMF - The off beat pathEMF - The off beat path
EMF - The off beat path17thcamel
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017Ayush Sharma
 
Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMTom Lee
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaBrian Topping
 
Construction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific LanguagesConstruction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific LanguagesThoughtWorks
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for MainframersRich Helton
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San FranciscoMartin Odersky
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionGanesh Samarthyam
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to ElixirDiacode
 
Principled io in_scala_2019_distribution
Principled io in_scala_2019_distributionPrincipled io in_scala_2019_distribution
Principled io in_scala_2019_distributionRaymond Tay
 
Visual COBOL Development for Unix and Java
Visual COBOL Development for Unix and JavaVisual COBOL Development for Unix and Java
Visual COBOL Development for Unix and JavaMicro Focus
 
asgmt01.classpathasgmt01.project asgmt01 .docx
asgmt01.classpathasgmt01.project  asgmt01  .docxasgmt01.classpathasgmt01.project  asgmt01  .docx
asgmt01.classpathasgmt01.project asgmt01 .docxfredharris32
 

Semelhante a Codegeneration Goodies (20)

Xcore meets IncQuery: How the New Generation of DSLs are Made
Xcore meets IncQuery: How the New Generation of DSLs are MadeXcore meets IncQuery: How the New Generation of DSLs are Made
Xcore meets IncQuery: How the New Generation of DSLs are Made
 
02 java programming basic
02  java programming basic02  java programming basic
02 java programming basic
 
YAPC::NA 2007 - Epic Perl Coding
YAPC::NA 2007 - Epic Perl CodingYAPC::NA 2007 - Epic Perl Coding
YAPC::NA 2007 - Epic Perl Coding
 
Econ11 weaving
Econ11 weavingEcon11 weaving
Econ11 weaving
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
EMF - The off beat path
EMF - The off beat pathEMF - The off beat path
EMF - The off beat path
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017
 
Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVM
 
Scalax
ScalaxScalax
Scalax
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with Scala
 
Construction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific LanguagesConstruction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific Languages
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
mdeshell
mdeshellmdeshell
mdeshell
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
 
Principled io in_scala_2019_distribution
Principled io in_scala_2019_distributionPrincipled io in_scala_2019_distribution
Principled io in_scala_2019_distribution
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
Visual COBOL Development for Unix and Java
Visual COBOL Development for Unix and JavaVisual COBOL Development for Unix and Java
Visual COBOL Development for Unix and Java
 
asgmt01.classpathasgmt01.project asgmt01 .docx
asgmt01.classpathasgmt01.project  asgmt01  .docxasgmt01.classpathasgmt01.project  asgmt01  .docx
asgmt01.classpathasgmt01.project asgmt01 .docx
 

Último

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Último (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

Codegeneration Goodies

  • 1. Codegeneration Goodies Moritz.Eysholdt@itemis.de These slides have been presented at the EclipseCon 2011 conference in Santa Clara: http://www.eclipsecon.org/2011/sessions/?page=sessions&id=2253 They have been modified for slideshare.net to contain additional explanatory comments. The source code of the demos is available at http://github.com/meysholdt/codegeneration-goodies-demos
  • 3. We can edit the generated source code!
  • 4. We can edit the generated source code! actually, NO.
  • 5. We can edit the generated source code! actually, NO. • complicated to merge generated/handwritten code
  • 6. We can edit the generated source code! actually, NO. • complicated to merge generated/handwritten code • handwritten code “gets lost” within generated code
  • 7. We can edit the generated source code! actually, NO. • complicated to merge generated/handwritten code • handwritten code “gets lost” within generated code • requires to put generated source code under version control
  • 8. We can edit the generated source code! actually, NO. • complicated to merge generated/handwritten code • handwritten code “gets lost” within generated code • requires to put generated source code under version control • generated version of source code is lost once modified
  • 10. JMerge • Unneeded files are not removed
  • 11. JMerge • Unneeded files are not removed • easy to forget to remove @Generated
  • 12. JMerge • Unneeded files are not removed • easy to forget to remove @Generated • Handwritten, but orphaned code can easily be forgotten
  • 13. JMerge • Unneeded files are not removed • easy to forget to remove @Generated • Handwritten, but orphaned code can easily be forgotten • Import statements are not organized
  • 14. JMerge • Unneeded files are not removed • easy to forget to remove @Generated • Handwritten, but orphaned code can easily be forgotten • Import statements are not organized • etc.
  • 16. Solution: Generation Gap • inheritance + Java’s @Override instead of @Generated
  • 17. Solution: Generation Gap • inheritance + Java’s @Override instead of @Generated • two folders: “src”and “src-gen”
  • 18. Solution: Generation Gap • inheritance + Java’s @Override instead of @Generated • two folders: “src”and “src-gen” • use MWE’s EcoreGenerator instead of JMerge
  • 19. This is the famous library- example that ships with EMF.
  • 20. - interfaces - impl-classes - util (all generated) This is the famous library- example that ships with EMF.
  • 21. - interfaces - impl-classes - util (all generated) This is the - Ecore Model famous library- example that - Genmodel ships with EMF.
  • 22. - interfaces - impl-classes - util (all generated) This is the - Ecore Model famous library- example that - Genmodel ships with EMF.
  • 23. - interfaces - impl-classes - util (all generated) This is the - Ecore Model famous library- example that - Genmodel ships with EMF. Impl implements interface
  • 24. unmodified library- library-example with example from EMF Generation Gap
  • 25. unmodified library- library-example with example from EMF Generation Gap
  • 26. unmodified library- library-example with example from EMF Generation Gap
  • 27. unmodified library- library-example with example from EMF Generation Gap
  • 28. unmodified library- library-example with example from EMF Generation Gap
  • 29. unmodified library- library-example with example from EMF Generation Gap
  • 30. unmodified library- library-example with example from EMF Generation Gap
  • 31. Form the “Library”-EClass, EMF generates a “Library”-Interface and a “LibraryImpl”-Class. With the GenerationGap-Pattern, we additionally have a “LibraryImplCustom”-Class
  • 32. Form the “Library”-EClass, EMF generates a “Library”-Interface and a “LibraryImpl”-Class. With the GenerationGap-Pattern, we additionally have a “LibraryImplCustom”-Class
  • 33. Form the “Library”-EClass, EMF generates a “Library”-Interface and a “LibraryImpl”-Class. With the GenerationGap-Pattern, we additionally have a “LibraryImplCustom”-Class
  • 34. Form the “Library”-EClass, EMF generates a “Library”-Interface and a “LibraryImpl”-Class. With the GenerationGap-Pattern, we additionally have a “LibraryImplCustom”-Class
  • 35. generated code refers to “custom” classes as super types In the code that is generated by EMF, the “Custom”-Classes are automatically used instead of the “Impl”-Classes, when - another “Impl” class extends them. - the EFactory instantiated them.
  • 36. generated code refers to “custom” classes as super types In the code that is generated by EMF, the “Custom”-Classes are automatically used instead of the “Impl”-Classes, when - another “Impl” class extends them. - the EFactory instantiated them. in the EFactory
  • 37. JMerge generation gap files in VCS results of “git clean -fdX && tree” Here we can see which files need to be put under version control. - on the left-hand side, the unmodified library-example. - on the right-hand side, the example with generation gap. Please note that here no generated source code is being put under version control.
  • 38. How does this work? hack’ed EMFGen’s ImportManager The EMF-Generator has an ImportManaged that returns a SimpleName for each QualifiedName of a Java-Element that is used within the generated source code. Now, if there is a “Custom”-Class/Interface for a certain generated Java Class/ Interface, the name of the “Custom”-Class/Interface is returned instead.
  • 39. Generating Code... ...without a Template Language
  • 40. hey, we can generate this!
  • 41. hey, we can generate this! yes! I know a good template language.
  • 42. hey, we can generate this! yes! I know a good template language. yeah, let’s do it.
  • 43. hey, we can generate this! yes! I know a good template language. yeah, let’s do it. ! not so fast...
  • 44. code generation == map models to text
  • 45. code generation == map models to text
  • 46. code generation == map models to text Template
  • 47. code generation == map models to text Template XML Schema
  • 48. code generation == map models to text Template Grammar XML Schema
  • 49. code generation == map models to text Template Grammar XML Schema
  • 50. EMF provides a wizard to convert XML-Schema to Ecore. XSD Ecore
  • 51. EMF provides a wizard to convert XML-Schema to Ecore. XSD Ecore
  • 52. EMF provides a wizard to convert XML-Schema to Ecore. XSD Ecore
  • 53. EMF provides a wizard to convert XML-Schema to Ecore. XSD Ecore
  • 54. The Package Explorer shows a minimal example that generates RSS, which is in fact XML. rss-2.0.xsd has been downloaded from the internet and ecore/ genmodel have been derived from it. The Java code shows is a complete example of what is needed to run the code generation. The Console shows the output of this this example.
  • 55. The Package Explorer shows a minimal example that generates RSS, which is in fact XML. rss-2.0.xsd has been downloaded from the internet and ecore/ genmodel have been derived from it. The Java code shows is a complete example of what is needed to run the code generation. The Console shows the output of this this example.
  • 56. The Package Explorer shows a minimal example that generates RSS, which is in fact XML. rss-2.0.xsd has been downloaded from the internet and ecore/ genmodel have been derived from it. The Java code shows is a complete example of what is needed to run the code generation. The Console shows the output of this this example.
  • 57. what you get for free if you generate code via... template v.s. XSD
  • 58. what you get for free if you generate code via... template v.s. XSD • well-formed-ness • xsd-compliance • formatting • escaping • typed Java-model • headers • namespaces
  • 59. Grammar Text Model Most people probably know Xtext as a technology that can parse text into models. But it also works the other way around - models can be serialized into text!
  • 60. parse Grammar Text Model Most people probably know Xtext as a technology that can parse text into models. But it also works the other way around - models can be serialized into text!
  • 61. parse Grammar Text Model serialize Most people probably know Xtext as a technology that can parse text into models. But it also works the other way around - models can be serialized into text!
  • 62. parse Grammar Text Model serialize Most people probably know Xtext as a technology that can parse text into models. But it also works the other way around - models can be serialized into text!
  • 63. This example is a modified version of the arithmetics- example that ships with Xtext. It has been extended to allow serialization. The new*-Methods in the java code are utilities that simplify constructing a model. They delegate to the generated EFactory.
  • 64. This example is a modified version of the arithmetics- example that ships with Xtext. It has been extended to allow serialization. The new*-Methods in the java code are utilities that simplify constructing a model. They delegate to the generated EFactory.
  • 65. This example is a modified version of the arithmetics- example that ships with Xtext. It has been extended to allow serialization. The new*-Methods in the java code are utilities that simplify constructing a model. They delegate to the generated EFactory.
  • 66. what you get for free if you generate code via... template v.s. Grammar
  • 67. what you get for free if you generate code via... template v.s. Grammar • correct syntax • error messages for invalid models • good separation of concerns (see next slide) • typed Java-model • an Xtext-editor ;)
  • 69. serialization - separation of concerns model: Ecore (can be derived from grammar)
  • 70. serialization - separation of concerns model: Ecore (can be derived from grammar) syntactical structure: Xtext Grammar
  • 71. serialization - separation of concerns model: Ecore (can be derived from grammar) syntactical structure: Xtext Grammar transient values: ITransientValueService
  • 72. serialization - separation of concerns model: Ecore (can be derived from grammar) syntactical structure: Xtext Grammar transient values: ITransientValueService token syntax: IValueConverter
  • 73. serialization - separation of concerns model: Ecore (can be derived from grammar) syntactical structure: Xtext Grammar transient values: ITransientValueService token syntax: IValueConverter formatting: IFormatter
  • 74. serialization - separation of concerns model: Ecore (can be derived from grammar) syntactical structure: Xtext Grammar transient values: ITransientValueService token syntax: IValueConverter formatting: IFormatter identifiers: IQualifiedNameProvider,
  • 75. serialization - separation of concerns model: Ecore (can be derived from grammar) syntactical structure: Xtext Grammar transient values: ITransientValueService token syntax: IValueConverter formatting: IFormatter identifiers: IQualifiedNameProvider, IScopeProvider
  • 76. Xtext’s serializer: status Xtext 1.0 (Helios) Xtext 2.0 (Indigo) • algorithm: backtracking • algorithm: object-tree-parser • improves: • customizability • error messages new • performance
  • 77. Xtext’s serializer: status Xtext 1.0 (Helios) Xtext 2.0 (Indigo) • algorithm: backtracking • algorithm: object-tree-parser • improves: • customizability • error messages new • performance complete re-implementation

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n