1 19 20 package org.netbeans.modules.javacore.jmiimpl.javamodel; 21 22 import java.lang.reflect.Modifier ; 23 import java.util.*; 24 import javax.jmi.reflect.*; 25 import javax.jmi.model.MofClass; 26 import javax.jmi.model.Attribute; 27 import javax.jmi.model.GeneralizableElement; 28 import javax.jmi.model.NameNotFoundException; 29 import org.netbeans.jmi.javamodel.*; 30 31 34 public class ArrayLengthField implements Field { 35 36 private static final String typeName = "int"; private static final String MOF_ID_PREFIX = "ArrayLengthField:"; 39 private ArrayImpl parent; 40 private String mofId; 41 42 private Type type; 43 private MultipartId typeRef; 44 45 ArrayLengthField(ArrayImpl parent) { 46 this.parent = parent; 47 mofId = MOF_ID_PREFIX + parent.refMofId(); 48 type = ((JavaModelPackage) parent.refImmediatePackage()).getType().resolve(typeName); 49 typeRef = new SyntheticMultipartId(this); 50 } 51 52 public List getAnnotations() { 53 return Collections.EMPTY_LIST; 54 } 55 56 public ClassDefinition getDeclaringClass() { 57 return parent; 58 } 59 60 public int getDimCount() { 61 return 0; 62 } 63 64 public int getEndOffset() { 65 return 0; 66 } 67 68 public boolean isDeprecated() { 69 return false; 70 } 71 72 public InitialValue getInitialValue() { 73 return null; 74 } 75 76 public String getInitialValueText() { 77 return null; 78 } 79 80 public JavaDoc getJavadoc() { 81 return null; 82 } 83 84 public String getJavadocText() { 85 return null; 86 } 87 88 public int getModifiers() { 89 return Modifier.PUBLIC | Modifier.FINAL; 90 } 91 92 public String getName() { 93 return "length"; } 95 96 public int getPartEndOffset(ElementPartKind part) { 97 return 0; 98 } 99 100 public int getPartStartOffset(ElementPartKind part) { 101 return 0; 102 } 103 104 public Resource getResource() { 105 return parent.getResource(); 106 } 107 108 public int getStartOffset() { 109 return 0; 110 } 111 112 public Type getType() { 113 return type; 114 } 115 116 public TypeReference getTypeName() { 117 return typeRef; 118 } 119 120 public List getChildren() { 121 return Collections.EMPTY_LIST; 122 } 123 124 public boolean isValid() { 125 return true; 126 } 127 128 public Collection getReferences() { 129 return Collections.EMPTY_LIST; } 131 132 public boolean isFinal() { 133 return true; 134 } 135 136 public RefClass refClass() { 137 return ((JavaModelPackage) parent.refImmediatePackage()).getField(); 138 } 139 140 public void refDelete() { 141 } 143 144 public Object refGetValue(RefObject refObject) { 145 if (!(refObject instanceof Attribute)) { 146 throw new InvalidCallException(null, refObject); 147 } 148 return refGetValue(((Attribute) refObject).getName()); 149 } 150 151 public Object refGetValue(String str) { 152 if ("dimCount".equals(str)) { return new Integer (getDimCount()); 154 } else if ("final".equals(str)) { return isFinal() ? Boolean.TRUE : Boolean.FALSE; 156 } else if ("initialValue".equals(str)) { return getInitialValue(); 158 } else if ("initialValueText".equals(str)) { return getInitialValueText(); 160 } else if ("javadoc".equals(str)) { return getJavadoc(); 162 } else if ("javadocText".equals(str)) { return getJavadocText(); 164 } else if ("modifiers".equals(str)) { return new Integer (getModifiers()); 166 } else if ("name".equals(str)) { return getName(); 168 } else if ("type".equals(str)) { return getType(); 170 } else if ("typeName".equals(str)) { return getTypeName(); 172 } 173 throw new InvalidCallException(null, null, "Invalid attribute name: " + str); } 175 176 public RefFeatured refImmediateComposite() { 177 return parent; 178 } 179 180 public RefPackage refImmediatePackage() { 181 return parent.refImmediatePackage(); 182 } 183 184 public Object refInvokeOperation(RefObject refObject, List list) throws RefException { 185 throw new InvalidCallException(null, null); 186 } 187 188 public Object refInvokeOperation(String str, List list) throws RefException { 189 throw new InvalidCallException(null, null); 190 } 191 192 public boolean refIsInstanceOf(RefObject objType, boolean considerSubtypes) { 193 GeneralizableElement metaObject = (GeneralizableElement) refMetaObject(); 194 return isInstanceOf(metaObject, objType, considerSubtypes); 195 } 196 197 private boolean isInstanceOf(GeneralizableElement metaObject, RefObject objType, boolean considerSubtypes) { 198 if (metaObject.equals(objType)) 199 return true; 200 if (considerSubtypes) { 201 Iterator it = metaObject.getSupertypes().iterator(); 202 while (it.hasNext()) { 203 if (isInstanceOf(((GeneralizableElement) it.next()), objType, true)) { 204 return true; 205 } 206 } 207 } 208 return false; 209 } 210 211 public RefObject refMetaObject() { 212 return refClass().refMetaObject(); 213 } 214 215 public String refMofId() { 216 return mofId; 217 } 218 219 public RefFeatured refOutermostComposite() { 220 return parent.refOutermostComposite(); 221 } 222 223 public RefPackage refOutermostPackage() { 224 return parent.refOutermostPackage(); 225 } 226 227 public void refSetValue(String str, Object obj) { 228 ArrayImpl.throwIsReadOnly(this); 229 } 230 231 public void refSetValue(RefObject refObject, Object obj) { 232 ArrayImpl.throwIsReadOnly(this); 233 } 234 235 public Collection refVerifyConstraints(boolean param) { 236 return Collections.EMPTY_LIST; 237 } 238 239 public void replaceChild(Element oldChild, Element newChild) { 240 ArrayImpl.throwIsReadOnly(this); 241 } 242 243 public void setDimCount(int newValue) { 244 ArrayImpl.throwIsReadOnly(this, "dimCount"); } 246 247 public void setFinal(boolean newValue) { 248 ArrayImpl.throwIsReadOnly(this, "final"); } 250 251 public void setInitialValue(InitialValue newValue) { 252 ArrayImpl.throwIsReadOnly(this, "initialValue"); } 254 255 public void setInitialValueText(String newValue) { 256 ArrayImpl.throwIsReadOnly(this, "initialValueText"); } 258 259 public void setJavadoc(JavaDoc newValue) { 260 ArrayImpl.throwIsReadOnly(this, "javadoc"); } 262 263 public void setJavadocText(String newValue) { 264 ArrayImpl.throwIsReadOnly(this, "javadocText"); } 266 267 public void setModifiers(int newValue) { 268 ArrayImpl.throwIsReadOnly(this, "modifiers"); } 270 271 public void setName(String newValue) { 272 ArrayImpl.throwIsReadOnly(this, "name"); } 274 275 public void setType(Type newValue) { 276 ArrayImpl.throwIsReadOnly(this, "type"); } 278 279 public void setTypeName(TypeReference newValue) { 280 ArrayImpl.throwIsReadOnly(this, "typeName"); } 282 283 public Element duplicate() { 284 throw new UnsupportedOperationException (); 285 } 286 287 public void setDeprecated(boolean newValue) { 288 ArrayImpl.throwIsReadOnly(this, "typeName"); } 290 } 291 | Popular Tags |