Check if PsiType is a generic type
Answered
For example in
public String<T> getId(T obj)
How do I check if `T` is a generic type (and not just a class named T)?
Or in a more complicated scenario:
public String<T> getId(T[] obj)
Check if T[] is an array of generics, and not an array of normal classes.
Please sign in to leave a comment.
Did you ever find a solution for this?
Hi,
Get PsiTypeElement from the method parameter list and its PsiTypeElement.getInnermostComponentReferenceElement(). Then call PsiJavaCodeReferenceElement.resolve() and check if the resolved element is of PsiTypeParameter type.
Example for your case:
PsiParameter parameter = PsiMethod.getParametersList().getParameter(n); // where n - index of the checked parameter
PsiTypeElement typeElement = parameter.getTypeElement();
PsiJavaCodeReferenceElement = referenceElement.getInnermostComponentReferenceElement();
PsiElement resolved = referenceElement.resolve();
boolean isGeneric = resolved instanceof PsiTypeParameter;