How to parse psiMethod.getBody to find something
Answered
What is the best way to parse the Body of a method to find whatever you want?
E.g I have the following code :
public void sample(){
..
..
..
int test;
..
..
}
How i can retrieve the PsiLocalVariable test from this code block?
Please sign in to leave a comment.
You can get a handle to the PsiMethod then have it accept a JavaRecursiveElementVisitor. It has other methods you can override like visitParameter, etc.
method.accept(new JavaRecursiveElementVisitor() {@Override
public void visitLocalVariable(PsiLocalVariable localVariable) {
super.visitLocalVariable(localVariable);
if (localVariable.getName().equals("test") {
//blah
}
}
);