01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.corext.refactoring.typeconstraints;
11:
12: import org.eclipse.jdt.core.dom.ITypeBinding;
13:
14: import org.eclipse.jdt.internal.corext.dom.Bindings;
15: import org.eclipse.jdt.internal.corext.dom.TypeRules;
16:
17: public abstract class ConstraintVariable {
18: /**
19: * The type binding, or <code>null</code>.
20: */
21: private final ITypeBinding fTypeBinding;
22:
23: /**
24: * @param binding the type binding, or <code>null</code>
25: */
26: protected ConstraintVariable(ITypeBinding binding) {
27: fTypeBinding = binding;
28: }
29:
30: public boolean canBeAssignedTo(ConstraintVariable targetVariable) {
31: if (fTypeBinding == null || targetVariable.fTypeBinding == null)
32: return false;
33: return TypeRules.canAssign(fTypeBinding,
34: 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: public String toString() {
47: return toResolvedString();
48: }
49:
50: /**
51: * @return the type binding or <code>null</code>
52: */
53: //TODO: rename to getTypeBinding()
54: public ITypeBinding getBinding() {
55: return fTypeBinding;
56: }
57:
58: /**
59: * For storing additional information associated with constraint variables.
60: * Added in anticipation of the generics-related refactorings.
61: */
62: private Object fData;
63:
64: public Object getData() {
65: return fData;
66: }
67:
68: public void setData(Object data) {
69: fData = data;
70: }
71: }
|