Makefile fixup
[org.ibex.tool.git] / repo / org.ibex.tool / src / org / eclipse / jdt / internal / compiler / lookup / TypeBinding.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.lookup;
12
13 import org.eclipse.jdt.core.compiler.CharOperation;
14
15 /*
16  * Not all fields defined by this type (& its subclasses) are initialized when it is created.
17  * Some are initialized only when needed.
18  *
19  * Accessors have been provided for some public fields so all TypeBindings have the same API...
20  * but access public fields directly whenever possible.
21  * Non-public fields have accessors which should be used everywhere you expect the field to be initialized.
22  *
23  * null is NOT a valid value for a non-public field... it just means the field is not initialized.
24  */
25 abstract public class TypeBinding extends Binding implements BaseTypes, TagBits, TypeConstants, TypeIds {
26         public int id = NoId;
27         public int tagBits = 0; // See values in the interface TagBits below
28 /* API
29  * Answer the receiver's binding type from Binding.BindingID.
30  */
31
32 public final int bindingType() {
33         return TYPE;
34 }
35 /* Answer true if the receiver can be instantiated
36  */
37 public boolean canBeInstantiated() {
38         return !isBaseType();
39 }
40 /**
41  *  Answer the receiver's constant pool name.
42  *  NOTE: This method should only be used during/after code gen.
43  *  e.g. 'java/lang/Object' 
44  */
45 public abstract char[] constantPoolName();
46
47 String debugName() {
48         return new String(readableName());
49 }
50 /*
51  * Answer the receiver's dimensions - 0 for non-array types
52  */
53 public int dimensions(){
54         return 0;
55 }
56 public abstract PackageBinding getPackage();
57 /* Answer true if the receiver is an array
58 */
59
60 public final boolean isArrayType() {
61         return (tagBits & IsArrayType) != 0;
62 }
63 /* Answer true if the receiver is a base type
64 */
65
66 public final boolean isBaseType() {
67         return (tagBits & IsBaseType) != 0;
68 }
69 public boolean isClass() {
70         return false;
71 }
72 /* Answer true if the receiver type can be assigned to the argument type (right)
73 */
74         
75 public abstract boolean isCompatibleWith(TypeBinding right);
76 /* Answer true if the receiver's hierarchy has problems (always false for arrays & base types)
77 */
78
79 public final boolean isHierarchyInconsistent() {
80         return (tagBits & HierarchyHasProblems) != 0;
81 }
82 public boolean isInterface() {
83         return false;
84 }
85 public final boolean isNumericType() {
86         switch (id) {
87                 case T_int :
88                 case T_float :
89                 case T_double :
90                 case T_short :
91                 case T_byte :
92                 case T_long :
93                 case T_char :
94                         return true;
95                 default :
96                         return false;
97         }
98 }
99
100 public TypeBinding leafComponentType(){
101         return this;
102 }
103
104 /**
105  * Answer the qualified name of the receiver's package separated by periods
106  * or an empty string if its the default package.
107  *
108  * For example, {java.util.Hashtable}.
109  */
110
111 public char[] qualifiedPackageName() {
112         PackageBinding packageBinding = getPackage();
113         return packageBinding == null  || packageBinding.compoundName == CharOperation.NO_CHAR_CHAR
114                 ? CharOperation.NO_CHAR
115                 : packageBinding.readableName();
116 }
117 /**
118 * Answer the source name for the type.
119 * In the case of member types, as the qualified name from its top level type.
120 * For example, for a member type N defined inside M & A: "A.M.N".
121 */
122
123 public abstract char[] qualifiedSourceName();
124 /* Answer the receiver's signature.
125 *
126 * Arrays & base types do not distinguish between signature() & constantPoolName().
127 *
128 * NOTE: This method should only be used during/after code gen.
129 */
130
131 public char[] signature() {
132         return constantPoolName();
133 }
134 public abstract char[] sourceName();
135
136 /**
137  * Match a well-known type id to its binding
138  */
139 public static final TypeBinding wellKnownType(Scope scope, int id) {
140                 switch (id) { 
141                         case T_boolean :
142                                 return BooleanBinding;
143                         case T_byte :
144                                 return ByteBinding;
145                         case T_char :
146                                 return CharBinding;
147                         case T_short :
148                                 return ShortBinding;
149                         case T_double :
150                                 return DoubleBinding;
151                         case T_float :
152                                 return FloatBinding;
153                         case T_int :
154                                 return IntBinding;
155                         case T_long :
156                                 return LongBinding;
157                         case T_Object :
158                                 return scope.getJavaLangObject();
159                         case T_String :
160                                 return scope.getJavaLangString();
161                         default : 
162                                 return null;
163                 }
164         }
165 }