1 11 12 package org.eclipse.jdt.apt.core.internal.declaration; 13 14 import com.sun.mirror.declaration.AnnotationMirror; 15 import com.sun.mirror.declaration.Modifier; 16 import com.sun.mirror.declaration.ParameterDeclaration; 17 import com.sun.mirror.type.TypeMirror; 18 import com.sun.mirror.util.DeclarationVisitor; 19 import com.sun.mirror.util.SourcePosition; 20 21 import java.lang.annotation.Annotation ; 22 import java.util.Collection ; 23 import java.util.Collections ; 24 25 import org.eclipse.core.resources.IFile; 26 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv; 27 import org.eclipse.jdt.apt.core.internal.util.Factory; 28 import org.eclipse.jdt.core.dom.ASTNode; 29 import org.eclipse.jdt.core.dom.IBinding; 30 import org.eclipse.jdt.core.dom.IMethodBinding; 31 import org.eclipse.jdt.core.dom.IAnnotationBinding; 32 import org.eclipse.jdt.core.dom.ITypeBinding; 33 import org.eclipse.jdt.core.dom.SimpleName; 34 import org.eclipse.jdt.core.dom.SingleVariableDeclaration; 35 36 39 public class BinaryParameterDeclarationImpl extends DeclarationImpl implements ParameterDeclaration 40 { 41 static final String ARG = "arg"; private final ITypeBinding _type; 43 private final ExecutableDeclarationImpl _executable; 44 private final int _paramIndex; 45 48 public BinaryParameterDeclarationImpl(ExecutableDeclarationImpl executable, 49 ITypeBinding typeBinding, 50 int index, 51 BaseProcessorEnv env) 52 { 53 super(typeBinding, env); 54 assert( typeBinding != null ) : "missing type binding"; assert( index >= 0 ) : "invalid index " + index; assert executable != null : "missing executable"; _type = typeBinding; 58 _paramIndex = index; 59 _executable = executable; 60 } 61 62 public void accept(DeclarationVisitor visitor) 63 { 64 visitor.visitParameterDeclaration(this); 65 } 66 67 public Collection <Modifier> getModifiers() 68 { 69 return Collections.emptyList(); 72 } 73 74 public String getDocComment() 75 { 76 return null; 77 } 78 79 public String getSimpleName() 80 { 81 final SingleVariableDeclaration decl = (SingleVariableDeclaration)getAstNode(); 82 if( decl == null ) return ARG + _paramIndex; 83 final SimpleName name = decl.getName(); 84 return name == null ? ARG : name.toString(); 85 } 86 87 public SourcePosition getPosition() 88 { 89 return null; 90 } 91 92 public TypeMirror getType() 93 { 94 final TypeMirror mirrorType = Factory.createTypeMirror(getTypeBinding(), _env); 95 if( mirrorType == null ) 96 return Factory.createErrorClassType(getTypeBinding()); 97 return mirrorType; 98 } 99 100 public <A extends Annotation > A getAnnotation(Class <A> annotationClass) 101 { 102 final IMethodBinding methodBinding = _executable.getDeclarationBinding(); 103 final IAnnotationBinding[] paramAnnos = methodBinding.getParameterAnnotations(_paramIndex); 104 return _getAnnotation(annotationClass, paramAnnos); 105 } 106 107 public Collection <AnnotationMirror> getAnnotationMirrors() 108 { 109 final IMethodBinding methodBinding = _executable.getDeclarationBinding(); 110 final IAnnotationBinding[] paramAnnos = methodBinding.getParameterAnnotations(_paramIndex); 111 return _getAnnotationMirrors(paramAnnos); 112 } 113 114 public boolean isBindingBased(){ return true; } 115 116 public boolean isFromSource(){ return false; } 117 118 ASTNode getAstNode(){ return null; } 119 120 public IFile getResource(){ return null; } 121 122 private ITypeBinding getTypeBinding(){ return _type; } 123 124 public MirrorKind kind(){ return MirrorKind.FORMAL_PARAMETER; } 125 126 public IBinding getDeclarationBinding(){ 127 throw new UnsupportedOperationException ("should never be invoked on a BinaryParameterDeclaration"); } 129 130 public boolean equals(Object obj){ 131 if( obj instanceof BinaryParameterDeclarationImpl ){ 132 final BinaryParameterDeclarationImpl otherParam = (BinaryParameterDeclarationImpl)obj; 133 return otherParam._paramIndex == _paramIndex && 134 otherParam._executable.getDeclarationBinding().isEqualTo(_executable.getDeclarationBinding()) ; 135 } 136 return false; 137 } 138 139 public int hashCode(){ 140 final String methodKey = _executable.getDeclarationBinding().getKey(); 141 int hashcode = 0; 142 if( methodKey != null ) 143 hashcode = methodKey.hashCode(); 144 return hashcode + _paramIndex; 145 } 146 147 public String toString(){ 148 final StringBuilder builder = new StringBuilder (); 149 builder.append(getTypeBinding().getName()); 150 builder.append(' '); 151 builder.append(getSimpleName()); 152 return builder.toString(); 153 } 154 } 155 | Popular Tags |