ImportAll.hx 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2005, The haXe Project Contributors
  3. * All rights reserved.
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * - Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * - Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  23. * DAMAGE.
  24. */
  25. import haxe.macro.Context;
  26. class ImportAll {
  27. public static function run( ?pack ) {
  28. if( pack == null ) {
  29. pack = "";
  30. haxe.macro.Compiler.define("doc_gen");
  31. }
  32. switch( pack ) {
  33. case "php":
  34. if( !Context.defined("php") ) return;
  35. case "neko":
  36. if( !Context.defined("neko") ) return;
  37. case "js":
  38. if( !Context.defined("js") ) return;
  39. case "cpp":
  40. if( !Context.defined("cpp") ) return;
  41. case "flash8":
  42. if( !Context.defined("flash") || Context.defined("flash9") ) return;
  43. case "flash":
  44. if( !Context.defined("flash9") ) return;
  45. case "mt","mtwin":
  46. return;
  47. case "sys":
  48. if( !Context.defined("neko") && !Context.defined("php") && !Context.defined("cpp") ) return;
  49. case "java":
  50. if( !Context.defined("java") ) return;
  51. case "cs":
  52. if( !Context.defined("cs") ) return;
  53. case "tools":
  54. return;
  55. case "build-tool":
  56. return;
  57. }
  58. for( p in Context.getClassPath() ) {
  59. if( p == "/" )
  60. continue;
  61. // skip if we have a classpath to haxe
  62. if( pack.length == 0 && sys.FileSystem.exists(p+"std") )
  63. continue;
  64. var p = p + pack.split(".").join("/");
  65. if( StringTools.endsWith(p,"/") )
  66. p = p.substr(0,-1);
  67. if( !sys.FileSystem.exists(p) || !sys.FileSystem.isDirectory(p) )
  68. continue;
  69. for( file in sys.FileSystem.readDirectory(p) ) {
  70. if( file == ".svn" || file == "_std" )
  71. continue;
  72. var full = (pack == "") ? file : pack + "." + file;
  73. if( StringTools.endsWith(file, ".hx") ) {
  74. var cl = full.substr(0, full.length - 3);
  75. if( StringTools.startsWith(cl,"flash8.") )
  76. cl = "flash."+cl.substr(7);
  77. switch( cl ) {
  78. case "ImportAll", "neko.db.MacroManager": continue;
  79. case "haxe.TimerQueue": if( Context.defined("neko") || Context.defined("php") || Context.defined("cpp") ) continue;
  80. case "Sys": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("cpp")) ) continue;
  81. case "haxe.web.Request": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("js")) ) continue;
  82. case "haxe.macro.ExampleJSGenerator","haxe.macro.Context", "haxe.macro.Compiler": if( !Context.defined("neko") ) continue;
  83. case "haxe.remoting.SocketWrapper": if( !Context.defined("flash") ) continue;
  84. case "haxe.remoting.SyncSocketConnection": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("cpp")) ) continue;
  85. }
  86. Context.getModule(cl);
  87. } else if( sys.FileSystem.isDirectory(p + "/" + file) )
  88. run(full);
  89. }
  90. }
  91. }
  92. }