How to judge PsiType implements java.util.Map

已回答

How to judge a psiType is java.util.Map?

I mean it or its super type extends java.util.Map or implements java.util.Map

0

hello, i think this works:

 

public static boolean isMapType(PsiType psiType, Project project) {
    if (psiType == null || project == null) {
        return false;
    }

    JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    PsiClass mapClass = facade.findClass("java.util.Map", psiType.getResolveScope());

    if (mapClass == null) {
        return false; // Map class not found in the project scope
    }

    PsiClass psiClass = PsiTypesUtil.getPsiClass(psiType);

    if (psiClass == null) {
        return false;
    }

    return InheritanceUtil.isInheritorOrSelf(psiClass, mapClass, true);
}
0

Bro, great help!

0

请先登录再写评论。