Is It Possible To Check Types Passed To A Specific Method?


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?

Comment actions Permalink

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....

Comment actions Permalink

Use PsiViewer plugin to navigate/visualize the tree

com.intellij.psi.JavaElementVisitor#visitMethodCallExpression should be right for your use case



Please sign in to leave a comment.