finding a statement within a PsiMethod

Hello

I'm within LocalInspectionTool#checkMethod(PsiMethod, InspectionManager, boolean) and would like to see if there is a statement with the 'pattern' Collection.add(String), e.g. list.add("foo") where list is of type Collection.

Can anybody give me a hint on how to find such statements within a given PsiMethod? That would be great.

Thanks in advance for any help!

etienne

1 comment
Comment actions Permalink

Use the JavaElementVisitor#visitMethodCallExpression(PsiMethodCallExpression) callback and visit the method with a PsiRecursiveElementVisitor.

PsiRecursiveElementVisitor visitor = new PsiRecursiveElementVisitor() {
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
...
}
}
method.accept(visitor);

Answering my own question here...

0

Please sign in to leave a comment.