Package com.google.javascript.jscomp
Class ClosureCodingConvention
java.lang.Object
com.google.javascript.jscomp.CodingConventions.Proxy
com.google.javascript.jscomp.ClosureCodingConvention
- All Implemented Interfaces:
CodingConvention
,Serializable
This describes the Closure-specific JavaScript coding conventions.
- 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 inherited from class com.google.javascript.jscomp.CodingConventions.Proxy
nextConvention
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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) Closure's goog.inherits adds asuperClass_
property to the subclass, and aconstructor
property.@Nullable CodingConvention.Cache
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.@Nullable CodingConvention.Bind
describeFunctionBind
(Node n, boolean callerChecksTypes, boolean iCheckTypes) A Bind instance or null.extractClassNameIfProvide
(Node node, Node parent) Extracts X from goog.provide('X'), if the applied Node is goog.extractClassNameIfRequire
(Node node, Node parent) Extracts X from goog.require('X'), if the applied Node is goog.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.com.google.common.collect.ImmutableSet
<CodingConvention.AssertionFunctionSpec> Returns the set of AssertionFunction.@Nullable CodingConvention.SubclassRelationship
getClassesDefinedByCall
(Node callNode) Checks if the given method defines a subclass relationship, and if it does, returns information on that relationship.Use closure's implementation.Use closure's implementation.com.google.common.collect.ImmutableSet
<String> Gets a collection of all properties that are defined indirectly on global objects.@Nullable CodingConvention.ObjectLiteralCast
getObjectLiteralCast
(Node callNode) Checks if the given method performs a object literal cast, and if it does, returns information on the cast.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
Used by CheckMissingReturn.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
isSuperClassReference
(String propertyName) Returns true if passed a string referring to the superclass.Methods inherited from class com.google.javascript.jscomp.CodingConventions.Proxy
applyDelegateRelationship, checkForCallingConventionDefinitions, defineDelegateProxyPrototypeProperties, describeFunctionBind, getDelegateRelationship, getDelegateSuperclassName, getPackageName, isClassFactoryCall, isConstant, isConstantKey, isExported, isExported, isOptionalParameter, isPrototypeAlias, isValidEnumKey, isVarArgsParameter
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
-
Constructor Details
-
ClosureCodingConvention
public ClosureCodingConvention() -
ClosureCodingConvention
-
-
Method Details
-
applySubclassRelationship
public void applySubclassRelationship(NominalTypeBuilder parent, NominalTypeBuilder child, CodingConvention.SubclassType type) Closure's goog.inherits adds asuperClass_
property to the subclass, and aconstructor
property.- Specified by:
applySubclassRelationship
in interfaceCodingConvention
- Overrides:
applySubclassRelationship
in classCodingConventions.Proxy
-
getClassesDefinedByCall
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.Understands several different inheritance patterns that occur in Google code (various uses of
inherits
andmixin
).- Specified by:
getClassesDefinedByCall
in interfaceCodingConvention
- Overrides:
getClassesDefinedByCall
in classCodingConventions.Proxy
- 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
- Overrides:
isSuperClassReference
in classCodingConventions.Proxy
-
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
- Overrides:
extractIsModuleFile
in classCodingConventions.Proxy
- Returns:
- Whether the node indicates that the file represents a "module", a file whose top level declarations are not in global scope.
-
extractClassNameIfProvide
Extracts X from goog.provide('X'), if the applied Node is goog.- Specified by:
extractClassNameIfProvide
in interfaceCodingConvention
- Overrides:
extractClassNameIfProvide
in classCodingConventions.Proxy
- Returns:
- The extracted class name, or null.
-
extractClassNameIfRequire
Extracts X from goog.require('X'), if the applied Node is goog.- Specified by:
extractClassNameIfRequire
in interfaceCodingConvention
- Overrides:
extractClassNameIfRequire
in classCodingConventions.Proxy
- Returns:
- The extracted class name, or null.
-
getExportPropertyFunction
Use closure's implementation.- Specified by:
getExportPropertyFunction
in interfaceCodingConvention
- Overrides:
getExportPropertyFunction
in classCodingConventions.Proxy
- Returns:
- closure's function name for exporting properties.
-
getExportSymbolFunction
Use closure's implementation.- Specified by:
getExportSymbolFunction
in interfaceCodingConvention
- Overrides:
getExportSymbolFunction
in classCodingConventions.Proxy
- Returns:
- closure's function name for exporting symbols.
-
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
- Overrides:
identifyTypeDeclarationCall
in classCodingConventions.Proxy
-
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
- Overrides:
getAbstractMethodName
in classCodingConventions.Proxy
- 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
- Overrides:
getSingletonGetterClassName
in classCodingConventions.Proxy
- 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
- Overrides:
applySingletonGetter
in classCodingConventions.Proxy
-
isPropertyTestFunction
Description copied from interface:CodingConvention
Whether this CALL function is testing for the existence of a property.- Specified by:
isPropertyTestFunction
in interfaceCodingConvention
- Overrides:
isPropertyTestFunction
in classCodingConventions.Proxy
-
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
- Overrides:
isPropertyRenameFunction
in classCodingConventions.Proxy
-
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
- Overrides:
isFunctionCallThatAlwaysThrows
in classCodingConventions.Proxy
-
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
- Overrides:
getObjectLiteralCast
in classCodingConventions.Proxy
- Parameters:
callNode
- A CALL node.
-
getAssertionFunctions
public com.google.common.collect.ImmutableSet<CodingConvention.AssertionFunctionSpec> getAssertionFunctions()Description copied from interface:CodingConvention
Returns the set of AssertionFunction.- Specified by:
getAssertionFunctions
in interfaceCodingConvention
- Overrides:
getAssertionFunctions
in classCodingConventions.Proxy
-
describeFunctionBind
public @Nullable 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
- Overrides:
describeFunctionBind
in classCodingConventions.Proxy
- 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
- Overrides:
describeCachingCall
in classCodingConventions.Proxy
-
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
- Overrides:
getIndirectlyDeclaredProperties
in classCodingConventions.Proxy
-