My current thoughts are to walk the tree in post-order.
Track 0 or 1 doc comments, ignoring regular comments
-
If there is a doc comment, replace the previous comment
-
If there is a closure/method/function/class/etc (Anything where reflection would return a doc comment) and there is an applicable phpdoc2 tag (Or one the caller recognizes), then apply it.
(Or just any phpdoc2 tag)
/** @param $y */ $x = function($y) {}
-
If there is an @var tag, and a variable is seen, then annotate that variable as having that type, somehow (passed in or assigned to)