private void moveMethods ( Collection < NameInfo > allNameInfo ) { boolean hasStubDeclaration = idGenerator . hasGeneratedAnyIds ( ) ; for ( NameInfo nameInfo : allNameInfo ) { if ( ! nameInfo . isReferenced ( ) ) { // The code below can't do anything with unreferenced name // infos. They should be skipped to avoid NPE since their // deepestCommonModuleRef is null. continue ; } if ( nameInfo . readsClosureVariables ( ) ) { continue ; } JSModule deepestCommonModuleRef = nameInfo . getDeepestCommonModuleRef ( ) ; if ( deepestCommonModuleRef == null ) { compiler . report ( JSError . make ( NULL_COMMON_MODULE_ERROR ) ) ; continue ; } Iterator < Symbol > declarations = nameInfo . getDeclarations ( ) . descendingIterator ( ) ; while ( declarations . hasNext ( ) ) { Symbol symbol = declarations . next ( ) ; if ( symbol instanceof PrototypeProperty ) { tryToMovePrototypeMethod ( nameInfo , deepestCommonModuleRef , ( PrototypeProperty ) symbol ) ; } else if ( symbol instanceof ClassMemberFunction ) { tryToMoveMemberFunction ( nameInfo , deepestCommonModuleRef , ( ClassMemberFunction ) symbol ) ; } // else it's a variable definition, and we don't move those. } } if ( ! noStubFunctions && ! hasStubDeclaration && idGenerator . hasGeneratedAnyIds ( ) ) { // Declare stub functions in the top-most chunk. Node declarations = compiler . parseSyntheticCode ( STUB_DECLARATIONS ) ; NodeUtil . markNewScopesChanged ( declarations , compiler ) ; Node firstScript = compiler . getNodeForCodeInsertion ( null ) ; firstScript . addChildrenToFront ( declarations . removeChildren ( ) ) ; compiler . reportChangeToEnclosingScope ( firstScript ) ; } }
Move methods deeper in the chunk graph when possible .