]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeVariable.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / core refactoring / org / eclipse / jdt / internal / corext / refactoring / typeconstraints / types / TypeVariable.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types;
12
13 import java.util.HashMap;
14
15 import org.eclipse.core.runtime.Assert;
16
17 import org.eclipse.jdt.core.ITypeParameter;
18 import org.eclipse.jdt.core.dom.ITypeBinding;
19
20 import org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsTCModel;
21 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2;
22 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2;
23
24
25
26 public final class TypeVariable extends AbstractTypeVariable {
27
28         private ITypeParameter fJavaTypeParameter;
29
30         protected TypeVariable(TypeEnvironment environment) {
31                 super(environment);
32         }
33
34         protected void initialize(ITypeBinding binding, ITypeParameter javaTypeParameter) {
35                 Assert.isTrue(binding.isTypeVariable());
36                 Assert.isNotNull(javaTypeParameter);
37                 fJavaTypeParameter= javaTypeParameter;
38                 super.initialize(binding);
39         }
40
41         @Override
42         public int getKind() {
43                 return TYPE_VARIABLE;
44         }
45
46         @Override
47         public boolean doEquals(TType type) {
48                 return fJavaTypeParameter.equals(((TypeVariable)type).fJavaTypeParameter);
49         }
50
51         @Override
52         public int hashCode() {
53                 return fJavaTypeParameter.hashCode();
54         }
55
56         @Override
57         protected boolean doCanAssignTo(TType lhs) {
58                 switch (lhs.getKind()) {
59                         case NULL_TYPE:
60                         case VOID_TYPE: return false;
61                         case PRIMITIVE_TYPE:
62
63                         case ARRAY_TYPE: return false;
64
65                         case GENERIC_TYPE: return false;
66
67                         case STANDARD_TYPE:
68                         case PARAMETERIZED_TYPE:
69                         case RAW_TYPE:
70                                 return canAssignOneBoundTo(lhs);
71
72                         case UNBOUND_WILDCARD_TYPE:
73                         case EXTENDS_WILDCARD_TYPE:
74                         case SUPER_WILDCARD_TYPE:
75                                 return ((WildcardType)lhs).checkAssignmentBound(this);
76
77                         case TYPE_VARIABLE:
78                                 return doExtends((TypeVariable)lhs);
79                         case CAPTURE_TYPE:
80                                 return ((CaptureType)lhs).checkLowerBound(this);
81                 }
82                 return false;
83         }
84
85         private boolean doExtends(TypeVariable other) {
86                 return other.generated_6736747279550072243(this);
87         }
88
89         @Override
90         public String getName() {
91                 return fJavaTypeParameter.getElementName();
92         }
93
94         @Override
95         public String getPrettySignature() {
96                 if (fBounds.length == 1 && fBounds[0].isJavaLangObject())
97                         return fJavaTypeParameter.getElementName(); // don't print the trivial bound
98
99                 StringBuffer result= new StringBuffer(fJavaTypeParameter.getElementName());
100                 if (fBounds.length > 0) {
101                         result.append(" extends "); //$NON-NLS-1$
102                         result.append(fBounds[0].getPlainPrettySignature());
103                         for (int i= 1; i < fBounds.length; i++) {
104                                 result.append(" & "); //$NON-NLS-1$
105                                 result.append(fBounds[i].getPlainPrettySignature());
106                         }
107                 }
108                 return result.toString();
109         }
110
111         @Override
112         protected String getPlainPrettySignature() {
113                 return fJavaTypeParameter.getElementName();
114         }
115
116         public void generated_6416044053138177621(ConstraintVariable2 expressionCv, int i, InferTypeArgumentsTCModel infertypeargumentstcmodel) {
117                 infertypeargumentstcmodel.makeElementVariable(expressionCv, this, i);
118                 if (getBounds().length != 0) {
119                         //TODO: create subtype constraints for bounds
120                 }
121         }
122
123         public CollectionElementVariable2 generated_2783228730288621572(ConstraintVariable2 constraintVariable) {
124                 Assert.isTrue(isTypeVariable()); // includes null check
125                 HashMap<String, CollectionElementVariable2> typeVarToElementVars= (HashMap<String, CollectionElementVariable2>) constraintVariable.getData(InferTypeArgumentsTCModel.INDEXED_COLLECTION_ELEMENTS);
126                 if (typeVarToElementVars == null)
127                         return null;
128                 return typeVarToElementVars.get(getBindingKey());
129         }
130
131         public boolean generated_6736747279550072243(TypeVariable typevariable) {
132                 for (int i= 0; i < typevariable.fBounds.length; i++) {
133                         TType bound= typevariable.fBounds[i];
134                         if (equals(bound) || (bound.getKind() == TType.TYPE_VARIABLE && ((TypeVariable)bound).doExtends(this)))
135                                 return true;
136                 }
137                 return false;
138         }
139 }