KickJava   Java API By Example, From Geeks To Geeks.

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


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
12 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints2;
13
14 import org.eclipse.core.runtime.Assert;
15
16 import org.eclipse.jdt.core.ICompilationUnit;
17
18 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.CompilationUnitRange;
19 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType;
20
21 /**
22  * A TypeVariable is a ConstraintVariable which stands for a
23  * single type reference (in source).
24  */

25 public final class TypeVariable2 extends ConstraintVariable2 implements ITypeConstraintVariable {
26
27     private final CompilationUnitRange fRange;
28
29     public TypeVariable2(TType type, CompilationUnitRange range) {
30         super(type);
31         Assert.isNotNull(range);
32         fRange= range;
33     }
34     
35     public CompilationUnitRange getRange() {
36         return fRange;
37     }
38     
39     /*
40      * @see java.lang.Object#hashCode()
41      */

42     public int hashCode() {
43         return getRange().hashCode() ^ getType().hashCode();
44     }
45     
46     /*
47      * @see java.lang.Object#equals(java.lang.Object)
48      */

49     public boolean equals(Object JavaDoc other) {
50         //TODO: unique per construction? //return this == other;
51
if (this == other)
52             return true;
53         if (other.getClass() != TypeVariable2.class)
54             return false;
55         
56         TypeVariable2 otherTypeVariable= (TypeVariable2) other;
57         return getRange().equals(otherTypeVariable.getRange())
58                 && getType() == otherTypeVariable.getType();
59     }
60
61     public void setCompilationUnit(ICompilationUnit unit) {
62         throw new UnsupportedOperationException JavaDoc();
63     }
64
65     public ICompilationUnit getCompilationUnit() {
66         return fRange.getCompilationUnit();
67     }
68     
69     public String JavaDoc toString() {
70         return super.toString() + " [" + fRange.getSourceRange().getOffset() + '+' + fRange.getSourceRange().getLength() + ']'; //$NON-NLS-1$
71
}
72 }
73
Popular Tags