Page MenuHomePhabricator

D9792.id23505.diff
No OneTemporary

D9792.id23505.diff

diff --git a/src/applications/diviner/atomizer/DivinerPHPAtomizer.php b/src/applications/diviner/atomizer/DivinerPHPAtomizer.php
--- a/src/applications/diviner/atomizer/DivinerPHPAtomizer.php
+++ b/src/applications/diviner/atomizer/DivinerPHPAtomizer.php
@@ -13,10 +13,38 @@
$file_data,
$future->resolve());
- $atoms = array();
-
$root = $tree->getRootNode();
+ $ns_declarations = $root->selectDescendantsOfType('n_NAMESPACE');
+
+ if (!count($ns_declarations)) {
+ return $this->atomizeNodeInNS($file_name, $root, null);
+ }
+
+ $atom_vectors = array();
+
+ foreach ($ns_declarations as $ns_declaration) {
+ if ($ns = $ns_declaration->getChildByIndex(0)->getConcreteString()) {
+ $ns .= '\\'; // A trailing NS separator is necessary
+ }
+ else {
+ $ns = null;
+ }
+
+ $ns_root = $ns_declaration; // "namespace Foo { }" has children
+ // "namespace Foo;" has siblings, just atomize the root node
+ if ($ns_dec->getChildByIndex(1)->getTypeName() == 'n_EMPTY') {
+ $ns_root = $root;
+ }
+ $atom_vectors[] = $this->atomizeNodeInNS($file_name,
+ $ns, $ns_root);
+ }
+
+ return array_mergev($atom_vectors);
+ }
+
+ private function atomizeNodeInNS($file_name, XHPASTNode $root, $namespace) {
+ $atoms = array();
$func_decl = $root->selectDescendantsOfType('n_FUNCTION_DECLARATION');
foreach ($func_decl as $func) {
@@ -28,6 +56,7 @@
}
$atom = $this->newAtom(DivinerAtom::TYPE_FUNCTION)
+ ->setContext($namespace)
->setName($name->getConcreteString())
->setLine($func->getLineNumber())
->setFile($file_name);
@@ -50,6 +79,7 @@
$name = $class->getChildByIndex(1, 'n_CLASS_NAME');
$atom = $this->newAtom($atom_type)
+ ->setContext($namespace)
->setName($name->getConcreteString())
->setFile($file_name)
->setLine($class->getLineNumber());
@@ -112,6 +142,7 @@
$this->parseParams($matom, $method);
+ $matom->setContext($namespace);
$matom->setName($method->getChildByIndex(2)->getConcreteString());
$matom->setLine($method->getLineNumber());
$matom->setFile($file_name);

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 23, 12:42 AM (1 h, 4 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7717631
Default Alt Text
D9792.id23505.diff (2 KB)

Event Timeline