Node.php 4.0 KB

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