private static boolean castClassMatches(PsiType type, String className) {
    if (type instanceof PsiPrimitiveType) {
      return className.equals(((PsiPrimitiveType)type).getBoxedTypeName());
    }
    if (type instanceof PsiIntersectionType) {
      for (PsiType conjunct : ((PsiIntersectionType)type).getConjuncts()) {
        if (castClassMatches(conjunct, className)) return true;
      }
      return false;
    }
    if (type instanceof PsiArrayType) {
      if (className.startsWith("[") && className.length() > 1) {
        PsiType componentType = ((PsiArrayType)type).getComponentType();
        char descriptorChar = className.charAt(1);
        PsiPrimitiveType expected = PsiPrimitiveType.fromJvmTypeDescriptor(descriptorChar);
        if (expected != null) {
          return componentType.equals(expected);
        }
        if (descriptorChar == '[') {
          return castClassMatches(componentType, className.substring(1));
        }
        if (descriptorChar == 'L' && className.charAt(className.length() - 1) == ';') {
          return castClassMatches(componentType, className.substring(2, className.length() - 1));
        }
        return false;
      }
    }
    if (type instanceof PsiClassType) {
      return classTypeMatches(className, (PsiClassType)type, new HashSet<>());
    }
    return true;
  }
private static boolean castClassMatches(PsiType type, String className)