KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc getName() {
66         return getJavaElementType().getElementName();
67     }
68     
69     protected String JavaDoc getPlainPrettySignature() {
70         StringBuffer JavaDoc result= new StringBuffer JavaDoc(getJavaElementType().getFullyQualifiedName('.'));
71         result.append("<"); //$NON-NLS-1$
72
result.append(fTypeParameters[0].getPrettySignature());
73         for (int i= 1; i < fTypeParameters.length; i++) {
74             result.append(", "); //$NON-NLS-1$
75
result.append(fTypeParameters[i].getPrettySignature());
76         }
77         result.append(">"); //$NON-NLS-1$
78
return result.toString();
79     }
80 }
81
Popular Tags