1 11 package org.eclipse.jdt.apt.core.internal.declaration; 12 13 import java.util.Collection ; 14 import java.util.Collections ; 15 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv; 18 import org.eclipse.jdt.apt.core.internal.util.Factory; 19 import org.eclipse.jdt.core.dom.ASTNode; 20 import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration; 21 import org.eclipse.jdt.core.dom.Expression; 22 import org.eclipse.jdt.core.dom.ITypeBinding; 23 import org.eclipse.jdt.core.dom.SimpleName; 24 import org.eclipse.jdt.core.dom.Type; 25 import com.sun.mirror.declaration.AnnotationTypeDeclaration; 26 import com.sun.mirror.declaration.AnnotationTypeElementDeclaration; 27 import com.sun.mirror.declaration.AnnotationValue; 28 import com.sun.mirror.declaration.ParameterDeclaration; 29 import com.sun.mirror.type.TypeMirror; 30 import com.sun.mirror.util.DeclarationVisitor; 31 32 public class ASTBasedAnnotationElementDeclarationImpl 33 extends ASTBasedMethodDeclarationImpl implements AnnotationTypeElementDeclaration{ 34 35 public ASTBasedAnnotationElementDeclarationImpl( 36 final AnnotationTypeMemberDeclaration astNode, 37 final IFile file, 38 final BaseProcessorEnv env) 39 { 40 super(astNode, file, env); 41 } 42 43 public void accept(DeclarationVisitor visitor) { 44 visitor.visitAnnotationTypeElementDeclaration(this); 45 } 46 47 public AnnotationTypeDeclaration getDeclaringType() { 48 return (AnnotationTypeDeclaration) super.getDeclaringType(); 49 } 50 51 58 public AnnotationValue getDefaultValue() { 59 60 final AnnotationTypeMemberDeclaration decl = getMemberAstNode(); 61 if (decl != null){ 62 final Expression defaultExpr = decl.getDefault(); 63 if( defaultExpr != null ) 64 return Factory.createDefaultValue(defaultExpr.resolveConstantExpressionValue(), this, _env); 65 } 66 67 return null; 68 } 69 70 public ASTNode getAstNodeForDefault() { 71 final AnnotationTypeMemberDeclaration decl = (AnnotationTypeMemberDeclaration) getAstNode(); 72 if (decl != null) 73 return decl.getDefault(); 74 75 return null; 76 } 77 78 public boolean isVarArgs(){ return false; } 79 80 public String getSimpleName() 81 { 82 final AnnotationTypeMemberDeclaration memberAstNode = getMemberAstNode(); 83 final SimpleName nameNode = memberAstNode.getName(); 84 return nameNode == null ? EMPTY_STRING : nameNode.getIdentifier(); 85 } 86 87 public TypeMirror getReturnType() 88 { 89 final AnnotationTypeMemberDeclaration memberAstNode = getMemberAstNode(); 90 final Type retType = memberAstNode.getType(); 91 if( retType == null ) 93 return Factory.createErrorClassType(EMPTY_STRING); 94 final ITypeBinding typeBinding = retType.resolveBinding(); 95 if( typeBinding == null ){ 97 return Factory.createErrorClassType(retType.toString()); 98 } 99 else{ 100 final TypeMirror type = Factory.createTypeMirror(typeBinding, _env); 101 if(type == null ) 102 return Factory.createErrorClassType(retType.toString()); 103 return type; 104 } 105 } 106 107 public String toString() 108 { 109 final StringBuilder buffer = new StringBuilder (); 110 final AnnotationTypeMemberDeclaration memberAstNode = (AnnotationTypeMemberDeclaration) getAstNode(); 111 112 if( memberAstNode.getType() != null ) 113 buffer.append(memberAstNode.getType()); 114 buffer.append(' '); 115 buffer.append(memberAstNode.getName()); 116 buffer.append("()"); 118 return buffer.toString(); 119 } 120 121 public Collection <ParameterDeclaration> getParameters() { 122 return Collections.emptyList(); 123 } 124 125 public MirrorKind kind() { 126 return MirrorKind.ANNOTATION_ELEMENT; 127 } 128 129 private AnnotationTypeMemberDeclaration getMemberAstNode(){ 130 return (AnnotationTypeMemberDeclaration)_astNode; 131 } 132 } 133 | Popular Tags |