1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types;
13 import org.eclipse.core.runtime.Assert;
15 import org.eclipse.jdt.core.IType;
16 import org.eclipse.jdt.core.dom.ITypeBinding;
20 public final class ParameterizedType extends HierarchyType {
22 GenericType fTypeDeclaration;
23 TType[] fTypeArguments;
25 protected ParameterizedType(TypeEnvironment environment) {
30 protected void initialize(ITypeBinding binding, IType javaElementType) {
31 Assert.isTrue(binding.isParameterizedType());
32 super.initialize(binding, javaElementType);
33 TypeEnvironment environment= getEnvironment();
34 environment.generated_2085605341809161205(binding, this);
38 public int getKind() {
39 return PARAMETERIZED_TYPE;
43 public TType getTypeDeclaration() {
44 return fTypeDeclaration;
48 public TType getErasure() {
49 return fTypeDeclaration;
52 public TType[] getTypeArguments() {
53 return fTypeArguments.clone();
57 public boolean doEquals(TType type) {
58 ParameterizedType other= (ParameterizedType)type;
59 return other.generated_615097351123009789(this);
63 public int hashCode() {
64 return getBindingKey().hashCode();
68 protected boolean doCanAssignTo(TType lhs) {
69 int targetType= lhs.getKind();
71 case NULL_TYPE: return false;
72 case VOID_TYPE: return false;
73 case PRIMITIVE_TYPE: return false;
75 case ARRAY_TYPE: return false;
77 case STANDARD_TYPE: return canAssignToStandardType((StandardType)lhs);
78 case GENERIC_TYPE: return false;
79 case PARAMETERIZED_TYPE: return canAssignToParameterizedType((ParameterizedType)lhs);
80 case RAW_TYPE: return canAssignToRawType((RawType)lhs);
82 case UNBOUND_WILDCARD_TYPE:
83 case SUPER_WILDCARD_TYPE:
84 case EXTENDS_WILDCARD_TYPE:
85 return ((WildcardType)lhs).checkAssignmentBound(this);
87 case TYPE_VARIABLE: return false;
89 return ((CaptureType)lhs).checkLowerBound(this);
95 protected boolean isTypeEquivalentTo(TType other) {
96 int otherElementType= other.getKind();
97 if (otherElementType == RAW_TYPE || otherElementType == GENERIC_TYPE)
98 return getErasure().isTypeEquivalentTo(other.getErasure());
99 return super.isTypeEquivalentTo(other);
102 private boolean canAssignToRawType(RawType target) {
103 return fTypeDeclaration.isSubType(target.getHierarchyType());
106 private boolean canAssignToParameterizedType(ParameterizedType target) {
107 ParameterizedType sameSourceType= target.generated_1909260601597603387(this);
108 if (sameSourceType == null)
110 TType[] targetArguments= target.fTypeArguments;
111 TType[] sourceArguments= sameSourceType.fTypeArguments;
112 if (targetArguments.length != sourceArguments.length)
114 for (int i= 0; i < sourceArguments.length; i++) {
115 if (!targetArguments[i].checkTypeArgument(sourceArguments[i]))
121 ParameterizedType findSameDeclaration(GenericType targetDeclaration) {
122 return targetDeclaration.generated_145440679273676249(this);
126 public String getName() {
127 StringBuffer result= new StringBuffer(getJavaElementType().getElementName());
128 result.append("<"); //$NON-NLS-1$
129 result.append(fTypeArguments[0].getName());
130 for (int i= 1; i < fTypeArguments.length; i++) {
131 result.append(", "); //$NON-NLS-1$
132 result.append(fTypeArguments[i].getName());
134 result.append(">"); //$NON-NLS-1$
135 return result.toString();
139 protected String getPlainPrettySignature() {
140 StringBuffer result= new StringBuffer(getJavaElementType().getFullyQualifiedName('.'));
141 result.append("<"); //$NON-NLS-1$
142 result.append(fTypeArguments[0].getPlainPrettySignature());
143 for (int i= 1; i < fTypeArguments.length; i++) {
144 result.append(", "); //$NON-NLS-1$
145 result.append(fTypeArguments[i].getPlainPrettySignature());
147 result.append(">"); //$NON-NLS-1$
148 return result.toString();
151 public ParameterizedType generated_2503171166411270533(TypeEnvironment typeenvironment) {
152 typeenvironment.cacheSubType(getSuperclass(), this);
153 typeenvironment.cacheSubTypes(getInterfaces(), this);
157 public boolean generated_615097351123009789(ParameterizedType parameterizedtype) {
158 if (! parameterizedtype.getBindingKey().equals(getBindingKey()))
160 if (! parameterizedtype.getJavaElementType().equals(getJavaElementType()))
165 public ParameterizedType generated_1909260601597603387(ParameterizedType parameterizedtype) {
166 GenericType targetDeclaration= fTypeDeclaration;
167 ParameterizedType sameSourceType= parameterizedtype.findSameDeclaration(targetDeclaration);
168 return sameSourceType;