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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types;
13 import org.eclipse.jdt.core.IJavaProject;
16 public final class PrimitiveType extends TType {
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;
35 static final String[] NAMES= {
38 "boolean", //$NON-NLS-1$
39 "short", //$NON-NLS-1$
41 "float", //$NON-NLS-1$
42 "double", //$NON-NLS-1$
43 "byte"}; //$NON-NLS-1$
47 protected PrimitiveType(TypeEnvironment environment, int id, String signature) {
48 super(environment, signature);
57 public int getKind() {
58 return PRIMITIVE_TYPE;
62 protected boolean doEquals(TType type) {
63 return fId == ((PrimitiveType)type).fId;
67 public int hashCode() {
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);
81 switch (((PrimitiveType)lhs).fId) {
129 return (fId == BYTE);
135 public String getName() {
140 protected String getPlainPrettySignature() {