This repository was archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathListItem.hack
161 lines (142 loc) · 3.82 KB
/
ListItem.hack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
namespace Facebook\HHAST;
use namespace Facebook\TypeAssert;
use namespace HH\Lib\{Dict, Str};
/* HHAST_IGNORE_ALL[5624] */
final class ListItem<+T as ?Node> extends Node {
const string SYNTAX_KIND = 'list_item';
private T $_item;
private ?Token $_separator;
public function __construct(
T $item,
?Token $separator,
?__Private\SourceRef $source_ref = null,
) {
$this->_item = $item;
$this->_separator = $separator;
parent::__construct($source_ref);
}
<<__Override>>
public static function fromJSON(
dict<arraykey, mixed> $json,
string $file,
int $initial_offset,
string $source,
string $type_hint,
): this {
if (Str\starts_with($type_hint, 'ListItem<')) {
$type_hint = $type_hint
|> Str\strip_prefix($$, 'ListItem<')
|> Str\strip_suffix($$, '>');
} else {
$type_hint = 'Node';
}
$offset = $initial_offset;
$item = Node::fromJSON(
$json['list_item'] as dict<_, _>,
$file,
$offset,
$source,
$type_hint,
);
$offset += $item?->getWidth() ?? 0;
$separator = Node::fromJSON(
$json['list_separator'] as dict<_, _>,
$file,
$offset,
$source,
'Token',
);
$offset += $separator?->getWidth() ?? 0;
$source_ref = shape(
'file' => $file,
'source' => $source,
'offset' => $initial_offset,
'width' => $offset - $initial_offset,
);
return new static(
/* HH_FIXME[4110] Expected T, got ?Node */ $item,
$separator as ?Token,
$source_ref,
);
}
<<__Override>>
public function getChildren(): dict<string, Node> {
return Dict\filter_nulls(dict[
'item' => $this->_item,
'separator' => $this->_separator,
]);
}
<<__Override>>
public function rewriteChildren<Tret as ?Node>(
(function(Node, vec<Node>): Tret) $rewriter,
vec<Node> $parents = vec[],
): ListItem<T> {
$parents[] = $this;
$item = $this->_item === null
? $this->_item
: $rewriter($this->_item, $parents);
$separator = $this->_separator === null
? null
: $rewriter($this->_separator, $parents) as ?Token;
/* HHAST_IGNORE_ERROR[5607] this lint error is a false positive */
if ($item === $this->_item && $separator === $this->_separator) {
return $this;
}
return new static(/* HH_FIXME[4110] */ $item, $separator);
}
public function withItem<Tnode super T as Node>(
Tnode $value,
): ListItem<Tnode> {
if ($value === $this->_item) {
return $this;
}
return new static($value, $this->_separator);
}
public function hasItem(): bool {
return $this->_item !== null;
}
public function getItemUNTYPED(): ?Node {
return $this->_item;
}
public function getItem(): T {
if ($this->_item === null) {
return /* HH_FIXME[4110] trust that T is nullable */ null;
}
return $this->_item;
}
public function getItemx(): T where T as nonnull {
return $this->getItem() as nonnull;
}
public function getSeparatorUNTYPED(): ?Token {
return $this->_separator;
}
public function withSeparator(?Token $value): this {
if ($value === $this->_separator) {
return $this;
}
return new static($this->_item, $value);
}
public function hasSeparator(): bool {
return $this->_separator !== null;
}
/**
* @return null | CommaToken | SemicolonToken | BackslashToken
*/
public function getSeparator(): ?Token {
return $this->_separator;
}
/**
* @return CommaToken | SemicolonToken | BackslashToken
*/
public function getSeparatorx(): Token {
return TypeAssert\not_null($this->getSeparator());
}
}