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 de.gulden.util.xml.XMLToolbox; 22 import javax.xml.parsers.*; 23 import org.w3c.dom.*; 24 import java.io.*; 25 import java.util.*; 26 27 33 public abstract class SourceObjectDeclared extends SourceObject { 34 35 39 41 public Class declaringClass; 42 43 45 public Documentation myDocumentation; 46 47 50 protected int modifier = 0; 51 52 55 protected String source; 56 57 60 protected int[] sourcePosition; 61 62 63 67 70 public int getModifier() { 71 return modifier; 72 } 73 74 77 public String getModifierString() { 78 return java.lang.reflect.Modifier.toString(getModifier()); 79 } 80 81 84 public void setModifier(int m) { 85 modifier=m; 86 } 87 88 91 public Class getDeclaringClass() { 92 return declaringClass; 93 } 94 95 98 public void setDeclaringClass(Class c) { 99 declaringClass=c; 100 } 101 102 105 public Documentation getDocumentation() { 106 return myDocumentation; 107 } 108 109 112 public void setDocumentation(Documentation d) { 113 myDocumentation=d; 114 } 115 116 122 public void initFromXML(Element element) throws IOException { 123 super.initFromXML(element); 125 126 this.modifier=0; 128 if (XMLToolbox.isYesAttribute(element,"final")) { 129 this.modifier|=java.lang.reflect.Modifier.FINAL; 130 } 131 132 Element doc=XMLToolbox.getChild(element,"documentation"); 134 if (doc!=null) { 135 DocumentationDeclared d=new DocumentationDeclared(); 136 d.initFromXML(doc); 137 myDocumentation=d; 138 } 139 else { 140 myDocumentation=null; 141 } 142 143 if (this instanceof Typed) { 144 Typed typed=(Typed)this; 145 Type t=null; 146 if (this instanceof Member) { 147 t=new Type((Member)this); 148 } 149 else if (this instanceof Parameter) { 150 t=new Type(((Parameter)this).myMemberExecutable); 151 } 152 else if (this instanceof Exception ) { 153 t=new Type(((Exception )this).myMemberExecutable); 154 } 155 t.initFromXML(XMLToolbox.getChildRequired(element,"type")); 156 typed.setType(t); 157 } 158 } 159 160 166 public Element buildXML(Document d) { 167 Element e=super.buildXML(d); 168 169 if (java.lang.reflect.Modifier.isFinal(modifier)) { 170 e.setAttribute("final","yes"); 171 } 172 if (java.lang.reflect.Modifier.isStrict(modifier)) { 173 e.setAttribute("strictfp","yes"); 174 } 175 176 Documentation doc=getDocumentation(); 178 if (doc!=null) { 179 e.appendChild(doc.buildXML(d)); 180 } 181 182 return e; 183 } 184 185 190 public String getSignature() { 191 String type; 192 if (this instanceof Typed) { 193 Typed tt=(Typed)this; 194 Type t=tt.getType(); 195 type=t.getFullTypeName()+" "; 196 } 197 else { 198 type=""; 199 } 200 return type+super.getSignature(); 201 } 202 203 206 public String getSource() { 207 return source; 208 } 209 210 213 public void setSource(String source) { 214 this.source=source; 215 } 216 217 220 public int[] getSourcePosition() { 221 return sourcePosition; 222 } 223 224 227 public String getSourcePositionString() { 228 return "["+getSourcePosition()[0]+":"+getSourcePosition()[1]+"]"; 229 } 230 231 public String toString() { 232 if (getSource()!=null) { 233 return super.toString()+" "+getSource()+" "+getSourcePositionString(); 234 } 235 else { 236 return super.toString(); 237 } 238 } 239 240 245 void initFromAST(Node rootnode) { 246 super.initFromAST(rootnode); 247 248 source=rootnode.getSource(); 249 sourcePosition=rootnode.getSourcePosition(); 250 251 this.modifier=0; 253 Node mod=rootnode.getChild(JJT_MODIFIER); 254 if (mod!=null) { 255 if (mod.hasChild(JJT_FINAL)) { 256 this.modifier|=java.lang.reflect.Modifier.FINAL; 257 } 258 if (mod.hasChild(JJT_STRICTFP)) { 259 this.modifier|=java.lang.reflect.Modifier.STRICT; 260 } 261 } 262 263 Token t=rootnode.getStartToken(); 265 t=t.specialToken; 266 if (t!=null) { 267 String doc=t.image; 268 if (doc.startsWith("/**")) { 270 DocumentationDeclared d=new DocumentationDeclared(); 271 d.setSourceObjectDeclared(this); 272 doc = doc.replace('\r', ' '); d.setRaw(doc); 274 myDocumentation=d; 275 } 276 else { 277 myDocumentation=null; 278 } 279 } 280 else { 281 myDocumentation=null; 282 } 283 } 284 285 } | Popular Tags |