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