11/*!
2- * Copyright (C) 2016 Glayzzle (BSD3 License)
2+ * Copyright (C) 2017 Glayzzle (BSD3 License)
33 * @authors https://github.com/glayzzle/php-reflection/graphs/contributors
44 * @url http://glayzzle.com
55 */
6- " use strict" ;
6+ ' use strict' ;
77
88var node = require ( './node' ) ;
99var ptr = require ( './ptr' ) ;
@@ -100,6 +100,15 @@ block.prototype.consumeChild = function(ast) {
100100 }
101101 }
102102
103+ // consome trait
104+ else if ( ast . kind === 'trait' ) {
105+ var trait = ptr . create ( 'trait' , this , ast ) ;
106+ this . traits . push ( trait ) ;
107+ if ( this . type !== 'namespace' ) {
108+ this . getNamespace ( ) . traits . push ( trait ) ;
109+ }
110+ }
111+
103112 // consome a namespace (from inner statements like declare)
104113 else if ( ast . kind === 'namespace' ) {
105114 node . create ( 'namespace' , this . getFile ( ) , ast ) ;
@@ -173,6 +182,29 @@ block.prototype.consumeChild = function(ast) {
173182 ptr . create ( 'define' , this , ast )
174183 ) ;
175184 }
185+
186+ // namespace constants
187+ else if ( ast . kind === 'constant' ) {
188+ this . getNamespace ( ) . constants . push (
189+ ptr . create ( 'constant' , this , ast )
190+ ) ;
191+ }
192+
193+ // namespace use statements
194+ else if ( ast . kind === 'usegroup' ) {
195+ var prefix = ast . name . name ;
196+ for ( var i = 0 ; i < ast . items . length ; i ++ ) {
197+ var alias = ast . items [ i ] . alias ;
198+ var name = ast . items [ i ] . name . name ;
199+ if ( name [ 0 ] !== '\\' ) name = '\\' + name ;
200+ if ( ! alias ) {
201+ alias = name . split ( '\\' ) ;
202+ alias = alias [ alias . length - 1 ] ;
203+ }
204+ this . getNamespace ( ) . uses [ alias ] = prefix + name ;
205+ }
206+ }
207+
176208 // @todo : variables by global statement
177209 // @todo : variables by static statement
178210
@@ -190,23 +222,7 @@ block.prototype.consumeChild = function(ast) {
190222 }
191223 }
192224
193-
194- /* else if (type === 'trait') {
195- this.traits.push(
196- new node.builders['trait'](this, node)
197- );
198- } else if (type === 'call') {
199- if (
200- ast[1][0] === 'ns' &&
201- ast[1][1].length === 1 &&
202- ast[1][1][0] === 'define'
203- ) {
204- this.defines.push(
205- new node.builders['define'](this, node)
206- );
207- }
208- }
209- // @todo use, var */
225+ /* @todo var */
210226} ;
211227
212228module . exports = block ;
0 commit comments