1 33 34 package net.percederberg.grammatica.code.java; 35 36 import java.io.File ; 37 import java.io.PrintWriter ; 38 39 import net.percederberg.grammatica.code.CodeElement; 40 import net.percederberg.grammatica.code.CodeStyle; 41 42 48 public class JavaPackage extends CodeElement { 49 50 53 private JavaPackage basePackage; 54 55 58 private String name; 59 60 65 public JavaPackage(String name) { 66 this(null, name); 67 } 68 69 75 public JavaPackage(JavaPackage base, String name) { 76 this.basePackage = base; 77 this.name = name; 78 } 79 80 85 public String toString() { 86 if (basePackage == null) { 87 return name; 88 } else { 89 return basePackage.toString() + "." + name; 90 } 91 } 92 93 101 public int category() { 102 return 1; 103 } 104 105 112 public File toFile(File baseDir) { 113 String firstName; 114 String restName; 115 int pos; 116 117 if (basePackage != null) { 118 baseDir = basePackage.toFile(baseDir); 119 } 120 restName = this.name; 121 while ((pos = restName.indexOf('.')) > 0) { 122 firstName = restName.substring(0, pos); 123 restName = restName.substring(pos + 1); 124 baseDir = new File (baseDir, firstName); 125 } 126 return new File (baseDir, restName); 127 } 128 129 136 public void print(PrintWriter out, CodeStyle style, int indent) { 137 out.println("package " + toString() + ";"); 138 } 139 } 140 | Popular Tags |