Class CodingConventions.Proxy
- All Implemented Interfaces:
CodingConvention
,Serializable
- Direct Known Subclasses:
ChromeCodingConvention
,ClosureCodingConvention
,GoogleCodingConvention
- Enclosing class:
CodingConventions
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.google.javascript.jscomp.CodingConvention
CodingConvention.AssertionFunctionLookup, CodingConvention.AssertionFunctionSpec, CodingConvention.Bind, CodingConvention.Cache, CodingConvention.DelegateRelationship, CodingConvention.ObjectLiteralCast, CodingConvention.SubclassRelationship, CodingConvention.SubclassType
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyDelegateRelationship
(NominalTypeBuilder delegateSuperclass, NominalTypeBuilder delegateBase, NominalTypeBuilder delegator, ObjectType delegateProxy, FunctionType findDelegate) In many JS libraries, the function that creates a delegate relationship also adds properties to the delegator and delegate base.void
applySingletonGetter
(NominalTypeBuilder classType, FunctionType getterType) In many JS libraries, the function that adds a singleton getter to a class adds properties to the class.void
applySubclassRelationship
(NominalTypeBuilder parent, NominalTypeBuilder child, CodingConvention.SubclassType type) In many JS libraries, the function that produces inheritance also adds properties to the superclass and/or subclass.void
checkForCallingConventionDefinitions
(Node n, Map<String, String> delegateCallingConventions) Checks for getprops that set the calling conventions on delegate methods.void
defineDelegateProxyPrototypeProperties
(JSTypeRegistry registry, List<NominalTypeBuilder> delegateProxies, Map<String, String> delegateCallingConventions) Defines the delegate proxy prototype properties.describeCachingCall
(Node node) Builds aCodingConvention.Cache
instance from the given call node and returns that instance, or null if theNode
does not resemble a cache utility call.A Bind instance or null.describeFunctionBind
(Node n, boolean callerChecksTypes, boolean iCheckTypes) A Bind instance or null.extractClassNameIfProvide
(Node node, Node parent) Convenience method for determining provided dependencies amongst different JS scripts.extractClassNameIfRequire
(Node node, Node parent) Convenience method for determining required dependencies amongst different JS scripts.boolean
extractIsModuleFile
(Node node, Node parent) Convenience method for determining if the node indicates the file is a "module" file (a file whose top level symbols are not in global scope).Function name for abstract methods.Returns the set of AssertionFunction.getClassesDefinedByCall
(Node callNode) Checks if the given method defines a subclass relationship, and if it does, returns information on that relationship.getDelegateRelationship
(Node callNode) Function name used when exporting properties.Function name used when exporting symbols.Gets a collection of all properties that are defined indirectly on global objects.getObjectLiteralCast
(Node callNode) Checks if the given method performs a object literal cast, and if it does, returns information on the cast.getPackageName
(StaticSourceFile source) getSingletonGetterClassName
(Node callNode) Checks if the given method defines a singleton getter, and if it does, returns the name of the class with the singleton getter.Checks if the given CALL node is forward-declaring any types, and returns the name of the types if it is.boolean
isClassFactoryCall
(Node callNode) Checks if the given method is a call to a class factory, such a factory returns a unique class.boolean
isConstant
(String variableName) This checks whether a given variable name, such as a name in all-caps should be treated as if it had the @const annotation.boolean
isConstantKey
(String keyName) This checks whether a given key of an object literal, such as a name in all-caps should be treated as if it had the @const annotation.final boolean
isExported
(String name) Equivalent to `isExported(name, true) || isExported(name, false);`boolean
isExported
(String name, boolean local) Checks whether a global variable or function name should be treated as exported, or externally referenceable.boolean
Used by CheckMissingReturn.boolean
isOptionalParameter
(Node parameter) This checks whether a given parameter name should be treated as an optional parameter as far as type checking or function call arg count checking is concerned.boolean
isPropertyRenameFunction
(Node nameNode) Whether this GETPROP or NAME node is the function is returning the string name for a property, but allows renaming.boolean
isPropertyTestFunction
(Node call) Whether this CALL function is testing for the existence of a property.boolean
isPrototypeAlias
(Node getProp) Whether this GETPROP node is an alias for an object prototype.boolean
isSuperClassReference
(String propertyName) Returns true if passed a string referring to the superclass.boolean
isValidEnumKey
(String key) This checks that a givenkey
may be used as a key for an enum.boolean
isVarArgsParameter
(Node parameter) This checks whether a given parameter should be treated as a marker for a variable argument list function.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.google.javascript.jscomp.CodingConvention
blockRenamingForProperty
-
Field Details
-
nextConvention
-
-
Constructor Details
-
Proxy
-
-
Method Details
-
isConstant
Description copied from interface:CodingConvention
This checks whether a given variable name, such as a name in all-caps should be treated as if it had the @const annotation.- Specified by:
isConstant
in interfaceCodingConvention
- Parameters:
variableName
- potentially constant variable name- Returns:
true
if the name should be treated as a constant.
-
isConstantKey
Description copied from interface:CodingConvention
This checks whether a given key of an object literal, such as a name in all-caps should be treated as if it had the @const annotation.- Specified by:
isConstantKey
in interfaceCodingConvention
-
isValidEnumKey
Description copied from interface:CodingConvention
This checks that a givenkey
may be used as a key for an enum.- Specified by:
isValidEnumKey
in interfaceCodingConvention
- Parameters:
key
- the potential key to an enum- Returns:
true
if thekey
may be used as an enum key,false
otherwise
-
isOptionalParameter
Description copied from interface:CodingConvention
This checks whether a given parameter name should be treated as an optional parameter as far as type checking or function call arg count checking is concerned. Note that an optional function parameter may be declared as a simple type and is automatically converted to a union of the declared type and Undefined.- Specified by:
isOptionalParameter
in interfaceCodingConvention
- Parameters:
parameter
- The parameter's node.- Returns:
true
if the parameter should be treated as an optional parameter.
-
isVarArgsParameter
Description copied from interface:CodingConvention
This checks whether a given parameter should be treated as a marker for a variable argument list function. A VarArgs parameter must be the last parameter in a function declaration.- Specified by:
isVarArgsParameter
in interfaceCodingConvention
- Parameters:
parameter
- The parameter's node.- Returns:
true
if the parameter should be treated as a variable length parameter.
-
isFunctionCallThatAlwaysThrows
Description copied from interface:CodingConvention
Used by CheckMissingReturn. When a function call always throws an error, it can be the last stm of a block and we don't warn about missing return.- Specified by:
isFunctionCallThatAlwaysThrows
in interfaceCodingConvention
-
isExported
Description copied from interface:CodingConvention
Checks whether a global variable or function name should be treated as exported, or externally referenceable.- Specified by:
isExported
in interfaceCodingConvention
- Parameters:
name
- A global variable or function name.local
-true
if the name is a local variable.- Returns:
true
if the name should be considered exported.
-
isExported
Description copied from interface:CodingConvention
Equivalent to `isExported(name, true) || isExported(name, false);`Should only be used to check if a property is exported. Variables should always use
CodingConvention.isExported(String, boolean)
, as in most cases local variables should not be treated as exported.Do not override! Unfortunately, that cannot be enforced without making this an abstract class.
- Specified by:
isExported
in interfaceCodingConvention
-
getPackageName
- Specified by:
getPackageName
in interfaceCodingConvention
- Returns:
- the package name for the given source file, or null if no package name is known.
-
getClassesDefinedByCall
Description copied from interface:CodingConvention
Checks if the given method defines a subclass relationship, and if it does, returns information on that relationship. By default, always returns null. Meant to be overridden by subclasses.- Specified by:
getClassesDefinedByCall
in interfaceCodingConvention
- Parameters:
callNode
- A CALL node.
-
isClassFactoryCall
Description copied from interface:CodingConvention
Checks if the given method is a call to a class factory, such a factory returns a unique class.- Specified by:
isClassFactoryCall
in interfaceCodingConvention
- Parameters:
callNode
- A CALL node.
-
isSuperClassReference
Description copied from interface:CodingConvention
Returns true if passed a string referring to the superclass. The string will usually be from the string node at the right of a GETPROP, e.g. this.superClass_.- Specified by:
isSuperClassReference
in interfaceCodingConvention
-
extractIsModuleFile
Description copied from interface:CodingConvention
Convenience method for determining if the node indicates the file is a "module" file (a file whose top level symbols are not in global scope).- Specified by:
extractIsModuleFile
in interfaceCodingConvention
-
extractClassNameIfProvide
Description copied from interface:CodingConvention
Convenience method for determining provided dependencies amongst different JS scripts.- Specified by:
extractClassNameIfProvide
in interfaceCodingConvention
-
extractClassNameIfRequire
Description copied from interface:CodingConvention
Convenience method for determining required dependencies amongst different JS scripts.- Specified by:
extractClassNameIfRequire
in interfaceCodingConvention
-
getExportPropertyFunction
Description copied from interface:CodingConvention
Function name used when exporting properties. Signature: fn(object, publicName, symbol).- Specified by:
getExportPropertyFunction
in interfaceCodingConvention
- Returns:
- function name.
-
getExportSymbolFunction
Description copied from interface:CodingConvention
Function name used when exporting symbols. Signature: fn(publicPath, object).- Specified by:
getExportSymbolFunction
in interfaceCodingConvention
- Returns:
- function name.
-
identifyTypeDeclarationCall
Description copied from interface:CodingConvention
Checks if the given CALL node is forward-declaring any types, and returns the name of the types if it is.- Specified by:
identifyTypeDeclarationCall
in interfaceCodingConvention
-
applySubclassRelationship
public void applySubclassRelationship(NominalTypeBuilder parent, NominalTypeBuilder child, CodingConvention.SubclassType type) Description copied from interface:CodingConvention
In many JS libraries, the function that produces inheritance also adds properties to the superclass and/or subclass.- Specified by:
applySubclassRelationship
in interfaceCodingConvention
-
getAbstractMethodName
Description copied from interface:CodingConvention
Function name for abstract methods. An abstract method can be assigned to an interface method instead of an function expression in order to avoid linter warnings produced by assigning a function without a return value where a return value is expected.- Specified by:
getAbstractMethodName
in interfaceCodingConvention
- Returns:
- function name.
-
getSingletonGetterClassName
Description copied from interface:CodingConvention
Checks if the given method defines a singleton getter, and if it does, returns the name of the class with the singleton getter. By default, always returns null. Meant to be overridden by subclasses. addSingletonGetter needs a coding convention because in the general case, it can't be inlined. The function inliner sees that it creates an alias to the given class in an inner closure, and bails out.- Specified by:
getSingletonGetterClassName
in interfaceCodingConvention
- Parameters:
callNode
- A CALL node.
-
applySingletonGetter
Description copied from interface:CodingConvention
In many JS libraries, the function that adds a singleton getter to a class adds properties to the class.- Specified by:
applySingletonGetter
in interfaceCodingConvention
-
getDelegateRelationship
- Specified by:
getDelegateRelationship
in interfaceCodingConvention
- Returns:
- the delegate relationship created by the call or null.
-
applyDelegateRelationship
public void applyDelegateRelationship(NominalTypeBuilder delegateSuperclass, NominalTypeBuilder delegateBase, NominalTypeBuilder delegator, ObjectType delegateProxy, FunctionType findDelegate) Description copied from interface:CodingConvention
In many JS libraries, the function that creates a delegate relationship also adds properties to the delegator and delegate base.- Specified by:
applyDelegateRelationship
in interfaceCodingConvention
-
getDelegateSuperclassName
- Specified by:
getDelegateSuperclassName
in interfaceCodingConvention
- Returns:
- the name of the delegate superclass.
-
checkForCallingConventionDefinitions
public void checkForCallingConventionDefinitions(Node n, Map<String, String> delegateCallingConventions) Description copied from interface:CodingConvention
Checks for getprops that set the calling conventions on delegate methods.- Specified by:
checkForCallingConventionDefinitions
in interfaceCodingConvention
-
defineDelegateProxyPrototypeProperties
public void defineDelegateProxyPrototypeProperties(JSTypeRegistry registry, List<NominalTypeBuilder> delegateProxies, Map<String, String> delegateCallingConventions) Description copied from interface:CodingConvention
Defines the delegate proxy prototype properties. Their types depend on properties of the delegate base methods.- Specified by:
defineDelegateProxyPrototypeProperties
in interfaceCodingConvention
- Parameters:
delegateProxies
- List of delegate proxy types.
-
getAssertionFunctions
Description copied from interface:CodingConvention
Returns the set of AssertionFunction.- Specified by:
getAssertionFunctions
in interfaceCodingConvention
-
describeFunctionBind
Description copied from interface:CodingConvention
A Bind instance or null.- Specified by:
describeFunctionBind
in interfaceCodingConvention
-
describeFunctionBind
public CodingConvention.Bind describeFunctionBind(Node n, boolean callerChecksTypes, boolean iCheckTypes) Description copied from interface:CodingConvention
A Bind instance or null.When seeing an expression exp1.bind(recv, arg1, ...); we only know that it's a function bind if exp1 has type function. W/out type info, exp1 has certainly a function type only if it's a function literal.
If type checking has already happened, exp1's type is attached to the AST node. When iCheckTypes is true, describeFunctionBind looks for that type.
- Specified by:
describeFunctionBind
in interfaceCodingConvention
- Parameters:
callerChecksTypes
- Trust that the caller of this method has verified that the bound node has a function type.iCheckTypes
- Check that the bound node has a function type.
-
describeCachingCall
Description copied from interface:CodingConvention
Builds aCodingConvention.Cache
instance from the given call node and returns that instance, or null if theNode
does not resemble a cache utility call.This should match calls to a cache utility method. This type of node is specially considered for side-effects since conventionally storing something on a cache object would be seen as a side-effect.
- Specified by:
describeCachingCall
in interfaceCodingConvention
-
isPropertyTestFunction
Description copied from interface:CodingConvention
Whether this CALL function is testing for the existence of a property.- Specified by:
isPropertyTestFunction
in interfaceCodingConvention
-
isPropertyRenameFunction
Description copied from interface:CodingConvention
Whether this GETPROP or NAME node is the function is returning the string name for a property, but allows renaming.- Specified by:
isPropertyRenameFunction
in interfaceCodingConvention
-
isPrototypeAlias
Description copied from interface:CodingConvention
Whether this GETPROP node is an alias for an object prototype.- Specified by:
isPrototypeAlias
in interfaceCodingConvention
-
getObjectLiteralCast
Description copied from interface:CodingConvention
Checks if the given method performs a object literal cast, and if it does, returns information on the cast. By default, always returns null. Meant to be overridden by subclasses.- Specified by:
getObjectLiteralCast
in interfaceCodingConvention
- Parameters:
callNode
- A CALL node.
-
getIndirectlyDeclaredProperties
Description copied from interface:CodingConvention
Gets a collection of all properties that are defined indirectly on global objects. (For example, Closure defines superClass_ in the goog.inherits call).- Specified by:
getIndirectlyDeclaredProperties
in interfaceCodingConvention
-