private static @Nullable PsiType inferType(@NotNull PsiVariable variable) {
    if (variable instanceof PsiParameter && variable.getParent() instanceof PsiForeachStatement foreach) {
      PsiExpression iteratedValue = foreach.getIteratedValue();
      return iteratedValue != null ? JavaGenericsUtil.getCollectionItemType(iteratedValue) : null;
    }
    else if (variable instanceof PsiLocalVariable) {
      PsiExpression initializer = variable.getInitializer();
      if (initializer == null) return null;
      PsiType type = initializer.getType();
      return PsiTypesUtil.isDenotableType(type, variable) && !PsiTypes.voidType().equals(type) ? type : null;
    }
    return null;
  }
private static @Nullable PsiType inferType(@NotNull PsiVariable variable)