2016-10-05 9 views
1

私はIAnnotationインスタンスを持っています。IAnnotation#getElementName()が単純な名前を返す場合、注釈の完全修飾型名を取得するにはどうすればよいですか?JDT ASTを使用して注釈のタイプを取得する方法は?

IAnnotation ruleAnnotation = field.getAnnotation("Rule"); 
    String fullQualifiedName = ??? 
    if (fullQualifiedName.equals("org.junit.Rule")){ 
     ... 
    } 

私はこの答えを見つけましたが、これは異なるユースケースである: How to determine if a class has an annotation using JDT, considering the type hierarchy

答えて

3

あなたはおよそorg.eclipse.jdt.core.IFieldorg.eclipse.jdt.core.IAnnotation(「Javaのモデル」の一部で - ないAST)を話すと仮定すると、あなたが行う必要がありますS。T.これらの線に沿って:

IAnnotation ruleAnnotation = field.getAnnotation("Rule"); 
IType declaringType = field.getDeclaringType(); 
String elementName = ruleAnnotation.getElementName(); 
String[][] fullyQualifiedName = declaringType.resolveType(elementName); 

2次元の配列から修飾名を抽出するためのIType.resolveType(String)のJavadocを参照してください。

関連する問題