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.ASTNode; 17 import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; 18 import org.eclipse.jdt.core.dom.BodyDeclaration; 19 import org.eclipse.jdt.core.dom.ITypeBinding; 20 import com.sun.mirror.declaration.MemberDeclaration; 21 import com.sun.mirror.declaration.TypeDeclaration; 22 import com.sun.mirror.util.DeclarationVisitor; 23 24 public abstract class ASTBasedMemberDeclarationImpl 25 extends ASTBasedDeclarationImpl implements MemberDeclaration{ 26 27 public ASTBasedMemberDeclarationImpl( 28 ASTNode astNode, 29 IFile file, 30 BaseProcessorEnv env) 31 { 32 super(astNode, file, env); 33 } 34 35 public void accept(DeclarationVisitor visitor) { 36 visitor.visitMemberDeclaration(this); 37 } 38 39 public TypeDeclaration getDeclaringType() 40 { 41 final AbstractTypeDeclaration parentType = getContainingTypeAstNode(); 42 if( parentType == null ) 44 return null; 45 46 final ITypeBinding parentTypeBinding = parentType.resolveBinding(); 47 if( parentTypeBinding == null ) 48 throw new UnsupportedOperationException ("Type declaration that doesn't have binding"); return Factory.createReferenceType(parentTypeBinding, _env); 50 } 51 52 public String getDocComment() 53 { 54 final ASTNode node = getAstNode(); 55 56 if( node instanceof BodyDeclaration ) 57 return getDocComment((BodyDeclaration)node); 58 59 else if( node.getNodeType() == ASTNode.VARIABLE_DECLARATION_FRAGMENT ){ 60 final ASTNode parent = node.getParent(); 61 if( parent instanceof BodyDeclaration ) 63 return getDocComment((BodyDeclaration)parent); 64 65 } 66 return EMPTY_STRING; 67 } 68 69 73 protected AbstractTypeDeclaration getContainingTypeAstNode() 74 { 75 ASTNode cur = _astNode; 76 while(cur != null){ 77 switch(cur.getNodeType()){ 78 case ASTNode.ANNOTATION_TYPE_DECLARATION: 79 case ASTNode.ENUM_DECLARATION: 80 case ASTNode.TYPE_DECLARATION: 81 return (AbstractTypeDeclaration)cur; 82 } 83 cur = cur.getParent(); 84 } 85 return null; 86 } 87 } 88 | Popular Tags |