Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Codegeneration Goodies

3,673 views

Published on

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

Published in: Technology
  • Be the first to comment

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

×