1 | public Collection generateFiles(Collection elements, String path, | | 1 | private Collection generateFilesForElem(Object o, |
2 | boolean deps) { | | 2 | String path, boolean deps) { |
3 | List ret = new ArrayList(); | | 3 | Vector ret = new Vector(); |
4 | startFileGeneration(); | | 4 | if (generatedFiles.contains(o)) { |
5 | for (Iterator it = elements.iterator(); it.hasNext(); ) { | | 5 | return ret; // generated already |
6 | Object elem = it.next(); | | 6 | } |
7 | ret.addAll(generateFilesForElem(elem, path, deps)); | | 7 | if (!getFacade().isAClass(o) && !getFacade().isAInterface(o)) { |
8 | } | | 8 | return ret; // not a class or interface |
9 | endFileGeneration(); | | 9 | } |
10 | return ret; | | 10 | while (isAInnerClass(o)) { |
11 | } | | 11 | o = getFacade().getNamespace(o); |
| | | 12 | } |
| | | 13 | String pathname = null; |
| | | 14 | |
| | | 15 | // use unique section for both passes -> allow move of |
| | | 16 | // normal function body to inline and vice versa |
| | | 17 | if (Section.getUseSect() != Section.SECT_NONE) { |
| | | 18 | sect = new Section(); |
| | | 19 | |
| | | 20 | /* |
| | | 21 | * 2002-11-28 Achim Spangler |
| | | 22 | * first read header and source file into global/unique section |
| | | 23 | */ |
| | | 24 | for (generatorPass = HEADER_PASS; |
| | | 25 | generatorPass <= SOURCE_PASS; |
| | | 26 | generatorPass++) { |
| | | 27 | pathname = createDirectoriesPathname(o, path); |
| | | 28 | //String pathname = path + filename; |
| | | 29 | // TODO: package, project basepath, tagged values to configure |
| | | 30 | File f = new File(pathname); |
| | | 31 | if (f.exists()) { |
| | | 32 | LOG.info("Generating (updated) " + f.getPath()); |
| | | 33 | sect.read(pathname); |
| | | 34 | File bakFile = new File(pathname + ".bak"); |
| | | 35 | if (bakFile.exists()) { |
| | | 36 | bakFile.delete(); |
| | | 37 | } |
| | | 38 | f.renameTo(bakFile); |
| | | 39 | } else { |
| | | 40 | LOG.info("Generating (new) " + f.getPath()); |
| | | 41 | } |
| | | 42 | } |
| | | 43 | } |
| | | 44 | |
| | | 45 | Set dependencies = null; |
| | | 46 | if (deps) dependencies = new TreeSet(); |
| | | 47 | /** |
| | | 48 | * 2002-11-28 Achim Spangler |
| | | 49 | * run basic generation function two times for header and implementation |
| | | 50 | */ |
| | | 51 | for (generatorPass = HEADER_PASS; |
| | | 52 | generatorPass <= SOURCE_PASS; |
| | | 53 | generatorPass++) { |
| | | 54 | pathname = createDirectoriesPathname(o, path); |
| | | 55 | String fileContent = generateFileAsString(o, pathname); |
| | | 56 | if (fileContent.length() == 0) continue; |
| | | 57 | BufferedWriter fos = null; |
| | | 58 | //String pathname = path + filename; |
| | | 59 | // TODO: package, project basepath, tagged values to configure |
| | | 60 | File f = new File(pathname); |
| | | 61 | try { |
| | | 62 | // TODO: This is using the default platform character encoding |
| | | 63 | // specifying an encoding will produce more predictable results |
| | | 64 | fos = new BufferedWriter (new FileWriter (f)); |
| | | 65 | writeTemplate(o, path, fos); |
| | | 66 | fos.write(fileContent); |
| | | 67 | fos.newLine(); |
| | | 68 | } |
| | | 69 | catch (IOException exp) { } |
| | | 70 | finally { |
| | | 71 | try { |
| | | 72 | if (fos != null) fos.close(); |
| | | 73 | } |
| | | 74 | catch (IOException exp) { |
| | | 75 | LOG.error("FAILED: " + f.getPath()); |
| | | 76 | } |
| | | 77 | } |
| | | 78 | |
| | | 79 | LOG.info("written: " + pathname); |
| | | 80 | |
| | | 81 | if (Section.getUseSect() != Section.SECT_NONE) { |
| | | 82 | // output lost sections only in the second path |
| | | 83 | // -> sections which are moved from header(inline) to source |
| | | 84 | // file are prevented to be outputted in header pass |
| | | 85 | File outFile = new File(pathname + ".out"); |
| | | 86 | if (outFile.exists()) { |
| | | 87 | outFile.delete(); // remove junk |
| | | 88 | } |
| | | 89 | if (generatorPass == HEADER_PASS) { |
| | | 90 | sect.write(pathname, indent, false); |
| | | 91 | } else { |
| | | 92 | sect.write(pathname, indent, true); |
| | | 93 | } |
| | | 94 | |
| | | 95 | if (outFile.exists()) { |
| | | 96 | assert f.exists(); |
| | | 97 | f.delete(); |
| | | 98 | outFile.renameTo(f); |
| | | 99 | LOG.info("added sections to: " + pathname); |
| | | 100 | } |
| | | 101 | } |
| | | 102 | LOG.info("----- end updating " + pathname + "-----"); |
| | | 103 | ret.add(pathname); |
| | | 104 | if (deps) { |
| | | 105 | dependencies.add(includeCls); |
| | | 106 | dependencies.add(predeclCls); |
| | | 107 | } |
| | | 108 | } |
| | | 109 | cleanupGenerator(); |
| | | 110 | // reset generator pass to NONE for the notation to be correct |
| | | 111 | generatorPass = NONE_PASS; |
| | | 112 | generatedFiles.add(o); |
| | | 113 | if (deps) { |
| | | 114 | Iterator it = dependencies.iterator(); |
| | | 115 | while (it.hasNext()) { |
| | | 116 | ret.add(generateFilesForElem(it.next(), path, deps)); |
| | | 117 | } |
| | | 118 | } |
| | | 119 | |
| | | 120 | return ret; |
| | | 121 | } |