How to go specific code line
Hi everyone,
I'm trying to develop a plugin. It has a JTable and there are two informations in every row: Class name and Method name. I generate JButton for every row. Every button needs to go given method in the given class. I mean when button pressed it needs to do GoToClass and GoToLine action on editor. But I can't handle action that goes exact line in exact class.
Please give sample with your answers because I'm real newbie in Plugin development and IDEA. I can add my code or pic if needed. I tried Psi files and virtual files but I missed something at every attempt. I can appreciate any help, thank you.
Please sign in to leave a comment.
You can just call com.intellij.util.PsiNavigateUtil#navigate with the PsiMethod
First of all, I do thank you for replies they can save my life as an intern. I tried PsiClass like this and its working like magic:
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
Navigatable navigate = JavaPsiFacade.getInstance(project).findClass("MyString", scope);
OpenSourceUtil.navigate(true,navigate);
My second question is: Is there a way in "navigate" method for move the cursor to given method? Thank you again.
Yes, you have to resolve the corresponding PsiMethod within the PsiClass and pass it as navigation target.
Thank you again for answer. I did this:
PsiMethod[] psi = JavaPsiFacade.getInstance(project).findClass(classAddress.toString(), scope).findMethodsByName(methodName.toString(),true);
if(psi.length >= 0)
{
Navigatable navigate =JavaPsiFacade.getInstance(project).findClass(classAddress.toString(), scope).findMethodsByName(methodName.toString(),true)[0];
OpenSourceUtil.navigate(true,navigate);
}
It doesnt look good but it works. Thanks for your replies.