boolean visitName ( NodeTraversal t , Node n , Node parent ) { // At this stage, we need to determine whether this is a leaf // node in an expression (which therefore needs to have a type // assigned for it) versus some other decorative node that we // can safely ignore. Function names, arguments (children of PARAM_LIST nodes) and // variable declarations are ignored. // TODO(user): remove this short-circuiting in favor of a // pre order traversal of the FUNCTION, CATCH, PARAM_LIST and VAR nodes. Token parentNodeType = parent . getToken ( ) ; if ( parentNodeType == Token . FUNCTION || parentNodeType == Token . CATCH || parentNodeType == Token . PARAM_LIST || NodeUtil . isNameDeclaration ( parent ) ) { return false ; } // Not need to type first key in for-in or for-of. if ( NodeUtil . isEnhancedFor ( parent ) && parent . getFirstChild ( ) == n ) { return false ; } JSType type = n . getJSType ( ) ; if ( type == null ) { type = getNativeType ( UNKNOWN_TYPE ) ; TypedVar var = t . getTypedScope ( ) . getVar ( n . getString ( ) ) ; if ( var != null ) { JSType varType = var . getType ( ) ; if ( varType != null ) { type = varType ; } } } ensureTyped ( n , type ) ; return true ; }
Visits a NAME node .