idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
34,400
static final void addPassFactoryBefore ( List < PassFactory > factoryList , PassFactory factory , String passName ) { factoryList . add ( findPassIndexByName ( factoryList , passName ) , factory ) ; }
Insert the given pass factory before the factory of the given name .
34,401
static final void replacePassFactory ( List < PassFactory > factoryList , PassFactory factory ) { factoryList . set ( findPassIndexByName ( factoryList , factory . getName ( ) ) , factory ) ; }
Find a pass factory with the same name as the given one and replace it .
34,402
private static int findPassIndexByName ( List < PassFactory > factoryList , String name ) { for ( int i = 0 ; i < factoryList . size ( ) ; i ++ ) { if ( factoryList . get ( i ) . getName ( ) . equals ( name ) ) { return i ; } } throw new IllegalArgumentException ( "No factory named '" + name + "' in the factory list" ) ; }
Throws an exception if no pass with the given name exists .
34,403
final PassConfig getBasePassConfig ( ) { PassConfig current = this ; while ( current instanceof PassConfigDelegate ) { current = ( ( PassConfigDelegate ) current ) . delegate ; } return current ; }
Find the first pass provider that does not have a delegate .
34,404
@ SuppressWarnings ( "unchecked" ) public static < K , V > HamtPMap < K , V > empty ( ) { return ( HamtPMap < K , V > ) EMPTY ; }
Returns an empty map .
34,405
@ SuppressWarnings ( "unchecked" ) private static < K , V > HamtPMap < K , V > [ ] emptyChildren ( ) { return ( HamtPMap < K , V > [ ] ) EMPTY_CHILDREN ; }
Returns an empty array of child maps .
34,406
private void appendTo ( StringBuilder sb ) { if ( sb . length ( ) > 1 ) { sb . append ( ", " ) ; } sb . append ( key ) . append ( ": " ) . append ( value ) ; for ( HamtPMap < K , V > child : children ) { child . appendTo ( sb ) ; } }
Appends this map s contents to a string builder .
34,407
public V get ( K key ) { return ! isEmpty ( ) ? get ( key , hash ( key ) ) : null ; }
Retrieves the value associated with the given key from the map or returns null if it is not present .
34,408
public HamtPMap < K , V > plus ( K key , V value ) { return ! isEmpty ( ) ? plus ( key , hash ( key ) , checkNotNull ( value ) ) : new HamtPMap < > ( key , hash ( key ) , value , 0 , emptyChildren ( ) ) ; }
Returns a new map with the given key - value pair added . If the value is already present then this same map will be returned .
34,409
public HamtPMap < K , V > minus ( K key ) { return ! isEmpty ( ) ? minus ( key , hash ( key ) , null ) : this ; }
Returns a new map with the given key removed . If the key was not present in the first place then this same map will be returned .
34,410
public boolean equivalent ( PMap < K , V > that , BiPredicate < V , V > equivalence ) { return equivalent ( ! this . isEmpty ( ) ? this : null , ! that . isEmpty ( ) ? ( HamtPMap < K , V > ) that : null , equivalence ) ; }
Checks equality recursively based on the given equivalence . Short - circuits as soon as a false result is found .
34,411
private HamtPMap < K , V > getChild ( int bit ) { return ( mask & bit ) != 0 ? children [ index ( bit ) ] : null ; }
Returns the child for the given bit which must have exactly one bit set . Returns null if there is no child for that bit .
34,412
private static int compareUnsigned ( int left , int right ) { int diff = ( left >>> 2 ) - ( right >>> 2 ) ; return diff != 0 ? diff : ( left & 3 ) - ( right & 3 ) ; }
Compare two unsigned integers .
34,413
@ SuppressWarnings ( "unchecked" ) private HamtPMap < K , V > pivot ( K key , int hash ) { return pivot ( key , hash , null , ( V [ ] ) new Object [ 1 ] ) ; }
Returns a new version of this map with the given key at the root and the root element moved to some deeper node . If the key is not found then value will be null .
34,414
private HamtPMap < K , V > pivot ( K key , int hash , HamtPMap < K , V > parent , V [ ] result ) { int newMask = mask ; HamtPMap < K , V > [ ] newChildren = this . children ; if ( hash == this . hash && key . equals ( this . key ) ) { result [ 0 ] = this . value ; } else { int searchBucket = bucket ( hash ) ; int replacementBucket = bucket ( this . hash ) ; if ( searchBucket == replacementBucket ) { int bucketMask = 1 << searchBucket ; if ( ( mask & bucketMask ) != 0 ) { int index = index ( bucketMask ) ; HamtPMap < K , V > child = newChildren [ index ] ; HamtPMap < K , V > newChild = child . pivot ( key , shift ( hash ) , this , result ) ; newChildren = replaceChild ( newChildren , index , newChild ) ; } } else { int searchMask = 1 << searchBucket ; if ( ( mask & searchMask ) != 0 ) { int index = index ( searchMask ) ; HamtPMap < K , V > child = newChildren [ index ] ; HamtPMap < K , V > newChild = child . minus ( key , shift ( hash ) , result ) ; if ( ! newChild . isEmpty ( ) ) { newChildren = replaceChild ( newChildren , index , newChild ) ; } else { newChildren = deleteChild ( newChildren , index ) ; newMask &= ~ searchMask ; } } int replacementMask = 1 << replacementBucket ; int index = Integer . bitCount ( newMask & ( replacementMask - 1 ) ) ; if ( ( mask & replacementMask ) != 0 ) { HamtPMap < K , V > child = newChildren [ index ] ; HamtPMap < K , V > newChild = child . plus ( this . key , shift ( this . hash ) , this . value ) ; newChildren = replaceChild ( newChildren , index , newChild ) ; } else { newChildren = insertChild ( newChildren , index , new HamtPMap < > ( this . key , shift ( this . hash ) , this . value , 0 , emptyChildren ( ) ) ) ; newMask |= replacementMask ; } } } return parent != null ? new HamtPMap < > ( parent . key , shift ( parent . hash ) , parent . value , newMask , newChildren ) : new HamtPMap < > ( key , hash , result [ 0 ] , newMask , newChildren ) ; }
Internal recursive version of pivot . If parent is null then the result is used for the value in the returned map . The value if found is stored in the result array as a secondary return .
34,415
private HamtPMap < K , V > vacateRoot ( ) { int bucket = bucket ( this . hash ) ; int bucketMask = 1 << bucket ; int index = index ( bucketMask ) ; if ( ( mask & bucketMask ) != 0 ) { HamtPMap < K , V > newChild = children [ index ] . plus ( this . key , shift ( this . hash ) , this . value ) ; return new HamtPMap < > ( null , 0 , null , mask , replaceChild ( children , index , newChild ) ) ; } HamtPMap < K , V > newChild = new HamtPMap < > ( this . key , shift ( this . hash ) , this . value , 0 , emptyChildren ( ) ) ; return new HamtPMap < > ( null , 0 , null , mask | bucketMask , insertChild ( children , index , newChild ) ) ; }
Moves the root into the appropriate child .
34,416
private HamtPMap < K , V > withChildren ( int mask , HamtPMap < K , V > [ ] children ) { return mask == this . mask && children == this . children ? this : new HamtPMap < > ( key , hash , value , mask , children ) ; }
Returns a copy of this node with a different array of children .
34,417
private static < K , V > HamtPMap < K , V > deleteRoot ( int mask , HamtPMap < K , V > [ ] children ) { if ( mask == 0 ) { return null ; } HamtPMap < K , V > child = children [ 0 ] ; int hashBits = Integer . numberOfTrailingZeros ( mask ) ; int newHash = unshift ( child . hash , hashBits ) ; HamtPMap < K , V > newChild = deleteRoot ( child . mask , child . children ) ; if ( newChild == null ) { int newMask = mask & ~ Integer . lowestOneBit ( mask ) ; return new HamtPMap < > ( child . key , newHash , child . value , newMask , deleteChild ( children , 0 ) ) ; } else { return new HamtPMap < > ( child . key , newHash , child . value , mask , replaceChild ( children , 0 , newChild ) ) ; } }
Returns a new map with the elements from children . One element is removed from one of the children and promoted to a root node . If there are no children returns null .
34,418
private static < K , V > HamtPMap < K , V > [ ] insertChild ( HamtPMap < K , V > [ ] children , int index , HamtPMap < K , V > child ) { @ SuppressWarnings ( "unchecked" ) HamtPMap < K , V > [ ] newChildren = ( HamtPMap < K , V > [ ] ) new HamtPMap < ? , ? > [ children . length + 1 ] ; newChildren [ index ] = child ; System . arraycopy ( children , 0 , newChildren , 0 , index ) ; System . arraycopy ( children , index , newChildren , index + 1 , children . length - index ) ; return newChildren ; }
Returns a new array of children with an additional child inserted at the given index .
34,419
private static < K , V > HamtPMap < K , V > [ ] replaceChild ( HamtPMap < K , V > [ ] children , int index , HamtPMap < K , V > child ) { HamtPMap < K , V > [ ] newChildren = Arrays . copyOf ( children , children . length ) ; newChildren [ index ] = child ; return newChildren ; }
Returns a new array of children with the child at the given index replaced .
34,420
private static < K , V > HamtPMap < K , V > [ ] deleteChild ( HamtPMap < K , V > [ ] children , int index ) { if ( children . length == 1 ) { return emptyChildren ( ) ; } @ SuppressWarnings ( "unchecked" ) HamtPMap < K , V > [ ] newChildren = ( HamtPMap < K , V > [ ] ) new HamtPMap < ? , ? > [ children . length - 1 ] ; System . arraycopy ( children , 0 , newChildren , 0 , index ) ; System . arraycopy ( children , index + 1 , newChildren , index , children . length - index - 1 ) ; return newChildren ; }
Returns a new array of children with the child at the given index deleted .
34,421
public static IncrementalScopeCreator getInstance ( AbstractCompiler compiler ) { IncrementalScopeCreator creator = compiler . getScopeCreator ( ) ; if ( creator == null ) { creator = new IncrementalScopeCreator ( compiler ) ; compiler . putScopeCreator ( creator ) ; } return creator ; }
Get an instance of the ScopeCreator
34,422
public static Builder builder ( ) { return new AutoValue_Source . Builder ( ) . setPath ( DEV_NULL ) . setCode ( "" ) . setOriginalCodeSupplier ( null ) . setSourceMap ( "" ) . setSourceUrl ( "" ) . setSourceMappingUrl ( "" ) . setRuntimes ( ImmutableSet . of ( ) ) . setLoadFlags ( ImmutableMap . of ( ) ) . setEstimatedSize ( 0 ) ; }
Makes a new empty builder .
34,423
private void associateClones ( Node n , Node snapshot ) { if ( n . isRoot ( ) || NodeUtil . isChangeScopeRoot ( n ) ) { clonesByCurrent . put ( n , snapshot ) ; } Node child = n . getFirstChild ( ) ; Node snapshotChild = snapshot . getFirstChild ( ) ; while ( child != null ) { associateClones ( child , snapshotChild ) ; child = child . getNext ( ) ; snapshotChild = snapshotChild . getNext ( ) ; } }
Given an AST and its copy map the root node of each scope of main to the corresponding root node of clone
34,424
private void verifyScopeChangesHaveBeenRecorded ( String passName , Node root ) { final String passNameMsg = passName . isEmpty ( ) ? "" : passName + ": " ; final Set < Node > snapshotScopeNodes = new HashSet < > ( ) ; NodeUtil . visitPreOrder ( clonesByCurrent . get ( root ) , new Visitor ( ) { public void visit ( Node oldNode ) { if ( NodeUtil . isChangeScopeRoot ( oldNode ) ) { snapshotScopeNodes . add ( oldNode ) ; } } } ) ; NodeUtil . visitPreOrder ( root , new Visitor ( ) { public void visit ( Node n ) { if ( n . isRoot ( ) ) { verifyRoot ( n ) ; } else if ( NodeUtil . isChangeScopeRoot ( n ) ) { Node clone = clonesByCurrent . get ( n ) ; snapshotScopeNodes . remove ( clone ) ; verifyNode ( passNameMsg , n ) ; if ( clone == null ) { verifyNewNode ( passNameMsg , n ) ; } else { verifyNodeChange ( passNameMsg , n , clone ) ; } } } } ) ; verifyDeletedScopeNodes ( passNameMsg , snapshotScopeNodes ) ; }
Checks that the scope roots marked as changed have indeed changed
34,425
public boolean addRequiredParams ( JSType ... types ) { if ( hasOptionalOrVarArgs ( ) ) { return false ; } for ( JSType type : types ) { newParameter ( type ) ; } return true ; }
Add parameters of the given type to the end of the param list .
34,426
public boolean addOptionalParams ( JSType ... types ) { if ( hasVarArgs ( ) ) { return false ; } for ( JSType type : types ) { newParameter ( registry . createOptionalType ( type ) ) . setOptionalArg ( true ) ; } return true ; }
Add optional parameters of the given type to the end of the param list .
34,427
public boolean addVarArgs ( JSType type ) { if ( hasVarArgs ( ) ) { return false ; } newParameter ( type ) . setVarArgs ( true ) ; return true ; }
Add variable arguments to the end of the parameter list .
34,428
public Node newParameterFromNode ( Node n ) { Node newParam = newParameter ( n . getJSType ( ) ) ; newParam . setVarArgs ( n . isVarArgs ( ) ) ; newParam . setOptionalArg ( n . isOptionalArg ( ) ) ; return newParam ; }
Copies the parameter specification from the given node .
34,429
public Node newOptionalParameterFromNode ( Node n ) { Node newParam = newParameterFromNode ( n ) ; if ( ! newParam . isVarArgs ( ) && ! newParam . isOptionalArg ( ) ) { newParam . setOptionalArg ( true ) ; } return newParam ; }
Copies the parameter specification from the given node but makes sure it s optional .
34,430
private Node newParameter ( JSType type ) { Node paramNode = Node . newString ( Token . NAME , "" ) ; paramNode . setJSType ( type ) ; root . addChildToBack ( paramNode ) ; return paramNode ; }
Add a parameter to the list with the given type .
34,431
static void update ( AbstractCompiler compiler , Node externs , Node root ) { compiler . setExternGetterAndSetterProperties ( gather ( compiler , externs ) ) ; compiler . setSourceGetterAndSetterProperties ( gather ( compiler , root ) ) ; }
Gathers all getters and setters in the AST .
34,432
private static String formatProvide ( String namespace ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "goog.provide('" ) ; sb . append ( namespace ) ; sb . append ( "');" ) ; return sb . toString ( ) ; }
Returns the code for a correctly formatted provide call .
34,433
private void doExtraction ( GatherExtractionInfo info ) { if ( pattern == Pattern . USE_GLOBAL_TEMP ) { Node injectionPoint = compiler . getNodeForCodeInsertion ( null ) ; Node var = NodeUtil . newVarNode ( PROTOTYPE_ALIAS , null ) . useSourceInfoIfMissingFromForTree ( injectionPoint ) ; injectionPoint . addChildToFront ( var ) ; compiler . reportChangeToEnclosingScope ( var ) ; } for ( ExtractionInstance instance : info . instances ) { extractInstance ( instance ) ; } }
Declares the temp variable to point to prototype objects and iterates through all ExtractInstance and performs extraction there .
34,434
private void extractInstance ( ExtractionInstance instance ) { PrototypeMemberDeclaration first = instance . declarations . get ( 0 ) ; String className = first . qualifiedClassName ; if ( pattern == Pattern . USE_GLOBAL_TEMP ) { Node classNameNode = NodeUtil . newQName ( compiler , className ) ; classNameNode . putBooleanProp ( Node . IS_CONSTANT_NAME , first . constant ) ; Node stmt = IR . exprResult ( IR . assign ( IR . name ( PROTOTYPE_ALIAS ) , IR . getprop ( classNameNode , IR . string ( "prototype" ) ) ) ) . useSourceInfoIfMissingFromForTree ( first . node ) ; instance . parent . addChildBefore ( stmt , first . node ) ; compiler . reportChangeToEnclosingScope ( stmt ) ; } else if ( pattern == Pattern . USE_IIFE ) { Node block = IR . block ( ) ; Node func = IR . function ( IR . name ( "" ) , IR . paramList ( IR . name ( PROTOTYPE_ALIAS ) ) , block ) ; Node call = IR . call ( func , NodeUtil . newQName ( compiler , className + ".prototype" , instance . parent , className + ".prototype" ) ) ; call . putIntProp ( Node . FREE_CALL , 1 ) ; Node stmt = IR . exprResult ( call ) ; stmt . useSourceInfoIfMissingFromForTree ( first . node ) ; instance . parent . addChildBefore ( stmt , first . node ) ; compiler . reportChangeToEnclosingScope ( stmt ) ; for ( PrototypeMemberDeclaration declar : instance . declarations ) { compiler . reportChangeToEnclosingScope ( declar . node ) ; block . addChildToBack ( declar . node . detach ( ) ) ; } } for ( PrototypeMemberDeclaration declar : instance . declarations ) { replacePrototypeMemberDeclaration ( declar ) ; } }
At a given ExtractionInstance stores and prototype object in the temp variable and rewrite each member declaration to assign to the temp variable instead .
34,435
private void replacePrototypeMemberDeclaration ( PrototypeMemberDeclaration declar ) { Node assignment = declar . node . getFirstChild ( ) ; Node lhs = assignment . getFirstChild ( ) ; Node name = NodeUtil . newQName ( compiler , PROTOTYPE_ALIAS + "." + declar . memberName , declar . node , declar . memberName ) ; Node accessNode = declar . lhs . getFirstFirstChild ( ) ; String originalName = accessNode . getOriginalName ( ) ; String className = originalName != null ? originalName : "?" ; name . getFirstChild ( ) . useSourceInfoFromForTree ( lhs ) ; name . putBooleanProp ( Node . IS_CONSTANT_NAME , lhs . getBooleanProp ( Node . IS_CONSTANT_NAME ) ) ; name . getFirstChild ( ) . setOriginalName ( className + ".prototype" ) ; assignment . replaceChild ( lhs , name ) ; compiler . reportChangeToEnclosingScope ( name ) ; }
Replaces a member declaration to an assignment to the temp prototype object .
34,436
public VariableVisibility getVariableVisibility ( Node declaringNameNode ) { Node parent = declaringNameNode . getParent ( ) ; checkArgument ( parent . isVar ( ) || parent . isFunction ( ) || parent . isParamList ( ) ) ; return visibilityByDeclaringNameNode . get ( declaringNameNode ) ; }
Returns the visibility of of a variable given that variable s declaring name node .
34,437
public void process ( Node externs , Node root ) { ReferenceCollectingCallback callback = new ReferenceCollectingCallback ( compiler , ReferenceCollectingCallback . DO_NOTHING_BEHAVIOR , new Es6SyntacticScopeCreator ( compiler ) ) ; callback . process ( root ) ; for ( Var variable : callback . getAllSymbols ( ) ) { ReferenceCollection referenceCollection = callback . getReferences ( variable ) ; VariableVisibility visibility ; if ( variableIsParameter ( variable ) ) { visibility = VariableVisibility . PARAMETER ; } else if ( variable . isLocal ( ) ) { if ( referenceCollection . isEscaped ( ) ) { visibility = VariableVisibility . CAPTURED_LOCAL ; } else { visibility = VariableVisibility . LOCAL ; } } else if ( variable . isGlobal ( ) ) { visibility = VariableVisibility . GLOBAL ; } else { throw new IllegalStateException ( "Un-handled variable visibility for " + variable ) ; } visibilityByDeclaringNameNode . put ( variable . getNameNode ( ) , visibility ) ; } }
Determines the visibility class for each variable in root .
34,438
private static boolean variableIsParameter ( Var variable ) { Node variableParent = variable . getParentNode ( ) ; return variableParent != null && variableParent . isParamList ( ) ; }
Returns true if the variable is a formal parameter .
34,439
public static JSError make ( DiagnosticType type , String ... arguments ) { return new JSError ( null , null , - 1 , - 1 , type , null , arguments ) ; }
Creates a JSError with no source information
34,440
public static JSError make ( CheckLevel level , DiagnosticType type , String ... arguments ) { return new JSError ( null , null , - 1 , - 1 , type , level , arguments ) ; }
Creates a JSError with no source information and a non - default level .
34,441
public static JSError make ( String sourceName , int lineno , int charno , DiagnosticType type , String ... arguments ) { return new JSError ( sourceName , null , lineno , charno , type , null , arguments ) ; }
Creates a JSError at a given source location
34,442
public static JSError make ( Node n , DiagnosticType type , String ... arguments ) { return new JSError ( n . getSourceFileName ( ) , n , type , arguments ) ; }
Creates a JSError from a file and Node position .
34,443
public String format ( CheckLevel level , MessageFormatter formatter ) { switch ( level ) { case ERROR : return formatter . formatError ( this ) ; case WARNING : return formatter . formatWarning ( this ) ; default : return null ; } }
Format a message at the given level .
34,444
static String escapePath ( String input ) { String encodedInput = input . replace ( ':' , '-' ) . replace ( '\\' , '/' ) . replace ( " " , "%20" ) . replace ( "[" , "%5B" ) . replace ( "]" , "%5D" ) . replace ( "<" , "%3C" ) . replace ( ">" , "%3E" ) ; return canonicalizePath ( encodedInput ) ; }
Escapes the given input path .
34,445
static String canonicalizePath ( String path ) { String [ ] parts = path . split ( MODULE_SLASH ) ; String [ ] buffer = new String [ parts . length ] ; int position = 0 ; int available = 0 ; boolean absolutePath = ( parts . length > 1 && parts [ 0 ] . isEmpty ( ) ) ; if ( absolutePath ) { -- available ; } for ( String part : parts ) { if ( part . equals ( "." ) ) { continue ; } if ( part . equals ( ".." ) ) { if ( available > 0 ) { -- position ; -- available ; buffer [ position ] = null ; } else if ( ! absolutePath ) { buffer [ position ] = part ; ++ position ; } continue ; } buffer [ position ] = part ; ++ position ; ++ available ; } if ( absolutePath && position == 1 ) { return MODULE_SLASH ; } return MODULE_JOINER . join ( Arrays . copyOf ( buffer , position ) ) ; }
Canonicalize a given path removing segments containing . and consuming segments for .. .
34,446
public final boolean makesStructs ( ) { if ( ! hasInstanceType ( ) ) { return false ; } if ( propAccess == PropAccess . STRUCT ) { return true ; } FunctionType superc = getSuperClassConstructor ( ) ; if ( superc != null && superc . makesStructs ( ) ) { setStruct ( ) ; return true ; } return false ; }
When a class B inherits from A and A is annotated as a struct then B automatically gets the annotation even if B s constructor is not explicitly annotated .
34,447
public final boolean makesDicts ( ) { if ( ! isConstructor ( ) ) { return false ; } if ( propAccess == PropAccess . DICT ) { return true ; } FunctionType superc = getSuperClassConstructor ( ) ; if ( superc != null && superc . makesDicts ( ) ) { setDict ( ) ; return true ; } return false ; }
When a class B inherits from A and A is annotated as a dict then B automatically gets the annotation even if B s constructor is not explicitly annotated .
34,448
public final int getMinArity ( ) { int i = 0 ; int min = 0 ; for ( Node n : getParameters ( ) ) { i ++ ; if ( ! n . isOptionalArg ( ) && ! n . isVarArgs ( ) ) { min = i ; } } return min ; }
Gets the minimum number of arguments that this function requires .
34,449
public final int getMaxArity ( ) { Node params = getParametersNode ( ) ; if ( params != null ) { Node lastParam = params . getLastChild ( ) ; if ( lastParam == null || ! lastParam . isVarArgs ( ) ) { return params . getChildCount ( ) ; } } return Integer . MAX_VALUE ; }
Gets the maximum number of arguments that this function requires or Integer . MAX_VALUE if this is a variable argument function .
34,450
public final Set < String > getOwnPropertyNames ( ) { if ( prototypeSlot == null ) { return super . getOwnPropertyNames ( ) ; } else { ImmutableSet . Builder < String > names = ImmutableSet . builder ( ) ; names . add ( "prototype" ) ; names . addAll ( super . getOwnPropertyNames ( ) ) ; return names . build ( ) ; } }
Includes the prototype iff someone has created it . We do not want to expose the prototype for ordinary functions .
34,451
final boolean setPrototype ( ObjectType prototype , Node propertyNode ) { if ( prototype == null ) { return false ; } if ( isConstructor ( ) && prototype == getInstanceType ( ) ) { return false ; } return setPrototypeNoCheck ( prototype , propertyNode ) ; }
Sets the prototype .
34,452
private boolean setPrototypeNoCheck ( ObjectType prototype , Node propertyNode ) { ObjectType oldPrototype = prototypeSlot == null ? null : ( ObjectType ) prototypeSlot . getType ( ) ; boolean replacedPrototype = oldPrototype != null ; this . prototypeSlot = new Property ( "prototype" , prototype , true , propertyNode == null ? source : propertyNode ) ; prototype . setOwnerFunction ( this ) ; if ( oldPrototype != null ) { oldPrototype . setOwnerFunction ( null ) ; } if ( isConstructor ( ) || isInterface ( ) ) { FunctionType superClass = getSuperClassConstructor ( ) ; if ( superClass != null ) { superClass . addSubType ( this ) ; wasAddedToExtendedConstructorSubtypes = true ; } if ( isInterface ( ) ) { for ( ObjectType interfaceType : getExtendedInterfaces ( ) ) { if ( interfaceType . getConstructor ( ) != null ) { interfaceType . getConstructor ( ) . addSubType ( this ) ; } } } } if ( replacedPrototype ) { clearCachedValues ( ) ; } return true ; }
Set the prototype without doing any sanity checks .
34,453
public final Iterable < ObjectType > getAllImplementedInterfaces ( ) { Set < ObjectType > interfaces = new LinkedHashSet < > ( ) ; for ( ObjectType type : getImplementedInterfaces ( ) ) { addRelatedInterfaces ( type , interfaces ) ; } return interfaces ; }
Returns all interfaces implemented by a class or its superclass and any superclasses for any of those interfaces . If this is called before all types are resolved it may return an incomplete set .
34,454
public final ImmutableList < ObjectType > getImplementedInterfaces ( ) { FunctionType superCtor = isConstructor ( ) ? getSuperClassConstructor ( ) : null ; if ( superCtor == null ) { return implementedInterfaces ; } ImmutableList . Builder < ObjectType > builder = ImmutableList . builder ( ) ; builder . addAll ( implementedInterfaces ) ; while ( superCtor != null ) { builder . addAll ( superCtor . implementedInterfaces ) ; superCtor = superCtor . getSuperClassConstructor ( ) ; } return builder . build ( ) ; }
Returns interfaces implemented directly by a class or its superclass .
34,455
public final FunctionType getBindReturnType ( int argsToBind ) { Builder builder = builder ( registry ) . withReturnType ( getReturnType ( ) ) . withTemplateKeys ( getTemplateTypeMap ( ) . getTemplateKeys ( ) ) ; if ( argsToBind >= 0 ) { Node origParams = getParametersNode ( ) ; if ( origParams != null ) { Node params = origParams . cloneTree ( ) ; for ( int i = 1 ; i < argsToBind && params . getFirstChild ( ) != null ; i ++ ) { if ( params . getFirstChild ( ) . isVarArgs ( ) ) { break ; } params . removeFirstChild ( ) ; } builder . withParamsNode ( params ) ; } } return builder . build ( ) ; }
Get the return value of calling bind on this function with the specified number of arguments .
34,456
final boolean checkFunctionEquivalenceHelper ( FunctionType that , EquivalenceMethod eqMethod , EqCache eqCache ) { if ( this == that ) { return true ; } if ( kind != that . kind ) { return false ; } switch ( kind ) { case CONSTRUCTOR : return false ; case INTERFACE : return getReferenceName ( ) . equals ( that . getReferenceName ( ) ) ; case ORDINARY : return typeOfThis . checkEquivalenceHelper ( that . typeOfThis , eqMethod , eqCache ) && call . checkArrowEquivalenceHelper ( that . call , eqMethod , eqCache ) ; default : throw new AssertionError ( ) ; } }
Two function types are equal if their signatures match . Since they don t have signatures two interfaces are equal if their names match .
34,457
private void appendVarArgsString ( StringBuilder sb , JSType paramType , boolean forAnnotations ) { sb . append ( "..." ) ; paramType . appendAsNonNull ( sb , forAnnotations ) ; }
Gets the string representation of a var args param .
34,458
private void appendOptionalArgString ( StringBuilder sb , JSType paramType , boolean forAnnotations ) { if ( paramType . isUnionType ( ) ) { paramType = paramType . toMaybeUnionType ( ) . getRestrictedUnion ( registry . getNativeType ( JSTypeNative . VOID_TYPE ) ) ; } paramType . appendAsNonNull ( sb , forAnnotations ) . append ( "=" ) ; }
Gets the string representation of an optional param .
34,459
public final void setSource ( Node source ) { if ( prototypeSlot != null ) { if ( source == null || prototypeSlot . getNode ( ) == null ) { prototypeSlot = new Property ( prototypeSlot . getName ( ) , prototypeSlot . getType ( ) , prototypeSlot . isTypeInferred ( ) , source ) ; } } this . source = source ; }
Sets the source node .
34,460
private void addSubType ( FunctionType subType ) { if ( subTypes == null ) { subTypes = new ArrayList < > ( ) ; } subTypes . add ( subType ) ; }
Adds a type to the list of subtypes for this type .
34,461
public final void clearCachedValues ( ) { super . clearCachedValues ( ) ; if ( subTypes != null ) { for ( FunctionType subType : subTypes ) { subType . clearCachedValues ( ) ; } } if ( ! isNativeObjectType ( ) ) { if ( hasInstanceType ( ) ) { getInstanceType ( ) . clearCachedValues ( ) ; } if ( prototypeSlot != null ) { ( ( ObjectType ) prototypeSlot . getType ( ) ) . clearCachedValues ( ) ; } } }
prototypeSlot is non - null and this override does nothing to change that state .
34,462
private ImmutableList < ObjectType > resolveTypeListHelper ( ImmutableList < ObjectType > list , ErrorReporter reporter ) { boolean changed = false ; ImmutableList . Builder < ObjectType > resolvedList = ImmutableList . builder ( ) ; for ( ObjectType type : list ) { JSType rt = type . resolve ( reporter ) ; if ( ! rt . isObjectType ( ) ) { reporter . warning ( "not an object type: " + rt + " (at " + toString ( ) + ")" , source . getSourceFileName ( ) , source . getLineno ( ) , source . getCharno ( ) ) ; continue ; } ObjectType resolved = rt . toObjectType ( ) ; resolvedList . add ( resolved ) ; changed |= ( resolved != type ) ; } return changed ? resolvedList . build ( ) : null ; }
Resolve each item in the list and return a new list if any references changed . Otherwise return null .
34,463
public final Map < String , JSType > getPropertyTypeMap ( ) { Map < String , JSType > propTypeMap = new LinkedHashMap < > ( ) ; updatePropertyTypeMap ( this , propTypeMap , new HashSet < FunctionType > ( ) ) ; return propTypeMap ; }
get the map of properties to types covered in a function type
34,464
public final FunctionType forgetParameterAndReturnTypes ( ) { FunctionType result = builder ( registry ) . withName ( getReferenceName ( ) ) . withSourceNode ( source ) . withTypeOfThis ( getInstanceType ( ) ) . withKind ( kind ) . build ( ) ; result . setPrototypeBasedOn ( getInstanceType ( ) ) ; return result ; }
Create a new constructor with the parameters and return type stripped .
34,465
public final ImmutableList < TemplateType > getConstructorOnlyTemplateParameters ( ) { TemplateTypeMap ctorMap = getTemplateTypeMap ( ) ; TemplateTypeMap instanceMap = getInstanceType ( ) . getTemplateTypeMap ( ) ; if ( ctorMap == instanceMap ) { return ImmutableList . of ( ) ; } ImmutableList . Builder < TemplateType > ctorKeys = ImmutableList . builder ( ) ; Set < TemplateType > instanceKeys = ImmutableSet . copyOf ( instanceMap . getUnfilledTemplateKeys ( ) ) ; for ( TemplateType ctorKey : ctorMap . getUnfilledTemplateKeys ( ) ) { if ( ! instanceKeys . contains ( ctorKey ) ) { ctorKeys . add ( ctorKey ) ; } } return ctorKeys . build ( ) ; }
Returns a list of template types present on the constructor but not on the instance .
34,466
void addStringNode ( Node n , AbstractCompiler compiler ) { String name = n . getString ( ) ; Node syntheticRef = NodeUtil . newQName ( compiler , name , n , name ) ; final int forQuote = 1 ; final int forDot = 1 ; Node current = null ; for ( current = syntheticRef ; current . isGetProp ( ) ; current = current . getFirstChild ( ) ) { int fullLen = current . getQualifiedName ( ) . length ( ) ; int namespaceLen = current . getFirstChild ( ) . getQualifiedName ( ) . length ( ) ; current . setSourceEncodedPosition ( n . getSourcePosition ( ) + forQuote ) ; current . setLength ( fullLen ) ; current . getLastChild ( ) . setSourceEncodedPosition ( n . getSourcePosition ( ) + namespaceLen + forQuote + forDot ) ; current . getLastChild ( ) . setLength ( current . getLastChild ( ) . getString ( ) . length ( ) ) ; } current . setSourceEncodedPosition ( n . getSourcePosition ( ) + forQuote ) ; current . setLength ( current . getString ( ) . length ( ) ) ; addReference ( syntheticRef ) ; }
Adds a synthetic reference for a string node representing a reference name .
34,467
private void resetGlobalVarReferences ( Map < Var , ReferenceCollection > globalRefMap ) { refMap = new LinkedHashMap < > ( ) ; for ( Entry < Var , ReferenceCollection > entry : globalRefMap . entrySet ( ) ) { Var var = entry . getKey ( ) ; if ( var . isGlobal ( ) ) { refMap . put ( var . getName ( ) , entry . getValue ( ) ) ; } } }
Resets global var reference map with the new provide map .
34,468
private static boolean isPrototypeMethodDefinition ( Node node ) { Node parent = node . getParent ( ) ; Node grandparent = node . getGrandparent ( ) ; if ( parent == null || grandparent == null ) { return false ; } switch ( node . getToken ( ) ) { case MEMBER_FUNCTION_DEF : if ( NodeUtil . isEs6ConstructorMemberFunctionDef ( node ) ) { return false ; } return true ; case GETPROP : { if ( parent . getFirstChild ( ) != node ) { return false ; } if ( ! NodeUtil . isExprAssign ( grandparent ) ) { return false ; } Node functionNode = parent . getLastChild ( ) ; if ( ( functionNode == null ) || ! functionNode . isFunction ( ) ) { return false ; } Node nameNode = node . getFirstChild ( ) ; return nameNode . isGetProp ( ) && nameNode . getLastChild ( ) . getString ( ) . equals ( "prototype" ) ; } case STRING_KEY : { checkArgument ( parent . isObjectLit ( ) , parent ) ; if ( ! grandparent . isAssign ( ) ) { return false ; } if ( grandparent . getLastChild ( ) != parent ) { return false ; } Node greatgrandparent = grandparent . getParent ( ) ; if ( greatgrandparent == null || ! greatgrandparent . isExprResult ( ) ) { return false ; } Node functionNode = node . getFirstChild ( ) ; if ( ( functionNode == null ) || ! functionNode . isFunction ( ) ) { return false ; } Node target = grandparent . getFirstChild ( ) ; return target . isGetProp ( ) && target . getLastChild ( ) . getString ( ) . equals ( "prototype" ) ; } default : return false ; } }
Determines if the current node is a function prototype definition .
34,469
private boolean isEligibleDefinitionSite ( String name , Node definitionSite ) { switch ( definitionSite . getToken ( ) ) { case GETPROP : case MEMBER_FUNCTION_DEF : case STRING_KEY : break ; default : throw new IllegalArgumentException ( definitionSite . toString ( ) ) ; } CodingConvention codingConvention = compiler . getCodingConvention ( ) ; if ( codingConvention . isExported ( name ) ) { return false ; } if ( ! isPrototypeMethodDefinition ( definitionSite ) ) { return false ; } return true ; }
Determines if a method definition site is eligible for rewrite as a global .
34,470
private boolean isEligibleDefinitionFunction ( Node definitionFunction ) { checkArgument ( definitionFunction . isFunction ( ) , definitionFunction ) ; if ( definitionFunction . isArrowFunction ( ) ) { return false ; } for ( Node ancestor = definitionFunction . getParent ( ) ; ancestor != null ; ancestor = ancestor . getParent ( ) ) { if ( isScopingOrBranchingConstruct ( ancestor ) ) { return false ; } if ( ancestor . isClass ( ) && localNameIsDeclaredByClass ( ancestor ) ) { return false ; } } if ( NodeUtil . containsType ( definitionFunction , Token . SUPER ) ) { return false ; } if ( NodeUtil . doesFunctionReferenceOwnArgumentsObject ( definitionFunction ) ) { return false ; } return true ; }
Determines if a method definition function is eligible for rewrite as a global function .
34,471
private void rewriteCall ( Node getprop , String newMethodName ) { checkArgument ( getprop . isGetProp ( ) , getprop ) ; Node call = getprop . getParent ( ) ; checkArgument ( call . isCall ( ) , call ) ; Node receiver = getprop . getFirstChild ( ) ; getprop . removeChild ( receiver ) ; call . replaceChild ( getprop , receiver ) ; call . addChildToFront ( IR . name ( newMethodName ) . srcref ( getprop ) ) ; if ( receiver . isSuper ( ) ) { receiver . setToken ( Token . THIS ) ; } call . putBooleanProp ( Node . FREE_CALL , true ) ; compiler . reportChangeToEnclosingScope ( call ) ; }
Rewrites object method call sites as calls to global functions that take this as their first argument .
34,472
private void rewriteDefinition ( Node definitionSite , String newMethodName ) { final Node function ; final Node subtreeToRemove ; final Node nameSource ; switch ( definitionSite . getToken ( ) ) { case GETPROP : function = definitionSite . getParent ( ) . getLastChild ( ) ; nameSource = definitionSite . getLastChild ( ) ; subtreeToRemove = NodeUtil . getEnclosingStatement ( definitionSite ) ; break ; case STRING_KEY : case MEMBER_FUNCTION_DEF : function = definitionSite . getLastChild ( ) ; nameSource = definitionSite ; subtreeToRemove = definitionSite ; break ; default : throw new IllegalArgumentException ( definitionSite . toString ( ) ) ; } Node statement = NodeUtil . getEnclosingStatement ( definitionSite ) ; Node newNameNode = IR . name ( newMethodName ) . useSourceInfoIfMissingFrom ( nameSource ) ; Node newVarNode = IR . var ( newNameNode ) . useSourceInfoIfMissingFrom ( nameSource ) ; statement . getParent ( ) . addChildBefore ( newVarNode , statement ) ; function . detach ( ) ; newNameNode . addChildToFront ( function ) ; String selfName = newMethodName + "$self" ; Node paramList = function . getSecondChild ( ) ; paramList . addChildToFront ( IR . name ( selfName ) . useSourceInfoIfMissingFrom ( function ) ) ; compiler . reportChangeToEnclosingScope ( paramList ) ; replaceReferencesToThis ( function . getSecondChild ( ) , selfName ) ; replaceReferencesToThis ( function . getLastChild ( ) , selfName ) ; fixFunctionType ( function ) ; NodeUtil . deleteNode ( subtreeToRemove , compiler ) ; compiler . reportChangeToEnclosingScope ( newVarNode ) ; }
Rewrites method definitions as global functions that take this as their first argument .
34,473
private void fixFunctionType ( Node functionNode ) { JSType t = functionNode . getJSType ( ) ; if ( t == null ) { return ; } FunctionType ft = t . toMaybeFunctionType ( ) ; if ( ft != null ) { functionNode . setJSType ( convertMethodToFunction ( ft ) ) ; } }
Creates a new type based on the original function type by adding the original this pointer type to the beginning of the argument type list and replacing the this pointer type with bottom .
34,474
private void replaceReferencesToThis ( Node node , String name ) { if ( node . isFunction ( ) && ! node . isArrowFunction ( ) ) { return ; } for ( Node child : node . children ( ) ) { if ( child . isThis ( ) ) { Node newName = IR . name ( name ) . useSourceInfoFrom ( child ) . setJSType ( child . getJSType ( ) ) ; node . replaceChild ( child , newName ) ; compiler . reportChangeToEnclosingScope ( newName ) ; } else { replaceReferencesToThis ( child , name ) ; } } }
Replaces references to this with references to name . Do not traverse function boundaries .
34,475
private String getParameterJSDocName ( Node paramNode , int paramIndex ) { Node nameNode = null ; if ( paramNode != null ) { checkArgument ( paramNode . getParent ( ) . isParamList ( ) , paramNode ) ; if ( paramNode . isRest ( ) ) { paramNode = paramNode . getOnlyChild ( ) ; } else if ( paramNode . isDefaultValue ( ) ) { paramNode = paramNode . getFirstChild ( ) ; } if ( paramNode . isName ( ) ) { nameNode = paramNode ; } else { checkState ( paramNode . isObjectPattern ( ) || paramNode . isArrayPattern ( ) , paramNode ) ; nameNode = null ; } } if ( nameNode == null ) { return "p" + paramIndex ; } else { checkState ( nameNode . isName ( ) , nameNode ) ; return nameNode . getString ( ) ; } }
Return the name of the parameter to be used in JSDoc generating one for destructuring parameters .
34,476
private void appendClassAnnotations ( StringBuilder sb , FunctionType funType ) { FunctionType superConstructor = funType . getInstanceType ( ) . getSuperClassConstructor ( ) ; if ( superConstructor != null ) { ObjectType superInstance = superConstructor . getInstanceType ( ) ; if ( ! superInstance . toString ( ) . equals ( "Object" ) ) { sb . append ( " * " ) ; appendAnnotation ( sb , "extends" , superInstance . toAnnotationString ( Nullability . IMPLICIT ) ) ; sb . append ( "\n" ) ; } } Set < String > interfaces = new TreeSet < > ( ) ; for ( ObjectType interfaze : funType . getAncestorInterfaces ( ) ) { interfaces . add ( interfaze . toAnnotationString ( Nullability . IMPLICIT ) ) ; } for ( String interfaze : interfaces ) { sb . append ( " * " ) ; appendAnnotation ( sb , "implements" , interfaze ) ; sb . append ( "\n" ) ; } }
we should print it first like users write it . Same for
34,477
private String getParameterJSDocType ( List < JSType > types , int index , int minArgs , int maxArgs ) { JSType type = types . get ( index ) ; if ( index < minArgs ) { return type . toAnnotationString ( Nullability . EXPLICIT ) ; } boolean isRestArgument = maxArgs == Integer . MAX_VALUE && index == types . size ( ) - 1 ; if ( isRestArgument ) { return "..." + restrictByUndefined ( type ) . toAnnotationString ( Nullability . EXPLICIT ) ; } return restrictByUndefined ( type ) . toAnnotationString ( Nullability . EXPLICIT ) + "=" ; }
Creates a JSDoc - suitable String representation of the type of a parameter .
34,478
private JSType restrictByUndefined ( JSType type ) { if ( ! type . isVoidable ( ) ) { return type ; } JSType restricted = type . restrictByNotNullOrUndefined ( ) ; if ( type . isNullable ( ) ) { JSType nullType = registry . getNativeType ( JSTypeNative . NULL_TYPE ) ; return registry . createUnionType ( ImmutableList . of ( restricted , nullType ) ) ; } return restricted . isEmptyType ( ) ? type : restricted ; }
Removes undefined from a union type .
34,479
private void validateClassLevelJsDoc ( Node n , JSDocInfo info ) { if ( info != null && n . isMemberFunctionDef ( ) && hasClassLevelJsDoc ( info ) ) { report ( n , DISALLOWED_MEMBER_JSDOC ) ; } }
Checks that class - level annotations like
34,480
private void validateDeprecatedJsDoc ( Node n , JSDocInfo info ) { if ( info != null && info . isExpose ( ) ) { report ( n , ANNOTATION_DEPRECATED , "@expose" , "Use @nocollapse or @export instead." ) ; } }
Checks that deprecated annotations such as
34,481
private void validateNoCollapse ( Node n , JSDocInfo info ) { if ( n . isFromExterns ( ) ) { if ( info != null && info . isNoCollapse ( ) ) { reportMisplaced ( n , "nocollapse" , "This JSDoc has no effect in externs." ) ; } return ; } if ( ! NodeUtil . isPrototypePropertyDeclaration ( n . getParent ( ) ) ) { return ; } JSDocInfo jsdoc = n . getJSDocInfo ( ) ; if ( jsdoc != null && jsdoc . isNoCollapse ( ) ) { reportMisplaced ( n , "nocollapse" , "This JSDoc has no effect on prototype properties." ) ; } }
Warns when nocollapse annotations are present on nodes which are not eligible for property collapsing .
34,482
private void validateFunctionJsDoc ( Node n , JSDocInfo info ) { if ( info == null ) { return ; } if ( info . containsFunctionDeclaration ( ) && ! info . hasType ( ) && ! isJSDocOnFunctionNode ( n , info ) ) { reportMisplaced ( n , "function" , "This JSDoc is not attached to a function node. " + "Are you missing parentheses?" ) ; } }
Checks that JSDoc intended for a function is actually attached to a function .
34,483
private boolean isJSDocOnFunctionNode ( Node n , JSDocInfo info ) { switch ( n . getToken ( ) ) { case FUNCTION : case GETTER_DEF : case SETTER_DEF : case MEMBER_FUNCTION_DEF : case STRING_KEY : case COMPUTED_PROP : case EXPORT : return true ; case GETELEM : case GETPROP : if ( n . getFirstChild ( ) . isQualifiedName ( ) ) { return true ; } return false ; case VAR : case LET : case CONST : case ASSIGN : { Node lhs = n . getFirstChild ( ) ; Node rhs = NodeUtil . getRValueOfLValue ( lhs ) ; if ( rhs != null && isClass ( rhs ) && ! info . isConstructor ( ) ) { return false ; } return true ; } default : return false ; } }
Whether this node s JSDoc may apply to a function
34,484
private boolean isValidMsgName ( Node nameNode ) { if ( nameNode . isName ( ) || nameNode . isStringKey ( ) ) { return nameNode . getString ( ) . startsWith ( "MSG_" ) ; } else if ( nameNode . isQualifiedName ( ) ) { return nameNode . getLastChild ( ) . getString ( ) . startsWith ( "MSG_" ) ; } else { return false ; } }
Returns whether of not the given name is valid target for the result of goog . getMsg
34,485
private boolean isTypeAnnotationAllowedForName ( Node n ) { checkState ( n . isName ( ) , n ) ; if ( ! NodeUtil . isLValue ( n ) ) { return false ; } Node rootTarget = NodeUtil . getRootTarget ( n ) ; return ! NodeUtil . isLhsOfAssign ( rootTarget ) ; }
Is it valid to have a type annotation on the given NAME node?
34,486
private void validateImplicitCast ( Node n , JSDocInfo info ) { if ( ! inExterns && info != null && info . isImplicitCast ( ) ) { report ( n , TypeCheck . ILLEGAL_IMPLICIT_CAST ) ; } }
Checks that an
34,487
private void validateClosurePrimitive ( Node n , JSDocInfo info ) { if ( info == null || ! info . hasClosurePrimitiveId ( ) ) { return ; } if ( ! isJSDocOnFunctionNode ( n , info ) ) { report ( n , MISPLACED_ANNOTATION , "closurePrimitive" , "must be on a function node" ) ; } }
Checks that a
34,488
private void validateReturnJsDoc ( Node n , JSDocInfo info ) { if ( ! n . isReturn ( ) || info == null ) { return ; } if ( info . containsDeclaration ( ) && ! info . hasType ( ) ) { report ( n , JSDOC_ON_RETURN ) ; } }
Checks that there are no annotations on return .
34,489
private static void addAfter ( Node originalLvalue , Node newLvalue , Node newRvalue ) { Node parent = originalLvalue . getParent ( ) ; if ( parent . isAssign ( ) ) { Node newAssign = IR . assign ( newLvalue , newRvalue ) . srcref ( parent ) ; Node newComma = new Node ( Token . COMMA , newAssign ) ; parent . replaceWith ( newComma ) ; newComma . addChildToFront ( parent ) ; return ; } if ( newLvalue . isDestructuringPattern ( ) ) { newLvalue = new Node ( Token . DESTRUCTURING_LHS , newLvalue , newRvalue ) . srcref ( parent ) ; } else { newLvalue . addChildToBack ( newRvalue ) ; } Node declaration = parent . isDestructuringLhs ( ) ? originalLvalue . getGrandparent ( ) : parent ; checkState ( NodeUtil . isNameDeclaration ( declaration ) , declaration ) ; if ( NodeUtil . isStatementParent ( declaration . getParent ( ) ) ) { Node newDeclaration = new Node ( declaration . getToken ( ) ) . srcref ( declaration ) ; newDeclaration . addChildToBack ( newLvalue ) ; declaration . getParent ( ) . addChildAfter ( newDeclaration , declaration ) ; } else { declaration . addChildToBack ( newLvalue ) ; } }
Adds the new assign or name declaration after the original assign or name declaration
34,490
private static Node makeNewRvalueForDestructuringKey ( Node stringKey , Node rvalue , Set < AstChange > newNodes , Ref ref ) { if ( stringKey . getOnlyChild ( ) . isDefaultValue ( ) ) { Node defaultValue = stringKey . getFirstChild ( ) . getSecondChild ( ) . detach ( ) ; Node rvalueForSheq = rvalue . cloneTree ( ) ; if ( newNodes != null ) { newNodes . add ( new AstChange ( ref . module , ref . scope , rvalueForSheq ) ) ; } rvalue = IR . hook ( IR . sheq ( NodeUtil . newUndefinedNode ( rvalue ) , rvalueForSheq ) , defaultValue , rvalue ) . srcrefTree ( defaultValue ) ; } return rvalue ; }
Makes a default value expression from the rvalue or otherwise just returns it
34,491
private static Node createNewObjectPatternFromSuccessiveKeys ( Node stringKey ) { Node newPattern = stringKey . getParent ( ) . cloneNode ( ) ; for ( Node next = stringKey . getNext ( ) ; next != null ; ) { Node newKey = next ; next = newKey . getNext ( ) ; newPattern . addChildToBack ( newKey . detach ( ) ) ; } return newPattern ; }
Removes any keys after the given key and adds them in order to a new object pattern
34,492
private void rebuildAlternates ( ) { UnionTypeBuilder builder = UnionTypeBuilder . create ( registry ) ; builder . addAlternates ( alternates ) ; alternates = builder . getAlternates ( ) ; }
Use UnionTypeBuilder to rebuild the list of alternates and hashcode of the current UnionType .
34,493
boolean checkUnionEquivalenceHelper ( UnionType that , EquivalenceMethod eqMethod , EqCache eqCache ) { List < JSType > thatAlternates = that . getAlternates ( ) ; if ( eqMethod == EquivalenceMethod . IDENTITY && alternates . size ( ) != thatAlternates . size ( ) ) { return false ; } for ( int i = 0 ; i < thatAlternates . size ( ) ; i ++ ) { JSType thatAlternate = thatAlternates . get ( i ) ; if ( ! hasAlternate ( thatAlternate , eqMethod , eqCache ) ) { return false ; } } return true ; }
Two union types are equal if after flattening nested union types they have the same number of alternates and all alternates are equal .
34,494
private void removeUnneededPolyfills ( Node parent , Node runtimeEnd ) { Node node = parent . getFirstChild ( ) ; while ( node != null && node != runtimeEnd ) { Node next = node . getNext ( ) ; if ( NodeUtil . isExprCall ( node ) ) { Node call = node . getFirstChild ( ) ; Node name = call . getFirstChild ( ) ; if ( name . matchesQualifiedName ( "$jscomp.polyfill" ) ) { FeatureSet nativeVersion = FeatureSet . valueOf ( name . getNext ( ) . getNext ( ) . getNext ( ) . getString ( ) ) ; if ( languageOutIsAtLeast ( nativeVersion ) ) { NodeUtil . removeChild ( parent , node ) ; } } } node = next ; } }
that already contains the library ) is the same or lower than languageOut .
34,495
private void rewritePolymer1ClassDefinition ( Node node , Node parent , NodeTraversal traversal ) { Node grandparent = parent . getParent ( ) ; if ( grandparent . isConst ( ) ) { compiler . report ( JSError . make ( node , POLYMER_INVALID_DECLARATION ) ) ; return ; } PolymerClassDefinition def = PolymerClassDefinition . extractFromCallNode ( node , compiler , globalNames ) ; if ( def != null ) { if ( def . nativeBaseElement != null ) { appendPolymerElementExterns ( def ) ; } PolymerClassRewriter rewriter = new PolymerClassRewriter ( compiler , getExtensInsertionRef ( ) , polymerVersion , polymerExportPolicy , this . propertyRenamingEnabled ) ; if ( NodeUtil . isNameDeclaration ( grandparent ) || parent . isAssign ( ) ) { rewriter . rewritePolymerCall ( grandparent , def , traversal . inGlobalScope ( ) ) ; } else { rewriter . rewritePolymerCall ( parent , def , traversal . inGlobalScope ( ) ) ; } } }
Polymer 1 . x and Polymer 2 Legacy Element Definitions
34,496
private void rewritePolymer2ClassDefinition ( Node node , NodeTraversal traversal ) { PolymerClassDefinition def = PolymerClassDefinition . extractFromClassNode ( node , compiler , globalNames ) ; if ( def != null ) { PolymerClassRewriter rewriter = new PolymerClassRewriter ( compiler , getExtensInsertionRef ( ) , polymerVersion , polymerExportPolicy , this . propertyRenamingEnabled ) ; rewriter . propertySinkExternInjected = propertySinkExternInjected ; rewriter . rewritePolymerClassDeclaration ( node , traversal , def ) ; propertySinkExternInjected = rewriter . propertySinkExternInjected ; } }
Polymer 2 . x Class Nodes
34,497
private void appendPolymerElementExterns ( final PolymerClassDefinition def ) { if ( ! nativeExternsAdded . add ( def . nativeBaseElement ) ) { return ; } Node block = IR . block ( ) ; Node baseExterns = polymerElementExterns . cloneTree ( ) ; String polymerElementType = PolymerPassStaticUtils . getPolymerElementType ( def ) ; baseExterns . getFirstChild ( ) . setString ( polymerElementType ) ; String elementType = tagNameMap . get ( def . nativeBaseElement ) ; if ( elementType == null ) { compiler . report ( JSError . make ( def . descriptor , POLYMER_INVALID_EXTENDS , def . nativeBaseElement ) ) ; return ; } JSTypeExpression elementBaseType = new JSTypeExpression ( new Node ( Token . BANG , IR . string ( elementType ) ) , VIRTUAL_FILE ) ; JSDocInfoBuilder baseDocs = JSDocInfoBuilder . copyFrom ( baseExterns . getJSDocInfo ( ) ) ; baseDocs . changeBaseType ( elementBaseType ) ; baseExterns . setJSDocInfo ( baseDocs . build ( ) ) ; block . addChildToBack ( baseExterns ) ; for ( Node baseProp : polymerElementProps ) { Node newProp = baseProp . cloneTree ( ) ; Node newPropRootName = NodeUtil . getRootOfQualifiedName ( newProp . getFirstFirstChild ( ) ) ; newPropRootName . setString ( polymerElementType ) ; block . addChildToBack ( newProp ) ; } block . useSourceInfoIfMissingFromForTree ( polymerElementExterns ) ; Node parent = polymerElementExterns . getParent ( ) ; Node stmts = block . removeChildren ( ) ; parent . addChildrenAfter ( stmts , polymerElementExterns ) ; compiler . reportChangeToEnclosingScope ( stmts ) ; }
Duplicates the PolymerElement externs with a different element base class if needed . For example if the base class is HTMLInputElement then a class PolymerInputElement will be added . If the element does not extend a native HTML element this method is a no - op .
34,498
private static boolean validTemplateTypeName ( String name ) { return ! name . isEmpty ( ) && CharMatcher . javaLetterOrDigit ( ) . or ( CharMatcher . is ( '_' ) ) . matchesAllOf ( name ) ; }
The types in
34,499
private JsDocToken recordDescription ( JsDocToken token ) { if ( jsdocBuilder . shouldParseDocumentation ( ) ) { ExtractionInfo descriptionInfo = extractMultilineTextualBlock ( token ) ; token = descriptionInfo . token ; } else { token = eatTokensUntilEOL ( token ) ; } return token ; }
Records a marker s description if there is one available and record it in the current marker .