Eclipse JDT を使用して ICompilationUnit に注釈が存在するかどうかを確認する簡単な方法はありますか?
以下のコードを実行しようとしましたが、スーパー クラスについても同じことを行う必要があります。
IResource resource = ...;
ICompilationUnit cu = (ICompilationUnit) JavaCore.create(resource);
// consider only the first class of the compilation unit
IType firstClass = cu.getTypes()[0];
// first check if the annotation is pressent by its full id
if (firstClass.getAnnotation("java.lang.Deprecated").exists()) {
return true;
}
// then, try to find the annotation by the simple name and confirms if the full name is in the imports
if (firstClass.getAnnotation("Deprecated").exists() && //
cu.getImport("java.lang.Deprecated").exists()) {
return true;
}
ASTParser を使用してバインドを解決できることはわかっていますが、注釈が存在するかどうかを確認する方法が見つかりませんでした。そのようなことを行うための簡単な API はありますか?