KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.jdt.core.dom.ITypeBinding;
16
17
18 public abstract class WildcardType extends TType {
19     protected TType fBound;
20     
21     protected WildcardType(TypeEnvironment environment) {
22         super(environment);
23     }
24
25     protected void initialize(ITypeBinding binding) {
26         Assert.isTrue(binding.isWildcardType());
27         super.initialize(binding);
28         ITypeBinding bound= binding.getBound();
29         if (bound != null) {
30             fBound= getEnvironment().create(bound);
31         }
32     }
33     
34     public TType getBound() {
35         return fBound;
36     }
37     
38     public TType[] getSubTypes() {
39         throw new UnsupportedOperationException JavaDoc();
40     }
41     
42     public boolean doEquals(TType type) {
43         WildcardType other= (WildcardType)type;
44         if (fBound == null)
45             return other.fBound == null;
46         return fBound.equals(other.fBound);
47     }
48     
49     public int hashCode() {
50         if (fBound == null)
51             return super.hashCode();
52         return fBound.hashCode() << WILDCARD_TYPE_SHIFT;
53     }
54     
55     protected abstract boolean checkAssignmentBound(TType rhs);
56     
57     // protected abstract boolean checkTypeArgumentBound(TType rhs);
58

59     protected String JavaDoc internalGetName(String JavaDoc keyword) {
60         StringBuffer JavaDoc result= new StringBuffer JavaDoc("?"); //$NON-NLS-1$
61
TType bound= getBound();
62         if (bound != null) {
63             result.append(" "); //$NON-NLS-1$
64
result.append(keyword);
65             result.append(" "); //$NON-NLS-1$
66
result.append(bound.getName());
67         }
68         return result.toString();
69     }
70     
71     protected String JavaDoc internalGetPrettySignature(String JavaDoc keyword) {
72         StringBuffer JavaDoc result= new StringBuffer JavaDoc("?"); //$NON-NLS-1$
73
TType bound= getBound();
74         if (bound != null) {
75             result.append(" "); //$NON-NLS-1$
76
result.append(keyword);
77             result.append(" "); //$NON-NLS-1$
78
result.append(bound.getPlainPrettySignature());
79         }
80         return result.toString();
81     }
82 }
83
Popular Tags