1 19 20 package org.openide.src; 21 22 import java.io.*; 23 import java.lang.reflect.Modifier ; 24 25 import org.openide.util.NbBundle; 26 27 31 public final class FieldElement extends MemberElement { 32 33 private static final ElementFormat FIELD_FORMAT = 34 new ElementFormat("{m,,\" \"}{t} {n}"); 36 static final long serialVersionUID =2195820119328567201L; 37 38 40 public FieldElement() { 41 this(new Memory(), null); 42 } 43 44 48 public FieldElement(FieldElement.Impl impl, ClassElement declaringClass) { 49 super(impl, declaringClass); 50 } 51 52 56 public Object clone () { 57 return new FieldElement (new Memory (this), null); 58 } 59 60 final FieldElement.Impl getFieldImpl() { 61 return (FieldElement.Impl) impl; 62 } 63 64 67 public Type getType() { 68 return getFieldImpl().getType(); 69 } 70 71 75 public void setType(Type type) throws SourceException { 76 if (type == null) { 78 throwSourceException(NbBundle.getMessage(FieldElement.class, "ERR_NullType")); 79 } else if (type.equals(Type.VOID)) { 80 throwSourceException(NbBundle.getMessage(FieldElement.class, "ERR_FieldTypeVoid")); 81 } 82 getFieldImpl().setType(type); 83 } 84 85 88 public String getInitValue() { 89 return getFieldImpl().getInitValue(); 90 } 91 92 96 public void setInitValue(String value) throws SourceException { 97 getFieldImpl().setInitValue(value); 98 } 99 100 102 public int getModifiersMask() { 103 if (isDeclaredInInterface()) { 104 return Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL; 105 } 106 else { 107 return Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | 108 Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT | 109 Modifier.VOLATILE; 110 } 111 } 112 113 117 public final void setName(Identifier name) throws SourceException { 118 ClassElement c = getDeclaringClass(); 119 if (c != null) { 120 FieldElement f = c.getField(name); 121 if ((f != null) && (f != this)) { 122 String msg = NbBundle.getMessage(ElementFormat.class, 123 "FMT_EXC_RenameField", c.getName().getName(), name ); throwSourceException(msg); 125 } 126 } 127 super.setName(name); 128 } 129 130 133 public JavaDoc.Field getJavaDoc () { 134 return getFieldImpl ().getJavaDoc (); 135 } 136 137 141 public void print(ElementPrinter printer) throws ElementPrinterInterruptException { 142 printer.markField(this, printer.ELEMENT_BEGIN); 143 144 JavaDoc doc = getJavaDoc(); 145 if ((doc != null) && !doc.isEmpty()) { 146 printer.markField(this, printer.JAVADOC_BEGIN); printJavaDoc(doc, printer); 148 printer.markField(this, printer.JAVADOC_END); printer.println(""); } 151 152 printer.markField(this, printer.HEADER_BEGIN); 153 printer.print(FIELD_FORMAT.format(this)); 154 printer.markField(this, printer.HEADER_END); 155 156 String init = getInitValue(); 157 if (init.length() > 0) { 158 printer.print(" = "); printer.markField(this, printer.BODY_BEGIN); 160 printer.print(init); 161 printer.markField(this, printer.BODY_END); 162 } 163 164 printer.print(";"); 166 printer.markField(this, printer.ELEMENT_END); 167 } 168 169 172 public interface Impl extends MemberElement.Impl { 173 174 long serialVersionUID = -1612065404733395830L; 175 178 public Type getType(); 179 180 184 public void setType(Type type) throws SourceException; 185 186 189 public String getInitValue(); 190 191 195 public void setInitValue(String value) throws SourceException; 196 197 200 public JavaDoc.Field getJavaDoc (); 201 } 202 203 static class Memory extends MemberElement.Memory implements Impl { 204 205 private Type type; 206 207 208 private String initValue; 209 210 211 private JavaDoc.Field javaDoc; 212 213 static final long serialVersionUID =1407258001185361107L; 214 Memory() { 215 type = Type.VOID; 216 initValue = ""; javaDoc = JavaDocSupport.createFieldJavaDoc( null ); 218 } 219 220 224 Memory (FieldElement field) { 225 super (field); 226 type = field.getType (); 227 initValue = field.getInitValue (); 228 javaDoc = field.getJavaDoc().isEmpty() ? 229 JavaDocSupport.createFieldJavaDoc( null ) : 230 JavaDocSupport.createFieldJavaDoc( field.getJavaDoc().getRawText() ); 231 } 232 233 236 public Type getType() { 237 return type; 238 } 239 240 243 public void setType(Type type) { 244 Type old = this.type; 245 this.type = type; 246 firePropertyChange (PROP_TYPE, old, type); 247 } 248 249 252 public String getInitValue() { 253 return initValue; 254 } 255 256 259 public void setInitValue(String value) { 260 String old = initValue; 261 initValue = value; 262 firePropertyChange (PROP_INIT_VALUE, old, value); 263 } 264 265 267 public JavaDoc.Field getJavaDoc () { 268 return javaDoc; 269 } 270 271 public Object readResolve() { 272 return new FieldElement(this, null); 273 } 274 } 275 } 276 | Popular Tags |