SemanticAdaptationFormatter.xtend 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * generated by Xtext 2.11.0
  3. */
  4. package be.uantwerpen.ansymo.semanticadaptation.formatting2
  5. import be.uantwerpen.ansymo.semanticadaptation.generator.Log
  6. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Adaptation
  7. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.DataRule
  8. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
  9. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptationPackage
  10. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.StateTransitionFunction
  11. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Statement
  12. import org.eclipse.xtext.formatting2.AbstractFormatter2
  13. import org.eclipse.xtext.formatting2.IFormattableDocument
  14. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CompositeOutputFunction
  15. class SemanticAdaptationFormatter extends AbstractFormatter2 {
  16. //@Inject extension SemanticAdaptationGrammarAccess
  17. def dispatch void format(SemanticAdaptation semanticAdaptation, extension IFormattableDocument document) {
  18. Log.push("Formatting document")
  19. val adaptations = semanticAdaptation.elements.filter(Adaptation)
  20. if (adaptations.size == 0){
  21. Log.println("Warning: document has no adaptation declared. This is not supported yet.")
  22. return
  23. }
  24. val sa = adaptations.head
  25. Log.println("Adaptation: " + sa)
  26. sa.format
  27. Log.pop("Formatting document")
  28. }
  29. def dispatch void format(Adaptation sa, extension IFormattableDocument document){
  30. Log.push("Formatting adaptation")
  31. sa.regionFor.keyword('input').prepend[newLine]
  32. sa.regionFor.keyword('output').prepend[newLine]
  33. sa.regionFor.keyword('param').prepend[newLine]
  34. sa.regionFor.keyword('param').prepend[newLine]
  35. if (sa.in !== null){
  36. sa.in.regionFor.keyword('in').prepend[newLine]
  37. for (rule : sa.in.rules){
  38. rule.format
  39. }
  40. }
  41. /*
  42. for (inPort : sa.inports){
  43. Log.push("Formatting inPort " + inPort.name)
  44. inPort.regionFor.feature(SemanticAdaptationPackage.Literals.PORT__TYPE).prepend[newLine]
  45. Log.pop("Formatting inPort " + inPort.name)
  46. }
  47. */
  48. Log.pop("Formatting adaptation")
  49. }
  50. def dispatch void format(DataRule rule, extension IFormattableDocument document){
  51. Log.push("Formatting DataRule")
  52. rule.prepend[newLine]
  53. rule.statetransitionfunction.format
  54. rule.outputfunction.format
  55. Log.pop("Formatting DataRule")
  56. }
  57. def dispatch void format(StateTransitionFunction function, extension IFormattableDocument document){
  58. Log.push("Formatting StateTransitionFunction")
  59. for (statement : function.statements){
  60. statement.format
  61. }
  62. Log.pop("Formatting StateTransitionFunction")
  63. }
  64. def dispatch void format(CompositeOutputFunction function, extension IFormattableDocument document){
  65. Log.push("Formatting CompositeOutputFunction")
  66. for (statement : function.statements){
  67. statement.format
  68. }
  69. Log.pop("Formatting CompositeOutputFunction")
  70. }
  71. def dispatch void format(Statement statement, extension IFormattableDocument document){
  72. Log.push("Formatting Statement")
  73. statement.prepend[newLine]
  74. Log.pop("Formatting Statement")
  75. }
  76. }