KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > typeconstraints > types > PrimitiveType


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.corext.refactoring.typeconstraints.types;
12
13 import org.eclipse.jdt.core.IJavaProject;
14
15
16 public final class PrimitiveType extends TType {
17
18     /** Type code for the primitive type "int". */
19     public static final int INT = 0;
20     /** Type code for the primitive type "char". */
21     public static final int CHAR = 1;
22     /** Type code for the primitive type "boolean". */
23     public static final int BOOLEAN = 2;
24     /** Type code for the primitive type "short". */
25     public static final int SHORT = 3;
26     /** Type code for the primitive type "long". */
27     public static final int LONG = 4;
28     /** Type code for the primitive type "float". */
29     public static final int FLOAT = 5;
30     /** Type code for the primitive type "double". */
31     public static final int DOUBLE = 6;
32     /** Type code for the primitive type "byte". */
33     public static final int BYTE = 7;
34     
35     static final String JavaDoc[] NAMES= {
36         "int", //$NON-NLS-1$
37
"char", //$NON-NLS-1$
38
"boolean", //$NON-NLS-1$
39
"short", //$NON-NLS-1$
40
"long", //$NON-NLS-1$
41
"float", //$NON-NLS-1$
42
"double", //$NON-NLS-1$
43
"byte"}; //$NON-NLS-1$
44

45     private int fId;
46     
47     protected PrimitiveType(TypeEnvironment environment, int id, String JavaDoc signature) {
48         super(environment, signature);
49         fId= id;
50     }
51     
52     public int getId() {
53         return fId;
54     }
55     
56     public int getKind() {
57         return PRIMITIVE_TYPE;
58     }
59     
60     protected boolean doEquals(TType type) {
61         return fId == ((PrimitiveType)type).fId;
62     }
63
64     protected boolean doCanAssignTo(TType lhs) {
65         if (lhs.getKind() != PRIMITIVE_TYPE) {
66             if (lhs.getKind() == STANDARD_TYPE) {
67                 IJavaProject javaProject= ((StandardType)lhs).getJavaElementType().getJavaProject();
68                 return getEnvironment().createBoxed(this, javaProject).canAssignTo(lhs);
69             }
70             return false;
71         }
72         
73         switch (((PrimitiveType)lhs).fId) {
74             case BOOLEAN :
75             case BYTE :
76             case CHAR :
77                 return false;
78             case DOUBLE :
79                 switch (fId) {
80                     case BYTE :
81                     case CHAR :
82                     case SHORT :
83                     case INT :
84                     case LONG :
85                     case FLOAT :
86                         return true;
87                     default :
88                         return false;
89                 }
90             case FLOAT :
91                 switch (fId) {
92                     case BYTE :
93                     case CHAR :
94                     case SHORT :
95                     case INT :
96                     case LONG :
97                         return true;
98                     default :
99                         return false;
100                 }
101             case LONG :
102                 switch (fId) {
103                     case BYTE :
104                     case CHAR :
105                     case SHORT :
106                     case INT :
107                         return true;
108                     default :
109                         return false;
110                 }
111             case INT :
112                 switch (fId) {
113                     case BYTE :
114                     case CHAR :
115                     case SHORT :
116                         return true;
117                     default :
118                         return false;
119                 }
120             case SHORT :
121                 return (fId == BYTE);
122         }
123         return false;
124     }
125     
126     public String JavaDoc getName() {
127         return NAMES[fId];
128     }
129     
130     protected String JavaDoc getPlainPrettySignature() {
131         return NAMES[fId];
132     }
133 }
134
Popular Tags