1 20 21 package org.jacorb.idl; 22 23 29 30 import java.io.File ; 31 import java.io.IOException ; 32 import java.io.PrintWriter ; 33 34 37 38 public class Module 39 extends Declaration 40 implements Scope 41 { 42 public Definitions spec; 43 44 private ScopeData scopeData; 45 private String unreplacedName = null; 46 47 public Module(int num) 48 { 49 super(num); 50 pack_name = ""; 51 } 52 53 public void setScopeData(ScopeData data) 54 { 55 scopeData = data; 56 } 57 58 public ScopeData getScopeData() 59 { 60 return scopeData; 61 } 62 63 public void setPackage(String s) 64 { 65 if (unreplacedName == null) 66 unreplacedName = s; 67 s = parser.pack_replace(s); 68 69 if (pack_name.length() > 0) 70 { 71 pack_name = s + "." + pack_name; 72 spec.setPackage(s); 73 } 74 else 75 { 76 pack_name = s; 77 78 if (lexer.needsJavaEscape(this)) 79 pack_name = "_" + s; 80 81 name = pack_name; 82 spec.setPackage(pack_name); 83 } 84 } 85 86 String full_name() 87 { 88 return pack_name; 89 } 90 91 public void set_included(boolean i) 92 { 93 included = i; 94 spec.set_included(i); 95 } 96 97 public void setEnclosingSymbol(IdlSymbol s) 98 { 99 if (enclosing_symbol != null && enclosing_symbol != s) 100 throw new RuntimeException ("Compiler Error: trying to reassign container for " + name); 101 enclosing_symbol = s; 102 spec.setEnclosingSymbol(this); 103 } 104 105 public void parse() 106 { 107 try 108 { 109 NameTable.define(full_name(), "module"); 110 } 111 catch (NameAlreadyDefined nad) 112 { 113 parser.error("Module name " + full_name() + " already defined", token); 114 } 115 spec.parse(); 116 } 117 118 public void print(PrintWriter ps) 119 { 120 if (parser.generateIR) 121 { 122 try 123 { 124 126 String path = 127 parser.out_dir + fileSeparator + pack_name.replace('.', fileSeparator); 128 File dir = new File (path); 129 if (!dir.exists()) 130 { 131 if (!dir.mkdirs()) 132 { 133 org.jacorb.idl.parser.fatal_error("Unable to create " + path, null); 134 } 135 } 136 137 File f = new File (dir, "_" + name + "Module.java"); 138 if (GlobalInputStream.isMoreRecentThan(f)) 139 { 140 141 PrintWriter moduleWriter = new PrintWriter (new java.io.FileWriter (f )); 142 moduleWriter.println("package " + pack_name + ";\n"); 143 moduleWriter.println("/** \n * IR module information, generated by the JacORB IDL compiler \n */"); 144 moduleWriter.println("public class _" + name + "Module {}"); 145 moduleWriter.close(); 146 } 147 } 148 catch (IOException io) 149 { 150 if (logger.isWarnEnabled()) 151 logger.warn("Exception: ", io); 152 } 153 } 154 spec.print(ps); 155 } 156 157 162 163 public String originalModuleName() 164 { 165 return unreplacedName; 166 } 167 168 public Definitions getDefinitions() 169 { 170 return spec; 171 } 172 173 175 176 public void accept(IDLTreeVisitor visitor) 177 { 178 visitor.visitModule(this); 179 } 180 181 182 } 183 | Popular Tags |