Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.73 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Java code generation with XPAND (nested packages)
  2. model:
  3. package kitchen
  4. --package electronics
  5. --package food
  6. ----class tomatoe
  7.        
  8. package kitchen.food;
  9. class tomatoe{}
  10.        
  11. +---------+
  12. |Package  |
  13. |         |<>--+
  14. `---------+    | 0..* containedPackages
  15.         |      |
  16.         +------+ 0..1 parentPackage
  17.        
  18. «DEFINE class FOR Class»
  19.   import «EXPAND packagename FOR this.package»;
  20.   class «this.name»{}
  21. «ENDDEFINE»
  22.  
  23. «DEFINE packagename FOR Package»
  24.   «FOREACH this.packageHierarchy() as p SEPARATOR '.' -»«p»«ENDFOREACH»
  25. «ENDDEFINE»
  26.        
  27. List[Package] packageHierarchy(Package p):
  28.     let list = {}:
  29.     p.parentPackage == null ? list.add(p) : list.add(packageHierarchy(p.parentPackage)) ->
  30.     list.flatten().reverse()
  31. ;