]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/PrimitiveType.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / core refactoring / org / eclipse / jdt / internal / corext / refactoring / typeconstraints / types / PrimitiveType.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 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[] 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 signature) {
48                 super(environment, signature);
49                 fId= id;
50         }
51
52         public int getId() {
53                 return fId;
54         }
55
56         @Override
57         public int getKind() {
58                 return PRIMITIVE_TYPE;
59         }
60
61         @Override
62         protected boolean doEquals(TType type) {
63                 return fId == ((PrimitiveType)type).fId;
64         }
65
66         @Override
67         public int hashCode() {
68                 return fId;
69         }
70         
71         @Override
72         protected boolean doCanAssignTo(TType lhs) {
73                 if (lhs.getKind() != PRIMITIVE_TYPE) {
74                         if (lhs.getKind() == STANDARD_TYPE) {
75                                 IJavaProject javaProject= ((StandardType)lhs).getJavaElementType().getJavaProject();
76                                 return getEnvironment().createBoxed(this, javaProject).canAssignTo(lhs);
77                         }
78                         return false;
79                 }
80
81                 switch (((PrimitiveType)lhs).fId) {
82                         case BOOLEAN :
83                         case BYTE :
84                         case CHAR :
85                                 return false;
86                         case DOUBLE :
87                                 switch (fId) {
88                                         case BYTE :
89                                         case CHAR :
90                                         case SHORT :
91                                         case INT :
92                                         case LONG :
93                                         case FLOAT :
94                                                 return true;
95                                         default :
96                                                 return false;
97                                 }
98                         case FLOAT :
99                                 switch (fId) {
100                                         case BYTE :
101                                         case CHAR :
102                                         case SHORT :
103                                         case INT :
104                                         case LONG :
105                                                 return true;
106                                         default :
107                                                 return false;
108                                 }
109                         case LONG :
110                                 switch (fId) {
111                                         case BYTE :
112                                         case CHAR :
113                                         case SHORT :
114                                         case INT :
115                                                 return true;
116                                         default :
117                                                 return false;
118                                 }
119                         case INT :
120                                 switch (fId) {
121                                         case BYTE :
122                                         case CHAR :
123                                         case SHORT :
124                                                 return true;
125                                         default :
126                                                 return false;
127                                 }
128                         case SHORT :
129                                 return (fId == BYTE);
130                 }
131                 return false;
132         }
133
134         @Override
135         public String getName() {
136                 return NAMES[fId];
137         }
138
139         @Override
140         protected String getPlainPrettySignature() {
141                 return NAMES[fId];
142         }
143 }