Look for psi method annotations with plugin
I am trying to build a plugin that gives me all the names of functions in a file that have a the Junit.Test annotation. So this example class would return testFunction and testFunction2 but not testFunction3.
public class ThisIsMyFIrstTestClass {
@Test
public void testFunction(){
}
@Test
public void testFunction2(){
}
public void testFunction3(){
}
}
I then use this function to get my methods:
PsiJavaFile psi = (PsiJavaFile) e.getData(LangDataKeys.PSI_FILE);
PsiMethod[] methods = psi.getClasses()[0].getMethods();
Now All I want to do is something like the code below but the method isAnnotationPresent is not allowed on the PsiMethod object. Do anyone know how this is done?
ArrayList<String> testFunctions = new ArrayList<String>();
PsiMethod[] methods = psi.getClasses()[0].getMethods();
for (PsiMethod method : methods){
if (method.isAnnotationPresent()){
testFunctions.add(method.getName());
}
}
Please sign in to leave a comment.
Please see various com.intellij.codeInsight.AnnotationUtil#isAnnotated() variants