KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > apt > core > internal > declaration > ASTBasedMethodDeclarationImpl


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 BEA Systems, Inc.
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  * tyeung@bea.com - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.apt.core.internal.declaration;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv;
15 import org.eclipse.jdt.apt.core.internal.util.Factory;
16 import org.eclipse.jdt.core.dom.ITypeBinding;
17 import org.eclipse.jdt.core.dom.Type;
18
19 import com.sun.mirror.declaration.MethodDeclaration;
20 import com.sun.mirror.type.TypeMirror;
21 import com.sun.mirror.util.DeclarationVisitor;
22
23 public class ASTBasedMethodDeclarationImpl
24     extends ASTBasedExecutableDeclarationImpl
25     implements MethodDeclaration{
26
27     public ASTBasedMethodDeclarationImpl(
28             final org.eclipse.jdt.core.dom.BodyDeclaration astNode,
29             final IFile file,
30             final BaseProcessorEnv env)
31     {
32         super(astNode, file, env);
33     }
34     
35     public void accept(DeclarationVisitor visitor)
36     {
37         visitor.visitMethodDeclaration(this);
38     }
39     
40     public TypeMirror getReturnType()
41     {
42         final org.eclipse.jdt.core.dom.MethodDeclaration methodAstNode = getMethodAstNode();
43         final Type retType = methodAstNode.getReturnType2();
44         // some funny error case where the return type is missing but it's not a constructor.
45
if( retType == null )
46             return Factory.createErrorClassType(EMPTY_STRING);
47         final ITypeBinding typeBinding = retType.resolveBinding();
48         // This is most likely the reason that we end up with an ast based implementation.
49
if( typeBinding == null ){
50             return Factory.createErrorClassType(retType.toString());
51         }
52         else{
53             final TypeMirror type = Factory.createTypeMirror(typeBinding, _env);
54             if(type == null )
55                 return Factory.createErrorClassType(retType.toString());
56             return type;
57         }
58     }
59     
60     public MirrorKind kind(){ return MirrorKind.METHOD; }
61
62 }
63
Popular Tags