1 19 20 package org.openide.src; 21 22 import java.io.*; 23 import java.lang.reflect.Modifier ; 24 import java.util.Arrays ; 25 26 30 public class ConstructorElement extends MemberElement { 31 32 private static final ElementFormat HEADER_FORMAT = 33 new ElementFormat("{m,,\" \"}{n}({a}){e,\" throws \",}"); 35 static final long serialVersionUID =4794977239847390179L; 36 37 public ConstructorElement() { 38 this(new Memory(), null); 39 } 40 41 45 public ConstructorElement(ConstructorElement.Impl impl, ClassElement clazz) { 46 super(impl, clazz); 47 } 48 49 53 public Object clone () { 54 return new ConstructorElement (new Memory (this), null); 55 } 56 57 final ConstructorElement.Impl getConstructorImpl() { 58 return (ConstructorElement.Impl)impl; 59 } 60 61 65 public int getModifiersMask() { 66 return Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE; 67 } 68 69 72 public final MethodParameter[] getParameters() { 73 return getConstructorImpl().getParameters(); 74 } 75 76 80 public final void setParameters(MethodParameter[] params) throws SourceException { 81 getConstructorImpl().setParameters(params); 82 } 83 84 87 public final Identifier[] getExceptions() { 88 return getConstructorImpl().getExceptions(); 89 } 90 91 95 public final void setExceptions(Identifier[] exceptions) throws SourceException { 96 getConstructorImpl().setExceptions(exceptions); 97 } 98 99 104 public final void setBody (String s) throws SourceException { 105 getConstructorImpl ().setBody (s); 106 } 107 108 115 public final String getBody () { 116 return getConstructorImpl ().getBody (); 117 } 118 119 122 public final JavaDoc.Method getJavaDoc () { 123 return getConstructorImpl ().getJavaDoc (); 124 } 125 126 130 public void print(ElementPrinter printer) throws ElementPrinterInterruptException { 131 printerMark(printer, printer.ELEMENT_BEGIN); 132 133 JavaDoc doc = getJavaDoc(); 134 if ((doc != null) && !doc.isEmpty()) { 135 printerMark(printer, printer.JAVADOC_BEGIN); printJavaDoc(doc, printer); 137 printerMark(printer, printer.JAVADOC_END); printer.println(""); } 140 141 printerMark(printer, printer.HEADER_BEGIN); printer.print(getFormat().format(this)); 143 printerMark(printer, printer.HEADER_END); 145 String body = getBody(); 146 ClassElement declClass = getDeclaringClass(); 147 148 if (((declClass != null) && declClass.isInterface()) || (Modifier.isAbstract(getModifiers())) || (body == null)) { printer.print(";"); } 153 else { 154 printer.print(" {"); printerMark(printer, printer.BODY_BEGIN); printer.print(body); 157 printerMark(printer, printer.BODY_END); printer.print("}"); } 160 161 printerMark(printer, printer.ELEMENT_END); 162 } 163 164 169 void printerMark(ElementPrinter printer, int what) throws ElementPrinterInterruptException { 170 printer.markConstructor(this, what); 171 } 172 173 176 ElementFormat getFormat() { 177 return HEADER_FORMAT; 178 } 179 180 183 public interface Impl extends MemberElement.Impl { 184 185 long serialVersionUID = -8757076629808175158L; 186 189 public MethodParameter[] getParameters(); 190 191 195 public void setParameters(MethodParameter[] params) throws SourceException; 196 197 200 public Identifier[] getExceptions(); 201 202 206 public void setExceptions(Identifier[] exceptions) throws SourceException; 207 208 213 public void setBody (String s) throws SourceException; 214 215 219 public String getBody (); 220 221 224 public JavaDoc.Method getJavaDoc (); 225 } 226 227 231 public static class Key extends Object { 232 233 private Type[] params; 234 235 238 public Key (final Type[] params) { 239 this.params = params; 240 } 241 242 246 public Key (final ConstructorElement ce) { 247 MethodParameter[] mp = ce.getParameters(); 248 params = new Type[mp.length]; 249 for (int i = 0; i < mp.length; i++) { 250 params[i] = mp[i].getType(); 251 } 252 } 253 254 255 public boolean equals (Object obj) { 256 if (!(obj instanceof Key)) return false; 257 return Arrays.equals(params, ((Key)obj).params); 258 } 259 260 264 public int hashCode () { 265 if (params == null) return 0; 266 int length = params.length; 267 if (length == 0) return 0; 268 if (length == 1) return params[0].getFullString().hashCode(); 269 return params[0].getFullString().hashCode() ^ 270 params[length - 1].getFullString().hashCode(); 271 } 272 273 } 275 static class Memory extends MemberElement.Memory implements Impl { 276 277 private MethodParameter[] parameters; 278 279 280 private Identifier[] exceptions; 281 282 283 private String body; 284 285 286 private JavaDoc.Method javaDoc; 287 288 static final long serialVersionUID =-4826478874004410760L; 289 Memory() { 290 exceptions = new Identifier[0]; 291 parameters = new MethodParameter[0]; 292 body = ""; javaDoc = JavaDocSupport.createMethodJavaDoc( null ); 294 } 295 296 297 Memory (ConstructorElement el) { 298 super (el); 299 exceptions = el.getExceptions (); 300 parameters = el.getParameters (); 301 body = el.getBody (); 302 javaDoc = el.getJavaDoc().isEmpty() ? 303 JavaDocSupport.createMethodJavaDoc( null ) : 304 JavaDocSupport.createMethodJavaDoc( el.getJavaDoc().getRawText() ); 305 } 306 307 309 public MethodParameter[] getParameters() { 310 return parameters; 311 } 312 313 315 public void setParameters(MethodParameter[] params) { 316 MethodParameter[] m = parameters; 317 parameters = params; 318 firePropertyChange (PROP_PARAMETERS, m, params); 319 } 320 321 323 public Identifier[] getExceptions() { 324 return exceptions; 325 } 326 327 329 public void setExceptions(Identifier[] exceptions) { 330 Identifier[] old = this.exceptions; 331 this.exceptions = exceptions; 332 firePropertyChange (PROP_EXCEPTIONS, old, exceptions); 333 } 334 335 338 public void setBody (String s) throws SourceException { 339 String old = body; 340 body = s; 341 firePropertyChange (PROP_BODY, old, body); 342 } 343 344 347 public String getBody () { 348 return body; 349 } 350 351 354 public JavaDoc.Method getJavaDoc () { 355 return javaDoc; 356 } 357 358 public Object readResolve() { 359 return new ConstructorElement(this, null); 360 } 361 } 362 } 363 | Popular Tags |