1 11 package org.eclipse.jdt.apt.core.internal.declaration; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv; 15 import org.eclipse.jdt.apt.core.internal.util.Factory; 16 import org.eclipse.jdt.core.dom.ITypeBinding; 17 import org.eclipse.jdt.core.dom.IVariableBinding; 18 import org.eclipse.jdt.core.dom.Name; 19 import org.eclipse.jdt.core.dom.SingleVariableDeclaration; 20 import org.eclipse.jdt.core.dom.Type; 21 22 import com.sun.mirror.declaration.ParameterDeclaration; 23 import com.sun.mirror.type.TypeMirror; 24 import com.sun.mirror.util.DeclarationVisitor; 25 26 29 public class SourceParameterDeclarationImpl 30 extends ASTBasedDeclarationImpl implements ParameterDeclaration{ 31 32 38 public SourceParameterDeclarationImpl(SingleVariableDeclaration astNode, 39 IFile file, 40 BaseProcessorEnv env) 41 { 42 super( astNode, file, env); 43 } 44 45 public void accept(DeclarationVisitor visitor) 46 { 47 visitor.visitParameterDeclaration(this); 48 } 49 50 public TypeMirror getType() 51 { 52 final SingleVariableDeclaration astNode = getAstNode(); 53 final Type type = astNode.getType(); 54 if( type == null ) 55 return Factory.createErrorClassType(EMPTY_STRING); 56 final IVariableBinding varBinding = astNode.resolveBinding(); 57 if( varBinding == null ){ 58 String typeName = type.toString(); 59 if( astNode.isVarargs() ) 60 return Factory.createErrorArrayType(typeName, 1); 61 else 62 return Factory.createErrorClassType(typeName); 63 } 64 else{ 65 final ITypeBinding typeBinding = varBinding.getType(); 66 if( typeBinding == null ){ 67 String typeName = type.toString(); 68 if( astNode.isVarargs() ) 69 return Factory.createErrorArrayType(typeName, 1); 70 else 71 return Factory.createErrorClassType(typeName); 72 } 73 else{ 74 final TypeMirror mirrorType = Factory.createTypeMirror(typeBinding, _env); 75 if(mirrorType == null ) 76 return Factory.createErrorClassType(type.toString()); 77 return mirrorType; 78 } 79 } 80 } 81 82 public String getSimpleName() 83 { 84 final Name nameNode = getAstNode().getName(); 85 return nameNode == null ? EMPTY_STRING : nameNode.toString(); 86 } 87 88 public String getDocComment() 89 { 90 return EMPTY_STRING; 91 } 92 93 SingleVariableDeclaration getAstNode() 94 { 95 return (SingleVariableDeclaration)_astNode; 96 } 97 98 public MirrorKind kind(){ return MirrorKind.FORMAL_PARAMETER; } 99 100 public String toString(){ 101 return _astNode.toString(); 102 } 103 104 public boolean equals(Object obj){ 105 if( obj instanceof SourceParameterDeclarationImpl ){ 106 final SourceParameterDeclarationImpl otherParam = (SourceParameterDeclarationImpl)obj; 107 return _astNode == otherParam._astNode; 108 } 109 return false; 110 } 111 112 public int hashCode(){ 113 return _astNode.hashCode(); 114 } 115 } 116 117 118 | Popular Tags |