How to check PsiMethod is invoked?
Answered
I have a class like this:
public class ChainClass {
public ChainClass methodA() {return this;}
public ChainClass methodB() {return this;}
public ChainClass methodC() {return this;}
pubilc ChainClass methodD() {return this;}
}
I want to provide a Annotator or other component, can provide a feature:
If PsiMethod -> methodD is invoked, I should check PsiMethod -> methodA() are they called at the same time, then prompt an error.
eg:
ChainClass cc = new ChainClass()
.methodD()
.methodA();
It's ok!
ChainClass cc = new ChainClass()
.methodD();
It's not ok, should prompt an error!
Please sign in to leave a comment.
You can use Annotator or Inspection to perform such highlighting https://plugins.jetbrains.com/docs/intellij/syntax-highlighting-and-error-highlighting.html#annotator.
You'll need to write code to navigate the PSI method calls and act accordingly. If you want to find all usages of a given method, you can use ReferencesSearch.