Skip to content

Commit 15c13f9

Browse files
committed
Merge branch 'feature/github-pull-17' into develop
2 parents 251d5f0 + 8666c82 commit 15c13f9

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

PHPCtags.class.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class PHPCtags
1515
'd' => 'constant',
1616
'v' => 'variable',
1717
'i' => 'interface',
18+
'n' => 'namespace',
1819
);
1920

2021
private $mParser;
@@ -182,9 +183,11 @@ private function struct($node, $reset=FALSE, $parent=array())
182183
$this->struct($subNode, FALSE, array('interface' => $name));
183184
}
184185
} elseif ($node instanceof PHPParser_Node_Stmt_Namespace) {
185-
//@todo
186+
$kind = 'n';
187+
$name = $node->name;
188+
$line = $node->getLine();
186189
foreach ($node as $subNode) {
187-
$this->struct($subNode);
190+
$this->struct($subNode, FALSE, array('namespace' => $name));
188191
}
189192
} elseif ($node instanceof PHPParser_Node_Expr_Assign) {
190193
if (is_string($node->var->name)) {
@@ -283,19 +286,39 @@ private function render()
283286

284287
#field=s
285288
if (in_array('s', $this->mOptions['fields']) && !empty($struct['scope'])) {
289+
// $scope, $type, $name are current scope variables
286290
$scope = array_pop($struct['scope']);
287291
list($type, $name) = each($scope);
288292
switch ($type) {
293+
case 'class':
294+
// n_* stuffs are namespace related scope variables
295+
// current > class > namespace
296+
$n_scope = array_pop($struct['scope']);
297+
if(!empty($n_scope)) {
298+
list($n_type, $n_name) = each($n_scope);
299+
$s_str = 'class:' . $n_name . '\\' . $name;
300+
} else {
301+
$s_str = 'class:' . $name;
302+
}
303+
break;
289304
case 'method':
290-
$scope = array_pop($struct['scope']);
291-
list($p_type, $p_name) = each($scope);
292-
$scope = 'method:' . $p_name . '::' . $name;
305+
// c_* stuffs are class related scope variables
306+
// current > method > class > namespace
307+
$c_scope = array_pop($struct['scope']);
308+
list($c_type, $c_name) = each($c_scope);
309+
$n_scope = array_pop($struct['scope']);
310+
if(!empty($n_scope)) {
311+
list($n_type, $n_name) = each($n_scope);
312+
$s_str = 'method:' . $n_name . '\\' . $c_name . '::' . $name;
313+
} else {
314+
$s_str = 'method:' . $c_name . '::' . $name;
315+
}
293316
break;
294317
default:
295-
$scope = $type . ':' . $name;
318+
$s_str = $type . ':' . $name;
296319
break;
297320
}
298-
$str .= "\t" . $scope;
321+
$str .= "\t" . $s_str;
299322
}
300323

301324
#field=a

0 commit comments

Comments
 (0)