1 11 package org.eclipse.jdt.apt.core.internal.declaration; 12 13 import java.util.Collection ; 14 import java.util.List ; 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 <TypeParameterDeclaration> getFormalTypeParameters() 46 { 47 return ExecutableUtil.getFormalTypeParameters(this, _env); 48 } 49 50 public Collection <ParameterDeclaration> getParameters() 51 { 52 return ExecutableUtil.getParameters(this, _env); 53 } 54 55 public Collection <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 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 toString() 77 { 78 final StringBuilder buffer = new StringBuilder (); 79 final org.eclipse.jdt.core.dom.MethodDeclaration methodAstNode = getMethodAstNode(); 80 @SuppressWarnings ("unchecked") 81 final List <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(", "); 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 ("unchecked") 99 final List <SingleVariableDeclaration> params = methodAstNode.parameters(); 100 for( SingleVariableDeclaration param : params ){ 101 if( i++ != 0 ) 102 buffer.append(", "); buffer.append(param.getName()); 104 } 105 buffer.append(')'); 106 107 return buffer.toString(); 108 } 109 110 } 111 | Popular Tags |