KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Collection JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv;
18 import org.eclipse.jdt.core.dom.SimpleName;
19 import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
20 import org.eclipse.jdt.core.dom.TypeParameter;
21
22 import com.sun.mirror.declaration.ExecutableDeclaration;
23 import com.sun.mirror.declaration.ParameterDeclaration;
24 import com.sun.mirror.declaration.TypeParameterDeclaration;
25 import com.sun.mirror.type.ReferenceType;
26 import com.sun.mirror.util.DeclarationVisitor;
27
28 public abstract class ASTBasedExecutableDeclarationImpl
29     extends ASTBasedMemberDeclarationImpl
30     implements ExecutableDeclaration{
31     
32     public ASTBasedExecutableDeclarationImpl(
33             final org.eclipse.jdt.core.dom.BodyDeclaration astNode,
34             final IFile file,
35             final BaseProcessorEnv env)
36     {
37         super(astNode, file, env);
38     }
39     
40     public void accept(DeclarationVisitor visitor)
41     {
42         visitor.visitExecutableDeclaration(this);
43     }
44     
45     public Collection JavaDoc<TypeParameterDeclaration> getFormalTypeParameters()
46     {
47         return ExecutableUtil.getFormalTypeParameters(this, _env);
48     }
49     
50     public Collection JavaDoc<ParameterDeclaration> getParameters()
51     {
52         return ExecutableUtil.getParameters(this, _env);
53     }
54
55     public Collection JavaDoc<ReferenceType> getThrownTypes()
56     {
57         return ExecutableUtil.getThrownTypes(this, _env);
58     }
59
60     public boolean isVarArgs()
61     {
62         return getMethodAstNode().isVarargs();
63     }
64
65     public String JavaDoc getSimpleName()
66     {
67         final org.eclipse.jdt.core.dom.MethodDeclaration methodAstNode = getMethodAstNode();
68         final SimpleName nameNode = methodAstNode.getName();
69         return nameNode == null ? EMPTY_STRING : nameNode.getIdentifier();
70     }
71     
72     org.eclipse.jdt.core.dom.MethodDeclaration getMethodAstNode(){
73         return (org.eclipse.jdt.core.dom.MethodDeclaration)_astNode;
74     }
75     
76     public String JavaDoc toString()
77     {
78         final StringBuilder JavaDoc buffer = new StringBuilder JavaDoc();
79         final org.eclipse.jdt.core.dom.MethodDeclaration methodAstNode = getMethodAstNode();
80         @SuppressWarnings JavaDoc("unchecked")
81         final List JavaDoc<TypeParameter> typeParams = methodAstNode.typeParameters();
82         if( typeParams != null && typeParams.size() > 0 ){
83              buffer.append('<');
84              for(int i=0, size=typeParams.size(); i<size; i++ ){
85                  if( i != 0 )
86                      buffer.append(", "); //$NON-NLS-1$
87
buffer.append(typeParams.get(i).toString());
88              }
89              buffer.append('>');
90         }
91
92         if( methodAstNode.getReturnType2() != null )
93             buffer.append(methodAstNode.getReturnType2());
94         buffer.append(' ');
95         buffer.append(methodAstNode.getName());
96         buffer.append('(');
97         int i=0;
98         @SuppressWarnings JavaDoc("unchecked")
99         final List JavaDoc<SingleVariableDeclaration> params = methodAstNode.parameters();
100         for( SingleVariableDeclaration param : params ){
101             if( i++ != 0 )
102                 buffer.append(", "); //$NON-NLS-1$
103
buffer.append(param.getName());
104         }
105         buffer.append(')');
106
107         return buffer.toString();
108     }
109
110 }
111
Popular Tags