Page MenuHomePhabricator

Add a `getChildrenOfType` method to `AASTNode`
ClosedPublic

Authored by joshuaspence on Sep 24 2014, 11:34 PM.
Tags
None
Referenced Files
F13189974: D10554.diff
Sat, May 11, 6:39 AM
Unknown Object (File)
Fri, May 3, 10:26 AM
Unknown Object (File)
Fri, May 3, 10:26 AM
Unknown Object (File)
Fri, May 3, 10:26 AM
Unknown Object (File)
Wed, May 1, 1:00 AM
Unknown Object (File)
Wed, Apr 17, 6:54 PM
Unknown Object (File)
Tue, Apr 16, 7:19 AM
Unknown Object (File)
Feb 24 2024, 4:50 PM
Subscribers

Details

Summary

This method is similar to getChildren() but allows filtering based on $token->getTypeName().

Test Plan

See D10558.

Diff Detail

Repository
rPHU libphutil
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

joshuaspence retitled this revision from to Add a `getChildrenOfType` method to `AASTNode`.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.
joshuaspence edited edge metadata.

Add some more methods

joshuaspence retitled this revision from Add a `getChildrenOfType` method to `AASTNode` to Add a few methods to `AASTNode`.Sep 25 2014, 2:46 AM

(Let me know if you want me to split this into separate diffs)

joshuaspence retitled this revision from Add a few methods to `AASTNode` to Add a few methods to `AASTNode` and `AASTToken`.Sep 25 2014, 2:57 AM
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
epriestley edited edge metadata.

It looks like D10558 only actually needs something like getNextSemanticToken(). Maybe that's cleaner?

I think you could even getNextToken(), make sure it's isSemantic(), and then use it (i.e., "don't do anything if the next token is whitespace or a comment").

Offhand, one minor issue here is that a semantic token range is potentially the entire file.

These generally seem fine, but maybe consider a simpler approach if there aren't other use cases or you haven't already dismissed it.

This revision is now accepted and ready to land.Sep 25 2014, 1:25 PM

getNextToken() sounds reasonable... possibly I could do the following in D10558 and avoid the need to change AASTNode at all:

$after = last($value->getTokens())->getNextToken();

Actually, getChildrenOfType is still required.

joshuaspence retitled this revision from Add a few methods to `AASTNode` and `AASTToken` to Add a `getChildrenOfType` method to `AASTNode`.Sep 25 2014, 9:16 PM
joshuaspence updated this object.
joshuaspence edited edge metadata.
joshuaspence retitled this revision from Add a `getChildrenOfType` method to `AASTNode` to Add a few methods to `AASTNode` and `AASTToken`.
joshuaspence updated this object.

We only need `getChildrenOfType

joshuaspence retitled this revision from Add a few methods to `AASTNode` and `AASTToken` to Add a `getChildrenOfType` method to `AASTNode`.Sep 25 2014, 9:18 PM
joshuaspence updated this object.
This revision was automatically updated to reflect the committed changes.