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