KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > typeconstraints > ReturnTypeVariable


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 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.jdt.core.dom.IMethodBinding;
16 import org.eclipse.jdt.core.dom.MethodDeclaration;
17 import org.eclipse.jdt.core.dom.ReturnStatement;
18
19 import org.eclipse.jdt.internal.corext.dom.ASTNodes;
20 import org.eclipse.jdt.internal.corext.dom.Bindings;
21
22 public class ReturnTypeVariable extends ConstraintVariable{
23     
24     private final IMethodBinding fMethodBinding;
25
26     public ReturnTypeVariable(ReturnStatement returnStatement) {
27         this(getMethod(returnStatement).resolveBinding());
28         Assert.isNotNull(returnStatement);
29     }
30
31     public ReturnTypeVariable(IMethodBinding methodBinding) {
32         super(methodBinding.getReturnType());
33         fMethodBinding= methodBinding;
34     }
35     
36     public static MethodDeclaration getMethod(ReturnStatement returnStatement) {
37         return (MethodDeclaration)ASTNodes.getParent(returnStatement, MethodDeclaration.class);
38     }
39
40     /* (non-Javadoc)
41      * @see java.lang.Object#toString()
42      */

43     public String JavaDoc toString() {
44         return "[" + Bindings.asString(fMethodBinding) + "]_returnType"; //$NON-NLS-1$ //$NON-NLS-2$
45
}
46     
47     public IMethodBinding getMethodBinding() {
48         return fMethodBinding;
49     }
50
51 }
52
Popular Tags