PsiType (@NotNull PsiVariable variable) { final PsiExpression initializer = variable.getInitializer(); if (initializer == null) return null; final PsiType variableType = variable.getType(); final PsiType initializerType = initializer.getType(); if (!(variableType instanceof PsiClassType variableClassType)) return null; if (!variableClassType.isRaw()) return null; if (!(initializerType instanceof PsiClassType initializerClassType)) return null; if (initializerClassType.isRaw()) return null; final PsiClassType.ClassResolveResult variableResolveResult = variableClassType.resolveGenerics(); final PsiClassType.ClassResolveResult initializerResolveResult = initializerClassType.resolveGenerics(); if (initializerResolveResult.getElement() == null) return null; PsiClass variableResolved = variableResolveResult.getElement(); if (variableResolved == null) return null; PsiSubstitutor targetSubstitutor = TypeConversionUtil .getClassSubstitutor(variableResolved, initializerResolveResult.getElement(), initializerResolveResult.getSubstitutor()); if (targetSubstitutor == null) return null; PsiType type = JavaPsiFacade.getElementFactory(variable.getProject()).createType(variableResolved, targetSubstitutor); if (variableType.equals(type)) return null; return type; }