Codegeneration    Goodies Moritz.Eysholdt@itemis.de   test
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 cod...
We can edit the generated source code!                       actually, NO.• complicated to merge generated/handwritten cod...
We can edit the generated source code!                       actually, NO.• complicated to merge generated/handwritten cod...
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 ...
JMerge• Unneeded files are not removed• easy to forget to remove @Generated• Handwritten, but orphaned code can  easily be ...
JMerge• Unneeded files are not removed• easy to forget to remove @Generated• Handwritten, but orphaned code can  easily be ...
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...
test
- interfaces       - impl-classes       - util       (all generated)test
- interfaces       - impl-classes       - util       (all generated)test       - Ecore Model       - Genmodel
- interfaces       - impl-classes       - util       (all generated)test       - Ecore Model       - Genmodel
- interfaces       - impl-classes       - util       (all generated)test        - Ecore Model        - Genmodel       Impl...
generated code refers to “custom” classes as super types
generated code refers to “custom” classes as super types                                 in the EFactory
JMerge               generation                        gap         files in VCS                 results of         “git cle...
How does this work?hack’ed EMFGen’s ImportManager
Generating Code...   ...without aTemplate 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...
hey, we can generate this!                    yes! I know a good template                              language.   yeah, l...
code generation == map models to text
code generation == map models to text
code generation == map models to textTemplate
code generation == map models to textTemplate             XML Schema
code generation == map models to textTemplate                                Grammar             XML Schema
code generation == map models to textTemplate                                Grammar             XML Schema
XSDEcore
XSDEcore
XSDEcore
XSDEcore
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      ...
GrammarText             Model
parse        GrammarText              Model
parse           GrammarText                 Model       serialize
parse           GrammarText                 Model       serialize
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    ...
serialization - separation of concerns
serialization - separation of concernsmodel:   Ecore (can be derived from grammar)
serialization - separation of concernsmodel:     Ecore (can be derived from grammar)syntactical structure:   Xtext Grammar
serialization - separation of concernsmodel:     Ecore (can be derived from grammar)syntactical structure:   Xtext Grammar...
serialization - separation of concernsmodel:     Ecore (can be derived from grammar)syntactical structure:   Xtext Grammar...
serialization - separation of concernsmodel:     Ecore (can be derived from grammar)syntactical structure:   Xtext Grammar...
serialization - separation of concernsmodel:     Ecore (can be derived from grammar)syntactical structure:   Xtext Grammar...
serialization - separation of concernsmodel:     Ecore (can be derived from grammar)syntactical structure:   Xtext Grammar...
Xtext’s serializer: status Xtext 1.0 (Helios)                Xtext 2.0 (Indigo)• algorithm: backtracking   • algorithm: ob...
Xtext’s serializer: status Xtext 1.0 (Helios)                Xtext 2.0 (Indigo)• algorithm: backtracking   • algorithm: ob...
Questions?Moritz.Eysholdt@itemis.de
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Codegeneration Goodies
Upcoming SlideShare
Loading in …5
×

Codegeneration Goodies

3,136
-1

Published on

http://www.eclipsecon.org/2011/sessions/?page=sessions&id=2253

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,136
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
56
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide
  • \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
  • Codegeneration Goodies

    1. 1. Codegeneration Goodies Moritz.Eysholdt@itemis.de test
    2. 2. Generate Code... ...customize?
    3. 3. We can edit the generated source code!
    4. 4. We can edit the generated source code! actually, NO.
    5. 5. We can edit the generated source code! actually, NO.• complicated to merge generated/handwritten code
    6. 6. We can edit the generated source code! actually, NO.• complicated to merge generated/handwritten code• handwritten code “gets lost” within generated code
    7. 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. 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
    9. 9. JMerge
    10. 10. JMerge• Unneeded files are not removed
    11. 11. JMerge• Unneeded files are not removed• easy to forget to remove @Generated
    12. 12. JMerge• Unneeded files are not removed• easy to forget to remove @Generated• Handwritten, but orphaned code can easily be forgotten
    13. 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. 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.
    15. 15. Solution: Generation Gap
    16. 16. Solution: Generation Gap• inheritance + Java’s @Override instead of @Generated
    17. 17. Solution: Generation Gap• inheritance + Java’s @Override instead of @Generated• two folders: “src”and “src-gen”
    18. 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. 19. test
    20. 20. - interfaces - impl-classes - util (all generated)test
    21. 21. - interfaces - impl-classes - util (all generated)test - Ecore Model - Genmodel
    22. 22. - interfaces - impl-classes - util (all generated)test - Ecore Model - Genmodel
    23. 23. - interfaces - impl-classes - util (all generated)test - Ecore Model - Genmodel Impl implements interface
    24. 24. generated code refers to “custom” classes as super types
    25. 25. generated code refers to “custom” classes as super types in the EFactory
    26. 26. JMerge generation gap files in VCS results of “git clean -fdX && tree”
    27. 27. How does this work?hack’ed EMFGen’s ImportManager
    28. 28. Generating Code... ...without aTemplate Language
    29. 29. hey, we can generate this!
    30. 30. hey, we can generate this! yes! I know a good template language.
    31. 31. hey, we can generate this! yes! I know a good template language. yeah, let’s do it.
    32. 32. hey, we can generate this! yes! I know a good template language. yeah, let’s do it. ! not so fast...
    33. 33. code generation == map models to text
    34. 34. code generation == map models to text
    35. 35. code generation == map models to textTemplate
    36. 36. code generation == map models to textTemplate XML Schema
    37. 37. code generation == map models to textTemplate Grammar XML Schema
    38. 38. code generation == map models to textTemplate Grammar XML Schema
    39. 39. XSDEcore
    40. 40. XSDEcore
    41. 41. XSDEcore
    42. 42. XSDEcore
    43. 43. what you get for free if you generate code via...template v.s. XSD
    44. 44. 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
    45. 45. GrammarText Model
    46. 46. parse GrammarText Model
    47. 47. parse GrammarText Model serialize
    48. 48. parse GrammarText Model serialize
    49. 49. what you get for free if you generate code via...template v.s. Grammar
    50. 50. 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 ;)
    51. 51. serialization - separation of concerns
    52. 52. serialization - separation of concernsmodel: Ecore (can be derived from grammar)
    53. 53. serialization - separation of concernsmodel: Ecore (can be derived from grammar)syntactical structure: Xtext Grammar
    54. 54. serialization - separation of concernsmodel: Ecore (can be derived from grammar)syntactical structure: Xtext Grammartransient values: ITransientValueService
    55. 55. serialization - separation of concernsmodel: Ecore (can be derived from grammar)syntactical structure: Xtext Grammartransient values: ITransientValueServicetoken syntax: IValueConverter
    56. 56. serialization - separation of concernsmodel: Ecore (can be derived from grammar)syntactical structure: Xtext Grammartransient values: ITransientValueServicetoken syntax: IValueConverterformatting: IFormatter
    57. 57. serialization - separation of concernsmodel: Ecore (can be derived from grammar)syntactical structure: Xtext Grammartransient values: ITransientValueServicetoken syntax: IValueConverterformatting: IFormatteridentifiers: IQualifiedNameProvider,
    58. 58. serialization - separation of concernsmodel: Ecore (can be derived from grammar)syntactical structure: Xtext Grammartransient values: ITransientValueServicetoken syntax: IValueConverterformatting: IFormatteridentifiers: IQualifiedNameProvider, IScopeProvider
    59. 59. Xtext’s serializer: status Xtext 1.0 (Helios) Xtext 2.0 (Indigo)• algorithm: backtracking • algorithm: object-tree-parser • improves: • customizability • error messages new • performance
    60. 60. 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
    61. 61. Questions?Moritz.Eysholdt@itemis.de
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×