KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 ExtendsWildcardType extends WildcardType {
14
15     protected ExtendsWildcardType(TypeEnvironment environment) {
16         super(environment);
17     }
18
19     public int getKind() {
20         return EXTENDS_WILDCARD_TYPE;
21     }
22     
23     public TType getErasure() {
24         return fBound.getErasure();
25     }
26     
27     public TType[] getSubTypes() {
28         return new TType[] { fBound };
29     }
30     
31     protected boolean doCanAssignTo(TType lhs) {
32         switch (lhs.getKind()) {
33             case ARRAY_TYPE:
34             case STANDARD_TYPE:
35             case PARAMETERIZED_TYPE:
36             case RAW_TYPE:
37                 return getBound().canAssignTo(lhs);
38             
39             case UNBOUND_WILDCARD_TYPE:
40                 return true;
41             case SUPER_WILDCARD_TYPE:
42             case EXTENDS_WILDCARD_TYPE:
43                 return ((WildcardType)lhs).checkAssignmentBound(getBound());
44             
45             case TYPE_VARIABLE:
46                 return ((TypeVariable)lhs).checkAssignmentBound(getBound());
47             case CAPTURE_TYPE:
48                 return ((CaptureType)lhs).checkLowerBound(this);
49                 
50             default:
51                 return false;
52         }
53     }
54     
55     protected boolean checkTypeArgument(TType rhs) {
56         switch(rhs.getKind()) {
57             case ARRAY_TYPE:
58             case STANDARD_TYPE:
59             case PARAMETERIZED_TYPE:
60                 return rhs.canAssignTo(getBound());
61             case RAW_TYPE:
62                 // unchecked conversion not allowed here; fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583
63
return ! getBound().isParameterizedType() && rhs.canAssignTo(getBound());
64                 
65             case UNBOUND_WILDCARD_TYPE:
66                 return getBound().isJavaLangObject();
67             case EXTENDS_WILDCARD_TYPE:
68                 return ((ExtendsWildcardType)rhs).getBound().canAssignTo(getBound());
69             case SUPER_WILDCARD_TYPE:
70                 return getBound().isJavaLangObject();
71                 
72             case TYPE_VARIABLE:
73                 return rhs.canAssignTo(getBound());
74                 
75             case CAPTURE_TYPE:
76                 return checkTypeArgument(((CaptureType)rhs).getWildcard());
77                 
78             default:
79                 return false;
80         }
81     }
82     
83     protected boolean checkAssignmentBound(TType rhs) {
84         // ? extends Number is a set of all subtyes of number and number.
85
// so the only thing that can be assigned is null since null is
86
// a sub type of everything
87
return rhs.isNullType();
88     }
89     
90     public String JavaDoc getName() {
91         return internalGetName("extends"); //$NON-NLS-1$
92
}
93     
94     protected String JavaDoc getPlainPrettySignature() {
95         return internalGetPrettySignature("extends"); //$NON-NLS-1$
96
}
97 }
98
Popular Tags