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 / BaseTypeBinding.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 public final class BaseTypeBinding extends TypeBinding {
14         public char[] simpleName;
15
16         private char[] constantPoolName;
17
18         BaseTypeBinding(int id, char[] name, char[] constantPoolName) {
19                 this.tagBits |= IsBaseType;
20                 this.id = id;
21                 this.simpleName = name;
22                 this.constantPoolName = constantPoolName;
23         }
24
25         /*
26          * Answer the receiver's constant pool name.
27          */
28
29         public char[] constantPoolName() {
30                 return constantPoolName;
31         }
32
33         public PackageBinding getPackage() {
34                 return null;
35         }
36
37         /*
38          * Answer true if the receiver type can be assigned to the argument type
39          * (right)
40          */
41
42         public final boolean isCompatibleWith(TypeBinding right) {
43                 if (this == right)
44                         return true;
45                 if (!right.isBaseType())
46                         return this == NullBinding;
47
48                 switch (right.id) {
49                 case T_boolean:
50                 case T_byte:
51                 case T_char:
52                         return false;
53                 case T_double:
54                         switch (id) {
55                         case T_byte:
56                         case T_char:
57                         case T_short:
58                         case T_int:
59                         case T_long:
60                         case T_float:
61                                 return true;
62                         default:
63                                 return false;
64                         }
65                 case T_float:
66                         switch (id) {
67                         case T_byte:
68                         case T_char:
69                         case T_short:
70                         case T_int:
71                         case T_long:
72                                 return true;
73                         default:
74                                 return false;
75                         }
76                 case T_long:
77                         switch (id) {
78                         case T_byte:
79                         case T_char:
80                         case T_short:
81                         case T_int:
82                                 return true;
83                         default:
84                                 return false;
85                         }
86                 case T_int:
87                         switch (id) {
88                         case T_byte:
89                         case T_char:
90                         case T_short:
91                                 return true;
92                         default:
93                                 return false;
94                         }
95                 case T_short:
96                         return (id == T_byte);
97                 }
98                 return false;
99         }
100
101         public static final boolean isNarrowing(int left, int right) {
102                 // can "left" store a "right" using some narrowing conversion
103                 // (is left smaller than right)
104
105                 switch (left) {
106                 case T_boolean:
107                         return right == T_boolean;
108                 case T_char:
109                 case T_byte:
110                         if (right == T_byte)
111                                 return true;
112                 case T_short:
113                         if (right == T_short)
114                                 return true;
115                         if (right == T_char)
116                                 return true;
117                 case T_int:
118                         if (right == T_int)
119                                 return true;
120                 case T_long:
121                         if (right == T_long)
122                                 return true;
123                 case T_float:
124                         if (right == T_float)
125                                 return true;
126                 case T_double:
127                         if (right == T_double)
128                                 return true;
129                 default:
130                         return false;
131                 }
132         }
133
134         public static final boolean isWidening(int left, int right) {
135                 // can "left" store a "right" using some widening conversion
136                 // (is left "bigger" than right)
137
138                 switch (left) {
139                 case T_boolean:
140                         return right == T_boolean;
141                 case T_char:
142                         return right == T_char;
143                 case T_double:
144                         if (right == T_double)
145                                 return true;
146                 case T_float:
147                         if (right == T_float)
148                                 return true;
149                 case T_long:
150                         if (right == T_long)
151                                 return true;
152                 case T_int:
153                         if (right == T_int)
154                                 return true;
155                         if (right == T_char)
156                                 return true;
157                 case T_short:
158                         if (right == T_short)
159                                 return true;
160                 case T_byte:
161                         if (right == T_byte)
162                                 return true;
163                 default:
164                         return false;
165                 }
166         }
167
168         public char[] qualifiedSourceName() {
169                 return simpleName;
170         }
171
172         public char[] readableName() {
173                 return simpleName;
174         }
175
176         public char[] shortReadableName() {
177                 return simpleName;
178         }
179
180         public char[] sourceName() {
181                 return simpleName;
182         }
183
184         public String toString() {
185                 return new String(constantPoolName) + " (id=" + id + ")"; //$NON-NLS-1$ //$NON-NLS-2$
186         }
187 }