KickJava   Java API By Example, From Geeks To Geeks.

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


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.dom.ITypeBinding;
14
15
16 public abstract class AbstractTypeVariable extends TType {
17     
18     protected TType[] fBounds;
19     
20     protected AbstractTypeVariable(TypeEnvironment environment) {
21         super(environment);
22     }
23
24     protected void initialize(ITypeBinding binding) {
25         super.initialize(binding);
26         ITypeBinding[] bounds= binding.getTypeBounds();
27         if (bounds.length == 0) {
28             fBounds= EMPTY_TYPE_ARRAY;
29             if (getEnvironment().getJavaLangObject() == null) {
30                 getEnvironment().initializeJavaLangObject(binding.getErasure());
31             }
32         } else {
33             fBounds= new TType[bounds.length];
34             for (int i= 0; i < bounds.length; i++) {
35                 fBounds[i]= getEnvironment().create(bounds[i]);
36             }
37         }
38     }
39     
40     public TType getErasure() {
41         if (fBounds.length == 0)
42             return getEnvironment().getJavaLangObject();
43         return fBounds[0].getErasure();
44     }
45     
46     /* package */ final boolean isUnbounded() {
47         if (fBounds.length == 0)
48             return true;
49         return fBounds[0].isJavaLangObject();
50     }
51     
52     public final TType[] getBounds() {
53         return (TType[]) fBounds.clone();
54     }
55     
56     public final TType[] getSubTypes() {
57         return EMPTY_TYPE_ARRAY;
58     }
59     
60     protected final boolean checkAssignmentBound(TType rhs) {
61         if (fBounds.length == 0)
62             return true;
63         for (int i= 0; i < fBounds.length; i++) {
64             if (rhs.canAssignTo(fBounds[i]))
65                 return true;
66         }
67         return false;
68     }
69     
70     protected final boolean canAssignOneBoundTo(TType lhs) {
71         if (fBounds.length == 0)
72             return lhs.isJavaLangObject();
73         for (int i= 0; i < fBounds.length; i++) {
74             if (fBounds[i].canAssignTo(lhs))
75                 return true;
76         }
77         return false;
78     }
79     
80 }
81
Popular Tags