Is It Possible To Check Types Passed To A Specific Method? Follow
Answered
I use an RPC method from a third party library that takes the class name and varargs to pass constructor parameters.
Is it possible to write a custom code analysis that is specific to this particular method?
What I would like to do is take the first parameter (which is the class name), use reflection to find out the number of constructor args and their types then compare those to the other parameters that have been passed as varargs.
Can this be done? If so, where do I get started with examples of how to do it?
Please sign in to leave a comment.
Yes, http://www.jetbrains.org/intellij/sdk/docs/tutorials/code_inspections.html gets you started.All this information is available via Java PSI http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/psi.html
So I think I need to extend AbstractBaseJavaLocalInspectionTool.
Which method in JavaElementVisitor should I be implementing?
Maybe visitMethodCallExpression or maybe visitReferenceExpression. I'm not sure.
I need to do the check whenever somebody calls the method doRemote(...) in the class RPC.
I'm also not really sure how to get the constructors of a class once I get the first arg from the parameterList.
The PSI tree is very confusing....
Use PsiViewer plugin to navigate/visualize the tree https://plugins.jetbrains.com/plugin/227-psiviewer
com.intellij.psi.JavaElementVisitor#visitMethodCallExpression should be right for your use case