1 19 20 package org.openide.src; 21 22 import org.openide.util.Task; 23 import org.openide.util.NbBundle; 24 25 35 public final class SourceElement extends Element { 36 38 public static final int STATUS_NOT = 0; 39 41 public static final int STATUS_ERROR = 1; 42 44 public static final int STATUS_PARTIAL = 2; 45 47 public static final int STATUS_OK = 3; 48 49 static final long serialVersionUID =-1439690719608070114L; 50 51 54 public SourceElement(Impl impl) { 55 super (impl); 56 } 57 58 60 final Impl getSourceImpl () { 61 return (Impl)impl; 62 } 63 64 68 public int getStatus () { 69 return getSourceImpl ().getStatus (); 70 } 71 72 81 public Task prepare () { 82 return getSourceImpl ().prepare (); 83 } 84 85 86 88 92 public void setPackage (Identifier id) throws SourceException { 93 getSourceImpl ().setPackage (id); 94 } 95 96 99 public Identifier getPackage () { 100 return getSourceImpl ().getPackage (); 101 } 102 103 105 109 public Import[] getImports() { 110 return getSourceImpl ().getImports (); 111 } 112 113 118 public void setImports(Import[] imprt) throws SourceException { 119 getSourceImpl ().changeImports (imprt, Impl.SET); 120 } 121 122 126 public void addImport (Import el) throws SourceException { 127 getSourceImpl ().changeImports ( 128 new Import[] { el }, Impl.ADD 129 ); 130 } 131 132 136 public void addImports (final Import[] els) throws SourceException { 137 getSourceImpl ().changeImports (els, Impl.ADD); 138 } 139 140 144 public void removeImport (Import el) throws SourceException { 145 getSourceImpl ().changeImports ( 146 new Import[] { el }, Impl.REMOVE 147 ); 148 } 149 150 154 public void removeImports (final Import[] els) throws SourceException { 155 getSourceImpl ().changeImports (els, Impl.REMOVE); 156 } 157 158 160 164 public void addClass (ClassElement el) throws SourceException { 165 Identifier id = Identifier.create(el.getName().getName()); 166 if (getClass(id) != null) 167 throwAddException("FMT_EXC_AddClassToSource", el); getSourceImpl ().changeClasses (new ClassElement[] { el }, Impl.ADD); 169 } 170 171 175 public void addClasses (final ClassElement[] els) throws SourceException { 176 Identifier id; 177 178 for (int i = 0; i < els.length; i++) { 179 id = Identifier.create(els[i].getName().getName()); 180 if (getClass(id) != null) 181 throwAddException("FMT_EXC_AddClassToSource", els[i]); } 183 getSourceImpl ().changeClasses (els, Impl.ADD); 184 } 185 186 192 private void throwAddException(String formatKey, ClassElement element) throws SourceException { 193 String msg = NbBundle.getMessage(ElementFormat.class, formatKey, 194 element.getName().getName()); 195 throwSourceException(msg); 196 } 197 198 202 public void removeClass (ClassElement el) throws SourceException { 203 getSourceImpl ().changeClasses (new ClassElement[] { el }, Impl.REMOVE); 204 } 205 206 210 public void removeClasses (final ClassElement[] els) throws SourceException { 211 getSourceImpl ().changeClasses (els, Impl.REMOVE); 212 } 213 214 219 public void setClasses (ClassElement[] els) throws SourceException { 220 getSourceImpl ().changeClasses (els, Impl.SET); 221 } 222 223 226 public ClassElement[] getClasses () { 227 return getSourceImpl ().getClasses (); 228 } 229 230 234 public ClassElement getClass (Identifier name) { 235 return getSourceImpl ().getClass (name); 236 } 237 238 241 public ClassElement[] getAllClasses () { 242 return getSourceImpl ().getAllClasses (); 243 } 244 245 249 public void print(ElementPrinter printer) throws ElementPrinterInterruptException { 250 Identifier pack = getPackage(); 251 if (pack != null) { 252 printer.print("package "); printer.print(pack.getFullName()); 254 printer.println(";"); printer.println(""); } 257 258 Import[] imp = getImports(); 259 for(int i = 0; i < imp.length; i++) { 260 printer.print(imp[i].toString()); 261 printer.println(";"); } 263 if (imp.length > 0) 264 printer.println(""); 266 print(getClasses(), printer); 267 } 268 269 274 public void runAtomic (Runnable run) { 275 getSourceImpl ().runAtomic(run); 276 } 277 278 286 public void runAtomicAsUser (Runnable run) throws SourceException { 287 getSourceImpl ().runAtomicAsUser(run); 288 } 289 290 293 public static interface Impl extends Element.Impl { 294 295 public static final int ADD = ClassElement.Impl.ADD; 296 297 public static final int REMOVE = ClassElement.Impl.REMOVE; 298 299 public static final int SET = ClassElement.Impl.SET; 300 301 302 long serialVersionUID = -2181228658756563166L; 303 304 308 public int getStatus (); 309 310 311 320 public Task prepare (); 321 322 326 public void setPackage (Identifier id) throws SourceException; 327 328 331 public Identifier getPackage (); 332 333 335 339 public Import[] getImports(); 340 341 342 347 public void changeImports (Import[] elems, int action) throws SourceException; 348 349 350 355 public void changeClasses (ClassElement[] elems, int action) throws SourceException; 356 357 360 public ClassElement[] getClasses (); 361 362 366 public ClassElement getClass (Identifier name); 367 368 371 public ClassElement[] getAllClasses (); 372 373 378 public void runAtomic (Runnable run); 379 380 388 public void runAtomicAsUser (Runnable run) throws SourceException; 389 } 390 391 } 392 | Popular Tags |