Skip to content

Commit 3e4704f

Browse files
committed
add a new getFQN helper on namespace
1 parent 84fa325 commit 3e4704f

6 files changed

Lines changed: 23 additions & 6 deletions

File tree

src/nodes/class.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Class.prototype.consume = function(file, parent, ast) {
175175

176176
// handle name
177177
this.name = ast.name;
178-
this.fullName = this.getNamespace().name + '\\' + this.name;
178+
this.fullName = this.getNamespace().getFQN(this.name);
179179
this.indexName(this.fullName);
180180

181181
// handle flags

src/nodes/constant.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ Constant.prototype.consume = function(file, parent, ast) {
3131

3232
this.name = ast.name;
3333

34-
if (this.getParent()._type === 'namespace') {
34+
if (
35+
this.getParent()._type === 'class' ||
36+
this.getParent()._type === 'interface' ||
37+
this.getParent()._type === 'trait'
38+
) {
3539
this.fullName = this.getParent().fullName + '::' + this.name;
3640
} else {
37-
this.fullName = this.getNamespace().name + '::' + this.name;
41+
this.fullName = this.getNamespace().getFQN(this.name);
3842
}
3943
this.indexName(this.fullName);
4044

src/nodes/function.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Func.prototype.consume = function(file, parent, ast) {
6161
}
6262
} else {
6363
this.name = ast.name;
64-
this.fullName = this.getNamespace().name + '\\' + this.name;
64+
this.fullName = this.getNamespace().getFQN(this.name);
6565
this.indexName(this.fullName);
6666
}
6767

src/nodes/interface.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Interface.prototype.consume = function(file, parent, ast) {
7575

7676
// handle name
7777
this.name = ast.name;
78-
this.fullName = this.getNamespace().name + '\\' + this.name;
78+
this.fullName = this.getNamespace().getFQN(this.name);
7979

8080
this.indexName(this.name);
8181

src/nodes/namespace.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ Namespace.prototype.consume = function(file, parent, ast) {
2929
this.indexName(this.name);
3030
};
3131

32+
/**
33+
* Converts a namespace relative object name to a fully qualified name
34+
* @return {String}
35+
*/
36+
Namespace.prototype.getFQN = function(name) {
37+
if (name.name) name = name.name;
38+
if (this.name === '\\') {
39+
return '\\' + name;
40+
}
41+
return this.name + '\\' + name;
42+
};
43+
44+
3245
/**
3346
* Retrieves a list of use nodes
3447
*/

src/nodes/trait.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Trait.prototype.consume = function(file, parent, ast) {
4040

4141
// handle name
4242
this.name = ast.name;
43-
this.fullName = this.getNamespace().name + '\\' + this.name;
43+
this.fullName = this.getNamespace().getFQN(this.name);
4444
this.indexName(this.fullName);
4545

4646
// reads inner contents

0 commit comments

Comments
 (0)