KickJava   Java API By Example, From Geeks To Geeks.

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


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 public final class SuperWildcardType extends WildcardType {
14
15     protected SuperWildcardType(TypeEnvironment environment) {
16         super(environment);
17     }
18
19     public TType getErasure() {
20         return getEnvironment().getJavaLangObject();
21     }
22     
23     public int getKind() {
24         return SUPER_WILDCARD_TYPE;
25     }
26     
27     protected boolean doCanAssignTo(TType lhs) {
28         switch(lhs.getKind()) {
29             case STANDARD_TYPE:
30                 return ((StandardType)lhs).isJavaLangObject();
31             case UNBOUND_WILDCARD_TYPE:
32                 return true;
33             case EXTENDS_WILDCARD_TYPE:
34                 return ((ExtendsWildcardType)lhs).getBound().isJavaLangObject();
35             case SUPER_WILDCARD_TYPE:
36                 return ((SuperWildcardType)lhs).getBound().canAssignTo(this.getBound());
37             case TYPE_VARIABLE:
38                 return ((TypeVariable)lhs).isUnbounded();
39             case CAPTURE_TYPE:
40                 return ((CaptureType)lhs).checkLowerBound(this);
41                 
42             default:
43                 return false;
44         }
45     }
46     
47     protected boolean checkTypeArgument(TType rhs) {
48         switch(rhs.getKind()) {
49             case ARRAY_TYPE:
50             case STANDARD_TYPE:
51             case PARAMETERIZED_TYPE:
52             case RAW_TYPE:
53                 return getBound().canAssignTo(rhs);
54                 
55             case UNBOUND_WILDCARD_TYPE:
56                 return false;
57             case EXTENDS_WILDCARD_TYPE:
58                 return false;
59             case SUPER_WILDCARD_TYPE:
60                 return getBound().canAssignTo(((SuperWildcardType)rhs).getBound());
61                 
62             case TYPE_VARIABLE:
63                 return getBound().canAssignTo(rhs);
64                 
65             case CAPTURE_TYPE:
66                 return checkTypeArgument(((CaptureType)rhs).getWildcard());
67                 
68             default:
69                 return false;
70         }
71     }
72     
73     protected boolean checkAssignmentBound(TType rhs) {
74         // ? super Number is a set of all super types of number including
75
// Number. So I can only assign objects which are a subtype of
76
// Number.
77
return rhs.canAssignTo(getBound());
78     }
79     
80     public String JavaDoc getName() {
81         return internalGetName("super"); //$NON-NLS-1$
82
}
83     
84     protected String JavaDoc getPlainPrettySignature() {
85         return internalGetPrettySignature("super"); //$NON-NLS-1$
86
}
87 }
88
Popular Tags