1 11 package org.eclipse.jdt.internal.core; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.jdt.core.Flags; 15 import org.eclipse.jdt.core.IField; 16 import org.eclipse.jdt.core.IJavaModelStatusConstants; 17 import org.eclipse.jdt.core.JavaModelException; 18 import org.eclipse.jdt.core.Signature; 19 import org.eclipse.jdt.internal.compiler.env.IBinaryField; 20 import org.eclipse.jdt.internal.compiler.lookup.Binding; 21 22 25 26 class BinaryField extends BinaryMember implements IField { 27 28 31 protected BinaryField(JavaElement parent, String name) { 32 super(parent, name); 33 } 34 public boolean equals(Object o) { 35 if (!(o instanceof BinaryField)) return false; 36 return super.equals(o); 37 } 38 41 public Object getConstant() throws JavaModelException { 42 IBinaryField info = (IBinaryField) getElementInfo(); 43 return convertConstant(info.getConstant()); 44 } 45 48 public int getFlags() throws JavaModelException { 49 IBinaryField info = (IBinaryField) getElementInfo(); 50 return info.getModifiers(); 51 } 52 55 public int getElementType() { 56 return FIELD; 57 } 58 61 protected char getHandleMementoDelimiter() { 62 return JavaElement.JEM_FIELD; 63 } 64 public String getKey(boolean forceOpen) throws JavaModelException { 65 return getKey(this, forceOpen); 66 } 67 70 public String getTypeSignature() throws JavaModelException { 71 IBinaryField info = (IBinaryField) getElementInfo(); 72 return new String (ClassFile.translatedName(info.getTypeName())); 73 } 74 public boolean isEnumConstant() throws JavaModelException { 77 return Flags.isEnum(getFlags()); 78 } 79 82 public boolean isResolved() { 83 return false; 84 } 85 public JavaElement resolved(Binding binding) { 86 SourceRefElement resolvedHandle = new ResolvedBinaryField(this.parent, this.name, new String (binding.computeUniqueKey())); 87 resolvedHandle.occurrenceCount = this.occurrenceCount; 88 return resolvedHandle; 89 } 90 93 protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo) { 94 buffer.append(this.tabString(tab)); 95 if (info == null) { 96 toStringName(buffer); 97 buffer.append(" (not open)"); } else if (info == NO_INFO) { 99 toStringName(buffer); 100 } else { 101 try { 102 buffer.append(Signature.toString(this.getTypeSignature())); 103 buffer.append(" "); toStringName(buffer); 105 } catch (JavaModelException e) { 106 buffer.append("<JavaModelException in toString of " + getElementName()); } 108 } 109 } 110 public String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException { 111 String contents = ((BinaryType) this.getDeclaringType()).getJavadocContents(monitor); 112 if (contents == null) return null; 113 int indexAnchor = contents.indexOf( 114 JavadocConstants.ANCHOR_PREFIX_START + this.getElementName() + JavadocConstants.ANCHOR_PREFIX_END); 115 if (indexAnchor == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNKNOWN_JAVADOC_FORMAT, this)); 116 int indexOfEndLink = contents.indexOf(JavadocConstants.ANCHOR_SUFFIX, indexAnchor); 117 if (indexOfEndLink == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNKNOWN_JAVADOC_FORMAT, this)); 118 int indexOfNextField = contents.indexOf(JavadocConstants.ANCHOR_PREFIX_START, indexOfEndLink); 119 int indexOfBottom = contents.indexOf(JavadocConstants.CONSTRUCTOR_DETAIL, indexOfEndLink); 120 if (indexOfBottom == -1) { 121 indexOfBottom = contents.indexOf(JavadocConstants.METHOD_DETAIL, indexOfEndLink); 122 if (indexOfBottom == -1) { 123 indexOfBottom = contents.indexOf(JavadocConstants.END_OF_CLASS_DATA, indexOfEndLink); 124 } 125 } 126 indexOfNextField= Math.min(indexOfNextField, indexOfBottom); 127 if (indexOfNextField == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNKNOWN_JAVADOC_FORMAT, this)); 128 return contents.substring(indexOfEndLink + JavadocConstants.ANCHOR_SUFFIX_LENGTH, indexOfNextField); 129 } 130 } 131 | Popular Tags |