1 19 20 package org.openide.src; 21 22 import java.io.*; 23 24 30 public final class InitializerElement extends Element implements Cloneable { 31 32 private ClassElement declaringClass; 33 34 static final long serialVersionUID =5768667690932077280L; 35 36 public InitializerElement() { 37 this(new InitializerElement.Memory(), null); 38 } 39 40 44 public InitializerElement(InitializerElement.Impl impl, ClassElement declaringClass) { 45 super(impl); 46 this.declaringClass = declaringClass; 47 } 48 49 50 InitializerElement.Impl getInitializerImpl() { 51 return (InitializerElement.Impl)impl; 52 } 53 54 57 public Object clone () { 58 return new InitializerElement (new Memory (this), null); 59 } 60 61 65 public void setStatic(boolean stat) throws SourceException { 66 getInitializerImpl().setStatic(stat); 67 } 68 69 72 public boolean isStatic() { 73 return getInitializerImpl().isStatic(); 74 } 75 76 80 public void setBody (String s) throws SourceException { 81 getInitializerImpl ().setBody (s); 82 } 83 84 87 public String getBody () { 88 return getInitializerImpl ().getBody (); 89 } 90 91 94 public JavaDoc getJavaDoc() { 95 return getInitializerImpl ().getJavaDoc (); 96 } 97 98 105 public final ClassElement getDeclaringClass () { 106 return declaringClass; 107 } 108 109 113 public void print(ElementPrinter printer) throws ElementPrinterInterruptException { 114 printer.markInitializer(this, printer.ELEMENT_BEGIN); 115 116 JavaDoc doc = getJavaDoc(); 117 if ((doc != null) && !doc.isEmpty()) { 118 printer.markInitializer(this, printer.JAVADOC_BEGIN); printJavaDoc(doc, printer); 120 printer.markInitializer(this, printer.JAVADOC_END); printer.println(""); } 123 124 if (isStatic()) { 125 printer.markInitializer(this, printer.HEADER_BEGIN); 126 printer.print("static "); printer.markInitializer(this, printer.HEADER_END); 128 } 129 printer.print("{"); printer.markInitializer(this, printer.BODY_BEGIN); 131 printer.print(getBody()); 132 printer.markInitializer(this, printer.BODY_END); 133 printer.print("}"); printer.markInitializer(this, printer.ELEMENT_END); 135 } 136 137 140 public interface Impl extends Element.Impl { 141 142 long serialVersionUID = -3742940543185945549L; 143 147 public void setStatic(boolean stat) throws SourceException; 148 149 152 public boolean isStatic(); 153 154 158 public void setBody (String s) throws SourceException; 159 160 163 public String getBody (); 164 165 168 public JavaDoc getJavaDoc (); 169 } 170 171 174 static class Memory extends Element.Memory implements InitializerElement.Impl { 175 176 private boolean stat; 177 178 private String body; 179 180 private JavaDoc javadoc; 181 182 static final long serialVersionUID =1956692952966906280L; 183 Memory() { 184 stat = false; 185 body = ""; javadoc = JavaDocSupport.createInitializerJavaDoc(null); 187 } 188 189 191 Memory(InitializerElement el) { 192 stat = el.isStatic (); 193 body = el.getBody (); 194 javadoc = el.getJavaDoc().isEmpty() ? JavaDocSupport.createJavaDoc(null) : 195 JavaDocSupport.createJavaDoc(el.getJavaDoc().getRawText()); 196 } 197 198 public void setStatic(boolean stat) { 199 boolean old = stat; 200 this.stat = stat; 201 firePropertyChange (PROP_STATIC, 202 old ? Boolean.TRUE : Boolean.FALSE, 203 stat ? Boolean.TRUE : Boolean.FALSE); 204 } 205 206 209 public boolean isStatic() { 210 return stat; 211 } 212 213 216 public void setBody (String s) throws SourceException { 217 String old = body; 218 body = s; 219 firePropertyChange (PROP_BODY, old, body); 220 } 221 222 225 public String getBody () { 226 return body; 227 } 228 229 232 public JavaDoc getJavaDoc () { 233 return javadoc; 234 } 235 236 238 public void markCurrent(boolean after) { 239 ClassElement decl = ((InitializerElement)element).getDeclaringClass(); 240 if (decl == null) { 241 throw new IllegalStateException (); 242 } 243 ((ClassElement.Memory)decl.getCookie(ClassElement.Memory.class)).markCurrent(element, after); 244 } 245 246 public Object readResolve() { 247 return new InitializerElement(this, null); 248 } 249 } 250 } 251 | Popular Tags |