1 11 package org.eclipse.jdt.apt.core.internal.declaration; 12 13 import java.lang.annotation.Annotation ; 14 import java.util.Collection ; 15 16 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv; 17 import org.eclipse.jdt.apt.core.internal.util.SourcePositionImpl; 18 import org.eclipse.jdt.core.dom.*; 19 20 import com.sun.mirror.declaration.AnnotationMirror; 21 import com.sun.mirror.declaration.MemberDeclaration; 22 import com.sun.mirror.util.DeclarationVisitor; 23 import com.sun.mirror.util.SourcePosition; 24 25 public abstract class MemberDeclarationImpl extends DeclarationImpl implements MemberDeclaration, EclipseMirrorObject 26 { 27 MemberDeclarationImpl(final IBinding binding, BaseProcessorEnv env) 28 { 29 super(binding, env); 30 } 31 32 public void accept(DeclarationVisitor visitor) 33 { 34 visitor.visitMemberDeclaration(this); 35 } 36 37 public <A extends Annotation > A getAnnotation(Class <A> annotationClass) 38 { 39 final IAnnotationBinding[] instances = getAnnotationInstances(); 40 return _getAnnotation(annotationClass, instances); 41 } 42 43 public Collection <AnnotationMirror> getAnnotationMirrors() 44 { 45 final IAnnotationBinding[] instances = getAnnotationInstances(); 46 return _getAnnotationMirrors(instances); 47 } 48 49 private IAnnotationBinding[] getAnnotationInstances() 50 { 51 final IBinding binding = getDeclarationBinding(); 52 final IAnnotationBinding[] instances; 53 switch( binding.getKind() ) 54 { 55 case IBinding.TYPE: 56 instances = ((ITypeBinding)binding).getAnnotations(); 57 break; 58 case IBinding.METHOD: 59 instances = ((IMethodBinding)binding).getAnnotations(); 60 break; 61 case IBinding.VARIABLE: 62 instances = ((IVariableBinding)binding).getAnnotations(); 63 break; 64 case IBinding.PACKAGE: 65 return null; 67 default: 68 throw new IllegalStateException (); 69 } 70 return instances; 71 } 72 73 public String getDocComment() 74 { 75 if( isFromSource()){ 76 final ASTNode node = getAstNode(); 77 if(node != null){ 78 if( node instanceof BodyDeclaration ) 79 80 return getDocComment((BodyDeclaration)node); 81 82 else if( node.getNodeType() == ASTNode.VARIABLE_DECLARATION_FRAGMENT ){ 83 final ASTNode parent = node.getParent(); 84 if( parent instanceof BodyDeclaration ) 86 return getDocComment((BodyDeclaration)parent); 87 88 } 89 return ""; } 91 } 92 return null; 93 } 94 95 101 public SourcePosition getPosition() 102 { 103 if( isFromSource() ){ 104 final ASTNode node = getRangeNode(); 105 if( node == null ) return null; 106 final CompilationUnit unit = getCompilationUnit(); 107 final int start = node.getStartPosition(); 108 return new SourcePositionImpl(start, 109 node.getLength(), 110 unit.getLineNumber(start), 111 unit.getColumnNumber(start), 112 this); 113 } 114 return null; 115 } 116 } 117 | Popular Tags |