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