KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > hierarchy > HierarchyBinaryType


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.hierarchy;
12
13 import org.eclipse.jdt.core.Signature;
14 import org.eclipse.jdt.core.compiler.CharOperation;
15 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
16 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
17 import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
18 import org.eclipse.jdt.internal.compiler.env.IBinaryField;
19 import org.eclipse.jdt.internal.compiler.env.IBinaryMethod;
20 import org.eclipse.jdt.internal.compiler.env.IBinaryNestedType;
21 import org.eclipse.jdt.internal.compiler.env.IBinaryType;
22 import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
23
24 public class HierarchyBinaryType implements IBinaryType {
25     private int modifiers;
26     private char[] sourceName;
27     private char[] name;
28     private char[] enclosingTypeName;
29     private char[] superclass;
30     private char[][] superInterfaces = NoInterface;
31     private char[][] typeParameterSignatures;
32     private char[] genericSignature;
33     
34 public HierarchyBinaryType(int modifiers, char[] qualification, char[] sourceName, char[] enclosingTypeName, char[][] typeParameterSignatures, char typeSuffix){
35
36     this.modifiers = modifiers;
37     this.sourceName = sourceName;
38     if (enclosingTypeName == null){
39         this.name = CharOperation.concat(qualification, sourceName, '/');
40     } else {
41         this.name = CharOperation.concat(qualification, '/', enclosingTypeName, '$', sourceName); //rebuild A$B name
42
this.enclosingTypeName = CharOperation.concat(qualification, enclosingTypeName,'/');
43         CharOperation.replace(this.enclosingTypeName, '.', '/');
44     }
45     this.typeParameterSignatures = typeParameterSignatures;
46     CharOperation.replace(this.name, '.', '/');
47 }
48 /**
49  * Answer the resolved name of the enclosing type in the
50  * class file format as specified in section 4.2 of the Java 2 VM spec
51  * or null if the receiver is a top level type.
52  *
53  * For example, java.lang.String is java/lang/String.
54  */

55 public char[] getEnclosingTypeName() {
56     return this.enclosingTypeName;
57 }
58 /**
59  * Answer the receiver's fields or null if the array is empty.
60  */

61 public IBinaryField[] getFields() {
62     return null;
63 }
64 /**
65  * @see org.eclipse.jdt.internal.compiler.env.IDependent#getFileName()
66  */

67 public char[] getFileName() {
68     return null;
69 }
70 public char[] getGenericSignature() {
71     if (this.typeParameterSignatures != null && this.genericSignature == null) {
72         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
73         buffer.append('<');
74         for (int i = 0, length = this.typeParameterSignatures.length; i < length; i++) {
75             buffer.append(this.typeParameterSignatures[i]);
76         }
77         buffer.append('>');
78         if (this.superclass == null)
79             buffer.append(Signature.createTypeSignature("java.lang.Object", true/*resolved*/)); //$NON-NLS-1$
80
else
81             buffer.append(Signature.createTypeSignature(this.superclass, true/*resolved*/));
82         if (this.superInterfaces != null)
83             for (int i = 0, length = this.superInterfaces.length; i < length; i++)
84                 buffer.append(Signature.createTypeSignature(this.superInterfaces[i], true/*resolved*/));
85         this.genericSignature = buffer.toString().toCharArray();
86         CharOperation.replace(this.genericSignature, '.', '/');
87     }
88     return this.genericSignature;
89 }
90 /**
91  * Answer the resolved names of the receiver's interfaces in the
92  * class file format as specified in section 4.2 of the Java 2 VM spec
93  * or null if the array is empty.
94  *
95  * For example, java.lang.String is java/lang/String.
96  */

97 public char[][] getInterfaceNames() {
98     return this.superInterfaces;
99 }
100 /**
101  * Answer the receiver's nested types or null if the array is empty.
102  *
103  * This nested type info is extracted from the inner class attributes.
104  * Ask the name environment to find a member type using its compound name.
105  */

106 public IBinaryNestedType[] getMemberTypes() {
107     return null;
108 }
109 /**
110  * Answer the receiver's methods or null if the array is empty.
111  */

112 public IBinaryMethod[] getMethods() {
113     return null;
114 }
115 /**
116  * Answer an int whose bits are set according the access constants
117  * defined by the VM spec.
118  */

119 public int getModifiers() {
120     return this.modifiers;
121 }
122 /**
123  * Answer the resolved name of the type in the
124  * class file format as specified in section 4.2 of the Java 2 VM spec.
125  *
126  * For example, java.lang.String is java/lang/String.
127  */

128 public char[] getName() {
129     return this.name;
130 }
131
132 public char[] getSourceName() {
133     return this.sourceName;
134 }
135
136 /**
137  * Answer the resolved name of the receiver's superclass in the
138  * class file format as specified in section 4.2 of the Java 2 VM spec
139  * or null if it does not have one.
140  *
141  * For example, java.lang.String is java/lang/String.
142  */

143 public char[] getSuperclassName() {
144     return this.superclass;
145 }
146 public boolean isAnonymous() {
147     return false; // index did not record this information (since unused for hierarchies)
148
}
149
150 /**
151  * Answer whether the receiver contains the resolved binary form
152  * or the unresolved source form of the type.
153  */

154 public boolean isBinaryType() {
155     return true;
156 }
157 public boolean isLocal() {
158     return false; // index did not record this information (since unused for hierarchies)
159
}
160 public boolean isMember() {
161     return false; // index did not record this information (since unused for hierarchies)
162
}
163
164 public void recordSuperType(char[] superTypeName, char[] superQualification, char superClassOrInterface){
165
166     // index encoding of p.A$B was B/p.A$, rebuild the proper name
167
if (superQualification != null){
168         int length = superQualification.length;
169         if (superQualification[length-1] == '$'){
170             char[] enclosingSuperName = CharOperation.lastSegment(superQualification, '.');
171             superTypeName = CharOperation.concat(enclosingSuperName, superTypeName);
172             superQualification = CharOperation.subarray(superQualification, 0, length - enclosingSuperName.length - 1);
173         }
174     }
175     
176     if (superClassOrInterface == IIndexConstants.CLASS_SUFFIX){
177         // interfaces are indexed as having superclass references to Object by default,
178
// this is an artifact used for being able to query them only.
179
if (TypeDeclaration.kind(this.modifiers) == TypeDeclaration.INTERFACE_DECL) return;
180         char[] encodedName = CharOperation.concat(superQualification, superTypeName, '/');
181         CharOperation.replace(encodedName, '.', '/');
182         this.superclass = encodedName;
183     } else {
184         char[] encodedName = CharOperation.concat(superQualification, superTypeName, '/');
185         CharOperation.replace(encodedName, '.', '/');
186         if (this.superInterfaces == NoInterface){
187             this.superInterfaces = new char[][] { encodedName };
188         } else {
189             int length = this.superInterfaces.length;
190             System.arraycopy(this.superInterfaces, 0, this.superInterfaces = new char[length+1][], 0, length);
191             this.superInterfaces[length] = encodedName;
192         }
193     }
194 }
195 public String JavaDoc toString() {
196     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
197     if (this.modifiers == ClassFileConstants.AccPublic) {
198         buffer.append("public "); //$NON-NLS-1$
199
}
200     switch (TypeDeclaration.kind(this.modifiers)) {
201         case TypeDeclaration.CLASS_DECL :
202             buffer.append("class "); //$NON-NLS-1$
203
break;
204         case TypeDeclaration.INTERFACE_DECL :
205             buffer.append("interface "); //$NON-NLS-1$
206
break;
207         case TypeDeclaration.ENUM_DECL :
208             buffer.append("enum "); //$NON-NLS-1$
209
break;
210     }
211     if (this.name != null) {
212         buffer.append(this.name);
213     }
214     if (this.superclass != null) {
215         buffer.append("\n extends "); //$NON-NLS-1$
216
buffer.append(this.superclass);
217     }
218     int length;
219     if (this.superInterfaces != null && (length = this.superInterfaces.length) != 0) {
220         buffer.append("\n implements "); //$NON-NLS-1$
221
for (int i = 0; i < length; i++) {
222             buffer.append(this.superInterfaces[i]);
223             if (i != length - 1) {
224                 buffer.append(", "); //$NON-NLS-1$
225
}
226         }
227     }
228     return buffer.toString();
229 }
230
231 /**
232  * @see org.eclipse.jdt.internal.compiler.env.IBinaryType
233  */

234 public IBinaryAnnotation[] getAnnotations() {
235     return null;
236 }
237
238 /**
239  * @see org.eclipse.jdt.internal.compiler.env.IBinaryType
240  */

241 public char[] sourceFileName() {
242     return null;
243 }
244 // TODO (jerome) please verify that we don't need the tagbits for the receiver
245
public long getTagBits() {
246     return 0;
247 }
248 }
249
Popular Tags