Node.php 3.9 KB

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