]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
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; | |
12 | ||
13 | import org.eclipse.jdt.core.dom.ITypeBinding; | |
14 | ||
15 | import org.eclipse.jdt.internal.corext.dom.Bindings; | |
16 | import org.eclipse.jdt.internal.corext.dom.TypeRules; | |
17 | ||
18 | public abstract class ConstraintVariable { | |
19 | /** | |
20 | * The type binding, or <code>null</code>. | |
21 | */ | |
22 | private final ITypeBinding fTypeBinding; | |
23 | ||
24 | /** | |
25 | * @param binding the type binding, or <code>null</code> | |
26 | */ | |
27 | protected ConstraintVariable(ITypeBinding binding) { | |
28 | fTypeBinding= binding; | |
29 | } | |
30 | ||
31 | public boolean canBeAssignedTo(ConstraintVariable targetVariable) { | |
32 | if (fTypeBinding == null || targetVariable.fTypeBinding == null) | |
33 | return false; | |
34 | return TypeRules.canAssign(fTypeBinding, targetVariable.fTypeBinding); | |
35 | } | |
36 | ||
37 | public String toResolvedString() { | |
38 | if (fTypeBinding == null) | |
39 | return "<NULL BINDING>"; //$NON-NLS-1$ | |
40 | return Bindings.asString(fTypeBinding); | |
41 | } | |
42 | ||
43 | /* (non-Javadoc) | |
44 | * @see java.lang.Object#toString() | |
45 | */ | |
46 | @Override | |
47 | public String toString() { | |
48 | return toResolvedString(); | |
49 | } | |
50 | ||
51 | /** | |
52 | * @return the type binding or <code>null</code> | |
53 | */ | |
54 | //TODO: rename to getTypeBinding() | |
55 | public ITypeBinding getBinding() { | |
56 | return fTypeBinding; | |
57 | } | |
58 | ||
59 | /** | |
60 | * For storing additional information associated with constraint variables. | |
61 | * Added in anticipation of the generics-related refactorings. | |
62 | */ | |
63 | private Object fData; | |
64 | ||
65 | public Object getData(){ | |
66 | return fData; | |
67 | } | |
68 | ||
69 | public void setData(Object data){ | |
70 | fData= data; | |
71 | } | |
72 | } |