1 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 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 |