1 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.IType; 16 import org.eclipse.jdt.core.dom.ITypeBinding; 17 18 19 public final class GenericType extends HierarchyType { 20 21 private TypeVariable[] fTypeParameters; 22 23 protected GenericType(TypeEnvironment environment) { 24 super(environment); 25 } 26 27 protected void initialize(ITypeBinding binding, IType javaElementType) { 28 Assert.isTrue(binding.isGenericType()); 29 super.initialize(binding, javaElementType); 30 TypeEnvironment environment= getEnvironment(); 31 ITypeBinding[] typeParameters= binding.getTypeParameters(); 32 fTypeParameters= new TypeVariable[typeParameters.length]; 33 for (int i= 0; i < typeParameters.length; i++) { 34 fTypeParameters[i]= (TypeVariable) environment.create(typeParameters[i]); 35 } 36 } 37 38 public int getKind() { 39 return GENERIC_TYPE; 40 } 41 42 public TypeVariable[] getTypeParameters() { 43 return (TypeVariable[]) fTypeParameters.clone(); 44 } 45 46 public boolean doEquals(TType type) { 47 return getJavaElementType().equals(((GenericType)type).getJavaElementType()); 48 } 49 50 public int hashCode() { 51 return getJavaElementType().hashCode(); 52 } 53 54 protected boolean doCanAssignTo(TType type) { 55 return false; 56 } 57 58 protected boolean isTypeEquivalentTo(TType other) { 59 int otherElementType= other.getKind(); 60 if (otherElementType == RAW_TYPE || otherElementType == PARAMETERIZED_TYPE) 61 return getErasure().isTypeEquivalentTo(other.getErasure()); 62 return super.isTypeEquivalentTo(other); 63 } 64 65 public String getName() { 66 return getJavaElementType().getElementName(); 67 } 68 69 protected String getPlainPrettySignature() { 70 StringBuffer result= new StringBuffer (getJavaElementType().getFullyQualifiedName('.')); 71 result.append("<"); result.append(fTypeParameters[0].getPrettySignature()); 73 for (int i= 1; i < fTypeParameters.length; i++) { 74 result.append(", "); result.append(fTypeParameters[i].getPrettySignature()); 76 } 77 result.append(">"); return result.toString(); 79 } 80 } 81 | Popular Tags |