KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > typeconstraints2 > CollectionElementVariable2


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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
12 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints2;
13
14 import org.eclipse.jdt.core.ICompilationUnit;
15 import org.eclipse.jdt.core.dom.ITypeBinding;
16
17 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeVariable;
18
19 public final class CollectionElementVariable2 extends ConstraintVariable2 {
20
21     public static final int NOT_DECLARED_TYPE_VARIABLE_INDEX= -1;
22     
23     private final ConstraintVariable2 fParentCv;
24     private final String JavaDoc fTypeVariableKey;
25     private final int fDeclarationTypeVariableIndex;
26
27     //TODO: make a 'TypedCollectionElementVariable extends TypeConstraintVariable2'
28
// iff Collection reference already has type parameter in source
29
/**
30      * @param parentCv the parent constraint variable
31      * @param typeVariable the type variable for this constraint
32      * @param declarationTypeVariableIndex
33      */

34     public CollectionElementVariable2(ConstraintVariable2 parentCv, ITypeBinding typeVariable, int declarationTypeVariableIndex) {
35         super(null);
36         fParentCv= parentCv;
37         if (! typeVariable.isTypeVariable())
38             throw new IllegalArgumentException JavaDoc(typeVariable.toString());
39         fTypeVariableKey= typeVariable.getKey();
40         fDeclarationTypeVariableIndex= declarationTypeVariableIndex;
41     }
42
43     public CollectionElementVariable2(ConstraintVariable2 parentCv, TypeVariable typeVariable, int declarationTypeVariableIndex) {
44         super(null);
45         fParentCv= parentCv;
46         fTypeVariableKey= typeVariable.getBindingKey();
47         fDeclarationTypeVariableIndex= declarationTypeVariableIndex;
48     }
49
50     /*
51      * @see java.lang.Object#hashCode()
52      */

53     public int hashCode() {
54         return fParentCv.hashCode() ^ fTypeVariableKey.hashCode();
55     }
56
57     /*
58      * @see java.lang.Object#equals(java.lang.Object)
59      */

60     public boolean equals(Object JavaDoc other) {
61         if (this == other)
62             return true;
63         if (other.getClass() != CollectionElementVariable2.class)
64             return false;
65         
66         CollectionElementVariable2 other2= (CollectionElementVariable2) other;
67         return fParentCv == other2.fParentCv
68                 && fTypeVariableKey.equals(other2.fTypeVariableKey);
69     }
70     
71     public int getDeclarationTypeVariableIndex() {
72         return fDeclarationTypeVariableIndex;
73     }
74     
75     public ConstraintVariable2 getParentConstraintVariable() {
76         return fParentCv;
77     }
78     
79     public ICompilationUnit getCompilationUnit() {
80         if (fParentCv instanceof ISourceConstraintVariable)
81             return ((ISourceConstraintVariable) fParentCv).getCompilationUnit();
82         else
83             return null;
84 // //TODO: assert in constructor(s)
85
// return ((CollectionElementVariable2) fElementCv).getCompilationUnit();
86
}
87     
88     public String JavaDoc toString() {
89         return "Elem[" + fParentCv.toString() + ", " + fTypeVariableKey + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
90
}
91 }
92
Popular Tags