KickJava   Java API By Example, From Geeks To Geeks.

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


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.BindingKey;
14
15
16 public final class StandardType extends HierarchyType {
17     
18     private static final String JavaDoc OBJECT_KEY= BindingKey.createTypeBindingKey("java.lang.Object"); //$NON-NLS-1$
19
private static final String JavaDoc CLONEABLE_KEY= BindingKey.createTypeBindingKey("java.lang.Cloneable"); //$NON-NLS-1$
20
private static final String JavaDoc SERIALIZABLE_KEY= BindingKey.createTypeBindingKey("java.io.Serializable"); //$NON-NLS-1$
21

22     protected StandardType(TypeEnvironment environment) {
23         super(environment);
24     }
25     
26     public int getKind() {
27         return STANDARD_TYPE;
28     }
29     
30     public boolean isJavaLangObject() {
31         return OBJECT_KEY.equals(getBindingKey());
32     }
33     
34     public boolean isJavaLangCloneable() {
35         return CLONEABLE_KEY.equals(getBindingKey());
36     }
37     
38     public boolean isJavaIoSerializable() {
39         return SERIALIZABLE_KEY.equals(getBindingKey());
40     }
41     
42     public boolean doEquals(TType type) {
43         return getJavaElementType().equals(((StandardType)type).getJavaElementType());
44     }
45     
46     public int hashCode() {
47         return getJavaElementType().hashCode();
48     }
49     
50     protected boolean doCanAssignTo(TType lhs) {
51         switch (lhs.getKind()) {
52             case NULL_TYPE: return false;
53             case VOID_TYPE: return false;
54             case PRIMITIVE_TYPE: return canAssignToPrimitive((PrimitiveType)lhs);
55             
56             case ARRAY_TYPE: return false;
57             
58             case STANDARD_TYPE: return canAssignToStandardType((StandardType)lhs);
59             case GENERIC_TYPE: return false;
60             case PARAMETERIZED_TYPE: return isSubType((HierarchyType)lhs);
61             case RAW_TYPE: return isSubType((HierarchyType)lhs);
62             
63             case UNBOUND_WILDCARD_TYPE:
64             case SUPER_WILDCARD_TYPE:
65             case EXTENDS_WILDCARD_TYPE:
66                 return ((WildcardType)lhs).checkAssignmentBound(this);
67             
68             case TYPE_VARIABLE: return false;
69                 
70             case CAPTURE_TYPE:
71                 return ((CaptureType)lhs).checkLowerBound(this);
72         }
73         return false;
74     }
75
76     private boolean canAssignToPrimitive(PrimitiveType type) {
77         PrimitiveType source= getEnvironment().createUnBoxed(this);
78         return source != null && source.canAssignTo(type);
79     }
80
81     public String JavaDoc getName() {
82         return getJavaElementType().getElementName();
83     }
84     
85     protected String JavaDoc getPlainPrettySignature() {
86         return getJavaElementType().getFullyQualifiedName('.');
87     }
88 }
89
Popular Tags