KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > BinaryField


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
23  * @see IField
24  */

25
26 /* package */ class BinaryField extends BinaryMember implements IField {
27
28 /*
29  * Constructs a handle to the field with the given name in the specified type.
30  */

31 protected BinaryField(JavaElement parent, String JavaDoc name) {
32     super(parent, name);
33 }
34 public boolean equals(Object JavaDoc o) {
35     if (!(o instanceof BinaryField)) return false;
36     return super.equals(o);
37 }
38 /*
39  * @see IField
40  */

41 public Object JavaDoc getConstant() throws JavaModelException {
42     IBinaryField info = (IBinaryField) getElementInfo();
43     return convertConstant(info.getConstant());
44 }
45 /*
46  * @see IMember
47  */

48 public int getFlags() throws JavaModelException {
49     IBinaryField info = (IBinaryField) getElementInfo();
50     return info.getModifiers();
51 }
52 /*
53  * @see IJavaElement
54  */

55 public int getElementType() {
56     return FIELD;
57 }
58 /*
59  * @see JavaElement#getHandleMemento()
60  */

61 protected char getHandleMementoDelimiter() {
62     return JavaElement.JEM_FIELD;
63 }
64 public String JavaDoc getKey(boolean forceOpen) throws JavaModelException {
65     return getKey(this, forceOpen);
66 }
67 /*
68  * @see IField
69  */

70 public String JavaDoc getTypeSignature() throws JavaModelException {
71     IBinaryField info = (IBinaryField) getElementInfo();
72     return new String JavaDoc(ClassFile.translatedName(info.getTypeName()));
73 }
74 /* (non-Javadoc)
75  * @see org.eclipse.jdt.core.IField#isEnumConstant()
76  */
public boolean isEnumConstant() throws JavaModelException {
77     return Flags.isEnum(getFlags());
78 }
79 /* (non-Javadoc)
80  * @see org.eclipse.jdt.core.IField#isResolved()
81  */

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 JavaDoc(binding.computeUniqueKey()));
87     resolvedHandle.occurrenceCount = this.occurrenceCount;
88     return resolvedHandle;
89 }
90 /*
91  * @private Debugging purposes
92  */

93 protected void toStringInfo(int tab, StringBuffer JavaDoc buffer, Object JavaDoc info, boolean showResolvedInfo) {
94     buffer.append(this.tabString(tab));
95     if (info == null) {
96         toStringName(buffer);
97         buffer.append(" (not open)"); //$NON-NLS-1$
98
} else if (info == NO_INFO) {
99         toStringName(buffer);
100     } else {
101         try {
102             buffer.append(Signature.toString(this.getTypeSignature()));
103             buffer.append(" "); //$NON-NLS-1$
104
toStringName(buffer);
105         } catch (JavaModelException e) {
106             buffer.append("<JavaModelException in toString of " + getElementName()); //$NON-NLS-1$
107
}
108     }
109 }
110 public String JavaDoc getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException {
111     String JavaDoc 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