How can I check a PsiMethod has a parameter whose type is String[]?

I want to find out all methods have a parameter whose type is String[] from a class. How can I do it?

Thanks

4 comments

Hello t800t8,

I haven't tested this fragment, but you could try:
-


private static boolean matchingMethod(PsiMethod method) {
PsiParameter[] parameters = method.getParameterList().getParameters();
if(parameters.length != 1) return false;
PsiType type = parameters[0].getType();
if(!type.getDeepComponentType().equalsToText(String.class.getName()))
return false;
return type.getArrayDimensions() == 1;
}
-



Taras


0

Thanks Taras Tielkes. I will try it and inform you later :)

For more clear, what I want to know is how to check a PsiType is a String[] or not. I'm quite not understand PsiType.getJavaLangString() in OpenAPI.

And what will be return if I call getPresentableText() on a String[]? I think it should return "String[]".

0

Or, if you're lazy about these things, just check

parameter.getType().getCanonicalText().equals("java.lang.String[]").

In theory, this would be slower, but probably not in practice.

--Dave Griffith

0

Please sign in to leave a comment.