How can I check a PsiMethod has a parameter whose type is String[]? Permanently deleted user Created September 14, 2006 18:02 I want to find out all methods have a parameter whose type is String[] from a class. How can I do it?Thanks
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
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[]".
It works well. Thanks again
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