| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace PhpParser; |
| 4: | |
| 5: | interface Node { |
| 6: | /** |
| 7: | * Gets the type of the node. |
| 8: | * |
| 9: | * @psalm-return non-empty-string |
| 10: | * @return string Type of the node |
| 11: | */ |
| 12: | public function getType(): string; |
| 13: | |
| 14: | /** |
| 15: | * Gets the names of the sub nodes. |
| 16: | * |
| 17: | * @return string[] Names of sub nodes |
| 18: | */ |
| 19: | public function getSubNodeNames(): array; |
| 20: | |
| 21: | /** |
| 22: | * Gets line the node started in (alias of getStartLine). |
| 23: | * |
| 24: | * @return int Start line (or -1 if not available) |
| 25: | * @phpstan-return -1|positive-int |
| 26: | * |
| 27: | * @deprecated Use getStartLine() instead |
| 28: | */ |
| 29: | public function getLine(): int; |
| 30: | |
| 31: | /** |
| 32: | * Gets line the node started in. |
| 33: | * |
| 34: | * Requires the 'startLine' attribute to be enabled in the lexer (enabled by default). |
| 35: | * |
| 36: | * @return int Start line (or -1 if not available) |
| 37: | * @phpstan-return -1|positive-int |
| 38: | */ |
| 39: | public function getStartLine(): int; |
| 40: | |
| 41: | /** |
| 42: | * Gets the line the node ended in. |
| 43: | * |
| 44: | * Requires the 'endLine' attribute to be enabled in the lexer (enabled by default). |
| 45: | * |
| 46: | * @return int End line (or -1 if not available) |
| 47: | * @phpstan-return -1|positive-int |
| 48: | */ |
| 49: | public function getEndLine(): int; |
| 50: | |
| 51: | /** |
| 52: | * Gets the token offset of the first token that is part of this node. |
| 53: | * |
| 54: | * The offset is an index into the array returned by Lexer::getTokens(). |
| 55: | * |
| 56: | * Requires the 'startTokenPos' attribute to be enabled in the lexer (DISABLED by default). |
| 57: | * |
| 58: | * @return int Token start position (or -1 if not available) |
| 59: | */ |
| 60: | public function getStartTokenPos(): int; |
| 61: | |
| 62: | /** |
| 63: | * Gets the token offset of the last token that is part of this node. |
| 64: | * |
| 65: | * The offset is an index into the array returned by Lexer::getTokens(). |
| 66: | * |
| 67: | * Requires the 'endTokenPos' attribute to be enabled in the lexer (DISABLED by default). |
| 68: | * |
| 69: | * @return int Token end position (or -1 if not available) |
| 70: | */ |
| 71: | public function getEndTokenPos(): int; |
| 72: | |
| 73: | /** |
| 74: | * Gets the file offset of the first character that is part of this node. |
| 75: | * |
| 76: | * Requires the 'startFilePos' attribute to be enabled in the lexer (DISABLED by default). |
| 77: | * |
| 78: | * @return int File start position (or -1 if not available) |
| 79: | */ |
| 80: | public function getStartFilePos(): int; |
| 81: | |
| 82: | /** |
| 83: | * Gets the file offset of the last character that is part of this node. |
| 84: | * |
| 85: | * Requires the 'endFilePos' attribute to be enabled in the lexer (DISABLED by default). |
| 86: | * |
| 87: | * @return int File end position (or -1 if not available) |
| 88: | */ |
| 89: | public function getEndFilePos(): int; |
| 90: | |
| 91: | /** |
| 92: | * Gets all comments directly preceding this node. |
| 93: | * |
| 94: | * The comments are also available through the "comments" attribute. |
| 95: | * |
| 96: | * @return Comment[] |
| 97: | */ |
| 98: | public function getComments(): array; |
| 99: | |
| 100: | /** |
| 101: | * Gets the doc comment of the node. |
| 102: | * |
| 103: | * @return null|Comment\Doc Doc comment object or null |
| 104: | */ |
| 105: | public function getDocComment(): ?Comment\Doc; |
| 106: | |
| 107: | /** |
| 108: | * Sets the doc comment of the node. |
| 109: | * |
| 110: | * This will either replace an existing doc comment or add it to the comments array. |
| 111: | * |
| 112: | * @param Comment\Doc $docComment Doc comment to set |
| 113: | */ |
| 114: | public function setDocComment(Comment\Doc $docComment): void; |
| 115: | |
| 116: | /** |
| 117: | * Sets an attribute on a node. |
| 118: | * |
| 119: | * @param mixed $value |
| 120: | */ |
| 121: | public function setAttribute(string $key, $value): void; |
| 122: | |
| 123: | /** |
| 124: | * Returns whether an attribute exists. |
| 125: | */ |
| 126: | public function hasAttribute(string $key): bool; |
| 127: | |
| 128: | /** |
| 129: | * Returns the value of an attribute. |
| 130: | * |
| 131: | * @param mixed $default |
| 132: | * |
| 133: | * @return mixed |
| 134: | */ |
| 135: | public function getAttribute(string $key, $default = null); |
| 136: | |
| 137: | /** |
| 138: | * Returns all the attributes of this node. |
| 139: | * |
| 140: | * @return array<string, mixed> |
| 141: | */ |
| 142: | public function getAttributes(): array; |
| 143: | |
| 144: | /** |
| 145: | * Replaces all the attributes of this node. |
| 146: | * |
| 147: | * @param array<string, mixed> $attributes |
| 148: | */ |
| 149: | public function setAttributes(array $attributes): void; |
| 150: | } |
| 151: |