Brak opisu

Node.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. * @return null|Comment\Doc Doc comment object or null
  87. */
  88. public function getDocComment();
  89. /**
  90. * Sets the doc comment of the node.
  91. *
  92. * This will either replace an existing doc comment or add it to the comments array.
  93. *
  94. * @param Comment\Doc $docComment Doc comment to set
  95. */
  96. public function setDocComment(Comment\Doc $docComment);
  97. /**
  98. * Sets an attribute on a node.
  99. *
  100. * @param string $key
  101. * @param mixed $value
  102. */
  103. public function setAttribute(string $key, $value);
  104. /**
  105. * Returns whether an attribute exists.
  106. *
  107. * @param string $key
  108. *
  109. * @return bool
  110. */
  111. public function hasAttribute(string $key) : bool;
  112. /**
  113. * Returns the value of an attribute.
  114. *
  115. * @param string $key
  116. * @param mixed $default
  117. *
  118. * @return mixed
  119. */
  120. public function getAttribute(string $key, $default = null);
  121. /**
  122. * Returns all the attributes of this node.
  123. *
  124. * @return array
  125. */
  126. public function getAttributes() : array;
  127. /**
  128. * Replaces all the attributes of this node.
  129. *
  130. * @param array $attributes
  131. */
  132. public function setAttributes(array $attributes);
  133. }