SemanticAdaptationFormatter.xtend 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * generated by Xtext 2.11.0
  3. */
  4. package be.uantwerpen.ansymo.semanticadaptation.formatting2
  5. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Adaptation
  6. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CompositeOutputFunction
  7. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CustomControlRule
  8. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.DataRule
  9. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
  10. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.StateTransitionFunction
  11. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Statement
  12. import be.uantwerpen.ansymo.semanticadaptation.log.Log
  13. import org.eclipse.xtext.formatting2.AbstractFormatter2
  14. import org.eclipse.xtext.formatting2.IFormattableDocument
  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. if (sa.params.size > 0){
  34. for (paramDecls : sa.params){
  35. paramDecls.prepend[newLine]
  36. }
  37. }
  38. if (sa.in !== null){
  39. sa.in.regionFor.keyword('in').prepend[newLine]
  40. for (rule : sa.in.rules){
  41. rule.format
  42. }
  43. }
  44. if (sa.out !== null){
  45. sa.out.regionFor.keyword('out').prepend[newLine]
  46. for (rule : sa.out.rules){
  47. rule.format
  48. }
  49. }
  50. if (sa.control !== null){
  51. sa.control.prepend[newLine]
  52. sa.control.rule.format
  53. }
  54. /*
  55. for (inPort : sa.inports){
  56. Log.push("Formatting inPort " + inPort.name)
  57. inPort.regionFor.feature(SemanticAdaptationPackage.Literals.PORT__TYPE).prepend[newLine]
  58. Log.pop("Formatting inPort " + inPort.name)
  59. }
  60. */
  61. Log.pop("Formatting adaptation")
  62. }
  63. def dispatch void format(DataRule rule, extension IFormattableDocument document){
  64. Log.push("Formatting DataRule")
  65. rule.prepend[newLine]
  66. rule.statetransitionfunction.format
  67. rule.outputfunction.format
  68. Log.pop("Formatting DataRule")
  69. }
  70. def dispatch void format(CustomControlRule rule, extension IFormattableDocument document){
  71. Log.push("Formatting CustomControlRule")
  72. rule.prepend[newLine]
  73. for (statement : rule.controlRulestatements){
  74. statement.format
  75. }
  76. rule.returnstatement.prepend[newLine]
  77. Log.pop("Formatting CustomControlRule")
  78. }
  79. def dispatch void format(StateTransitionFunction function, extension IFormattableDocument document){
  80. Log.push("Formatting StateTransitionFunction")
  81. for (statement : function.statements){
  82. statement.format
  83. }
  84. Log.pop("Formatting StateTransitionFunction")
  85. }
  86. def dispatch void format(CompositeOutputFunction function, extension IFormattableDocument document){
  87. Log.push("Formatting CompositeOutputFunction")
  88. for (statement : function.statements){
  89. statement.format
  90. }
  91. Log.pop("Formatting CompositeOutputFunction")
  92. }
  93. def dispatch void format(Statement statement, extension IFormattableDocument document){
  94. Log.push("Formatting Statement")
  95. statement.prepend[newLine]
  96. Log.pop("Formatting Statement")
  97. }
  98. }