1 33 34 package net.percederberg.grammatica.code.java; 35 36 import java.io.PrintWriter ; 37 38 import net.percederberg.grammatica.code.CodeElement; 39 import net.percederberg.grammatica.code.CodeStyle; 40 41 47 public class JavaImport extends CodeElement { 48 49 52 private String packageName; 53 54 57 private String className; 58 59 65 public JavaImport(JavaPackage pkg) { 66 this(pkg.toString()); 67 } 68 69 75 public JavaImport(String packageName) { 76 this(packageName, ""); 77 } 78 79 86 public JavaImport(JavaPackage pkg, JavaClass cls) { 87 this(pkg.toString(), cls.toString()); 88 } 89 90 97 public JavaImport(String packageName, String className) { 98 this.packageName = packageName; 99 this.className = className; 100 } 101 102 113 public int compareTo(Object obj) { 114 int value = super.compareTo(obj); 115 116 if (value == 0) { 117 return toString().compareTo(obj.toString()); 118 } else { 119 return value; 120 } 121 } 122 123 131 public boolean equals(Object obj) { 132 return compareTo(obj) == 0; 133 } 134 135 140 public String toString() { 141 if (className.equals("")) { 142 return packageName + ".*"; 143 } else { 144 return packageName + "." + className; 145 } 146 } 147 148 156 public int category() { 157 return packageName.startsWith("java") ? 2 : 3; 158 } 159 160 167 public void print(PrintWriter out, CodeStyle style, int indent) { 168 out.println("import " + toString() + ";"); 169 } 170 } 171 | Popular Tags |