diff --git a/src/parser/aast/api/AASTNodeList.php b/src/parser/aast/api/AASTNodeList.php --- a/src/parser/aast/api/AASTNodeList.php +++ b/src/parser/aast/api/AASTNodeList.php @@ -1,62 +1,21 @@ ids); - } - - public function current() { - return $this->list[$this->key()]; - } - - public function rewind() { - $this->pos = 0; - } - - public function valid() { - return $this->pos < count($this->ids); - } - - public function next() { - $this->pos++; - } - - public function key() { - return $this->ids[$this->pos]; - } - - public static function newFromTreeAndNodes(AASTTree $tree, array $nodes) { - assert_instances_of($nodes, 'AASTNode'); - $obj = new AASTNodeList(); - $obj->tree = $tree; - $obj->list = $nodes; - $obj->ids = array_keys($nodes); - return $obj; - } - - public static function newFromTree(AASTTree $tree) { - $obj = new AASTNodeList(); - $obj->tree = $tree; - $obj->list = array(0 => $tree->getRootNode()); - $obj->ids = array(0 => 0); - return $obj; - } - protected function __construct() {} public function getDescription() { if (empty($this->list)) { - return 'an empty node list'; + return pht('an empty node list'); } $desc = array(); - $desc[] = 'a list of '.count($this->list).' nodes:'; + $desc[] = pht('a list of %s nodes:', new PhutilNumber(count($this->list))); foreach ($this->list as $node) { $desc[] = ' '.$node->getDescription().';'; } @@ -64,12 +23,8 @@ return implode("\n", $desc); } - - protected function newList(array $nodes) { - return AASTNodeList::newFromTreeAndNodes( - $this->tree, - $nodes); + return AASTNodeList::newFromTreeAndNodes($this->tree, $nodes); } public function selectDescendantsOfType($type_name) { @@ -107,7 +62,6 @@ return $this; } - protected function executeSelectDescendantsOfType($node, $type) { $results = array(); foreach ($node->getChildren() as $id => $child) { @@ -132,4 +86,52 @@ return $this->list; } + public static function newFromTreeAndNodes(AASTTree $tree, array $nodes) { + assert_instances_of($nodes, 'AASTNode'); + + $obj = new AASTNodeList(); + $obj->tree = $tree; + $obj->list = $nodes; + $obj->ids = array_keys($nodes); + return $obj; + } + + public static function newFromTree(AASTTree $tree) { + $obj = new AASTNodeList(); + $obj->tree = $tree; + $obj->list = array(0 => $tree->getRootNode()); + $obj->ids = array(0 => 0); + return $obj; + } + + +/* -( Countable )---------------------------------------------------------- */ + + public function count() { + return count($this->ids); + } + + +/* -( Iterator )----------------------------------------------------------- */ + + public function current() { + return $this->list[$this->key()]; + } + + public function key() { + return $this->ids[$this->pos]; + } + + public function next() { + $this->pos++; + } + + public function rewind() { + $this->pos = 0; + } + + public function valid() { + return $this->pos < count($this->ids); + } + }