1 11 12 package org.eclipse.jdt.apt.core.internal.declaration; 13 14 import com.sun.mirror.declaration.MethodDeclaration; 15 import com.sun.mirror.declaration.ParameterDeclaration; 16 import com.sun.mirror.type.TypeMirror; 17 import com.sun.mirror.util.DeclarationVisitor; 18 19 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv; 20 import org.eclipse.jdt.apt.core.internal.util.Factory; 21 import org.eclipse.jdt.core.dom.IMethodBinding; 22 import org.eclipse.jdt.core.dom.ITypeBinding; 23 24 public class MethodDeclarationImpl extends ExecutableDeclarationImpl implements MethodDeclaration 25 { 26 public MethodDeclarationImpl(final IMethodBinding binding, 27 final BaseProcessorEnv env) 28 { 29 super(binding, env); 30 assert !binding.isConstructor() : "binding does not represent a method."; } 32 33 public TypeMirror getReturnType() 34 { 35 final IMethodBinding methodBinding = getDeclarationBinding(); 36 final ITypeBinding retType = methodBinding.getReturnType(); 37 final TypeMirror type = Factory.createTypeMirror(retType, _env); 38 if(type == null ) 39 return Factory.createErrorClassType(retType); 40 return type; 41 } 42 43 public void accept(DeclarationVisitor visitor) 44 { 45 visitor.visitMethodDeclaration(this); 46 } 47 48 public MirrorKind kind(){ return MirrorKind.METHOD; } 49 50 public String toString() 51 { 52 final StringBuilder buffer = new StringBuilder (); 53 final IMethodBinding methodBinding = getDeclarationBinding(); 54 final ITypeBinding[] typeParams = methodBinding.getTypeParameters(); 55 if( typeParams != null && typeParams.length > 0 ){ 56 buffer.append('<'); 57 for(int i=0; i<typeParams.length; i++ ){ 58 if( i != 0 ) 59 buffer.append(", "); buffer.append(typeParams[i]); 61 } 62 buffer.append('>'); 63 } 64 65 if( methodBinding.getReturnType() != null ) 66 buffer.append(methodBinding.getReturnType().getName()); 67 buffer.append(' '); 68 buffer.append(methodBinding.getName()); 69 buffer.append('('); 70 int i=0; 71 for( ParameterDeclaration param : getParameters() ){ 72 if( i++ != 0 ) 73 buffer.append(", "); buffer.append(param); 75 } 76 buffer.append(')'); 77 78 return buffer.toString(); 79 } 80 } 81 | Popular Tags |