boolean (PsiElement element) { if (!(element instanceof PsiTypeElement)) { return false; } final PsiElement parent = element.getParent(); if (!(parent instanceof PsiVariable variable)) { return false; } final PsiExpression initializer = variable.getInitializer(); if (!(initializer instanceof PsiNewExpression)) { return false; } final PsiType type = variable.getType(); if (!(type instanceof PsiClassType classType)) { return false; } final PsiType initializerType = initializer.getType(); if (!(initializerType instanceof PsiClassType initializerClassType)) { return false; } PsiClass initializerClass = initializerClassType.resolve(); if (initializerClass instanceof PsiAnonymousClass) { initializerClass = initializerClass.getSuperClass(); } if (initializerClass == null) { return false; } final PsiClass variableClass = classType.resolve(); if (variableClass == null) { return false; } if (variableClass.equals(initializerClass)) { return false; } if (!initializerClass.isInheritor(variableClass, true)) { return false; } return true; }