1 16 17 package de.gulden.util.javasource; 18 19 import de.gulden.util.javasource.jjt.Node; 20 import de.gulden.util.javasource.jjt.*; 21 import javax.xml.parsers.*; 22 import org.w3c.dom.*; 23 import java.io.*; 24 import java.util.*; 25 26 32 public abstract class SourceObject implements Named, Serializable, ParserTreeConstants { 33 34 38 41 public static String nl = System.getProperty("line.separator"); 42 43 44 48 51 public Package myPackage; 52 53 56 protected String name; 57 58 59 63 66 public String getName() { 67 return name; 68 } 69 70 73 public void setName(String n) { 74 name=n; 75 } 76 77 80 public String getUnqualifiedName() { 81 return unqualify(getName()); 82 } 83 84 87 public Package getPackage() { 88 return myPackage; 89 } 90 91 97 public void initFromXML(Element element) throws IOException { 98 name=element.getAttribute("name"); 99 } 101 102 108 public Element buildXML(Document d) { 109 String tagName=getXMLName(); 111 Element e=d.createElement(tagName); 112 e.setAttribute("name",getName()); 113 return e; 114 } 115 116 121 public String getSignature() { 122 return getUnqualifiedName(); 124 } 125 126 133 public boolean equals(Object o) { 134 return o.getClass().equals(this.getClass()) 135 && ((SourceObject)o).getSignature().equals(this.getSignature()); 136 } 137 138 public String toString() { 139 return getXMLName()+" "+getSignature(); 140 } 141 142 145 protected String getXMLName() { 146 return SourceObjectDeclaredVisible.unqualify(this.getClass().getName()).toLowerCase(); } 148 149 154 void initFromAST(Node rootnode) { 155 name=rootnode.getName(); 157 } 159 160 161 165 171 static String unqualify(String n) { 172 int pos=n.lastIndexOf('.'); 173 if (pos!=-1) { 174 return n.substring(pos+1); 175 } 176 else { 177 return n; 178 } 179 } 180 181 187 static String unqualify(String n, int withParents) { 188 int pos=n.lastIndexOf('.'); 189 while ((pos > 0) && (withParents > 0)) { 190 pos = n.lastIndexOf('.', pos-1); 191 withParents--; 192 } 193 if (pos != -1) { 194 return n.substring(pos+1); 195 } else { 196 return n; 197 } 198 } 199 200 205 static void write(OutputStream out, String s) throws IOException { 206 out.write(s.getBytes()); 207 } 208 209 212 static void stringsIntoVector(Object [] s, Vector v) { 213 v.removeAllElements(); 214 for (int i=0;i<s.length;i++) { 215 v.addElement(s[i]); 216 } 217 } 218 219 } | Popular Tags |