Package com.google.javascript.jscomp
Interface CodingConvention
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
ClosureCodingConvention
,CodingConventions.Proxy
,GoogleCodingConvention
,JqueryCodingConvention
CodingConvention defines a set of hooks to customize the behavior of the
Compiler for a specific team/company.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
A function that will throw an exception when either: -One or more of its parameters evaluate to false.static class
static class
Delegates provides a mechanism and structure for identifying where classes can call out to optional code to augment their functionality.static class
An object literal cast provides a mechanism to cast object literals to other types without a warning.static class
static enum
-
Method Summary
Modifier and TypeMethodDescriptionvoid
applyDelegateRelationship
(ObjectType delegateSuperclass, ObjectType delegateBase, ObjectType delegator, FunctionType 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
(FunctionType functionType, FunctionType getterType, ObjectType objectType) In many JS libraries, the function that adds a singleton getter to a class adds properties to the class.void
applySubclassRelationship
(FunctionType parentCtor, FunctionType childCtor, CodingConvention.SubclassType type) In many JS libraries, the function that produces inheritance also adds properties to the superclass and/or subclass.void
checkForCallingConventionDefiningCalls
(Node n, Map<String, String> delegateCallingConventions) Checks for function calls that set the calling conventions on delegate methods.void
defineDelegateProxyPrototypeProperties
(JSTypeRegistry registry, StaticScope<JSType> scope, List<ObjectType> delegateProxyPrototypes, Map<String, String> delegateCallingConventions) Defines the delegate proxy prototype properties.A Bind instance or null.describeFunctionBind
(Node n, boolean useTypeInfo) 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.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 the name of the global object.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.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
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.boolean
isExported
(String name) Should be 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
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
Checks whether a name should be considered private.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.
-
Method Details
-
isConstant
This checks whether a given variable name, such as a name in all-caps should be treated as if it had the @const annotation.- Parameters:
variableName
- potentially constant variable name- Returns:
true
if the name should be treated as a constant.
-
isConstantKey
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. -
isValidEnumKey
This checks that a givenkey
may be used as a key for an enum.- Parameters:
key
- the potential key to an enum- Returns:
true
if thekey
may be used as an enum key,false
otherwise
-
isOptionalParameter
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.- Parameters:
parameter
- The parameter's node.- Returns:
true
if the parameter should be treated as an optional parameter.
-
isVarArgsParameter
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.- Parameters:
parameter
- The parameter's node.- Returns:
true
if the parameter should be treated as a variable length parameter.
-
isExported
Checks whether a global variable or function name should be treated as exported, or externally referenceable.- 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
Should be isExported(name, true) || isExported(name, false); -
isPrivate
Checks whether a name should be considered private. Private global variables and functions can only be referenced within the source file in which they are declared. Private properties and methods should only be accessed by the class that defines them.- Parameters:
name
- The name of a global variable or function, or a method or property.- Returns:
true
if the name should be considered private.
-
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.- Parameters:
callNode
- A CALL node.
-
isSuperClassReference
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_. -
extractClassNameIfProvide
Convenience method for determining provided dependencies amongst different JS scripts. -
extractClassNameIfRequire
Convenience method for determining required dependencies amongst different JS scripts. -
getExportPropertyFunction
String getExportPropertyFunction()Function name used when exporting properties. Signature: fn(object, publicName, symbol).- Returns:
- function name.
-
getExportSymbolFunction
String getExportSymbolFunction()Function name used when exporting symbols. Signature: fn(publicPath, object).- Returns:
- function name.
-
identifyTypeDeclarationCall
Checks if the given CALL node is forward-declaring any types, and returns the name of the types if it is. -
applySubclassRelationship
void applySubclassRelationship(FunctionType parentCtor, FunctionType childCtor, CodingConvention.SubclassType type) In many JS libraries, the function that produces inheritance also adds properties to the superclass and/or subclass. -
getAbstractMethodName
String getAbstractMethodName()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.- Returns:
- function name.
-
getSingletonGetterClassName
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.- Parameters:
callNode
- A CALL node.
-
applySingletonGetter
void applySingletonGetter(FunctionType functionType, FunctionType getterType, ObjectType objectType) In many JS libraries, the function that adds a singleton getter to a class adds properties to the class. -
isInlinableFunction
- Returns:
- Whether the function is inlinable by convention.
-
getDelegateRelationship
- Returns:
- the delegate relationship created by the call or null.
-
applyDelegateRelationship
void applyDelegateRelationship(ObjectType delegateSuperclass, ObjectType delegateBase, ObjectType delegator, FunctionType delegateProxy, FunctionType findDelegate) In many JS libraries, the function that creates a delegate relationship also adds properties to the delegator and delegate base. -
getDelegateSuperclassName
String getDelegateSuperclassName()- Returns:
- the name of the delegate superclass.
-
checkForCallingConventionDefiningCalls
Checks for function calls that set the calling conventions on delegate methods. -
defineDelegateProxyPrototypeProperties
void defineDelegateProxyPrototypeProperties(JSTypeRegistry registry, StaticScope<JSType> scope, List<ObjectType> delegateProxyPrototypes, Map<String, String> delegateCallingConventions) Defines the delegate proxy prototype properties. Their types depend on properties of the delegate base methods.- Parameters:
delegateProxyPrototypes
- List of delegate proxy prototypes.
-
getGlobalObject
String getGlobalObject()Gets the name of the global object. -
describeFunctionBind
A Bind instance or null. -
describeFunctionBind
A Bind instance or null.- Parameters:
useTypeInfo
- If we believe type information is reliable enough to use to figure out what the bind function is.
-
isPropertyTestFunction
Whether this CALL function is testing for the existence of a property. -
isPrototypeAlias
Whether this GETPROP node is an alias for an object prototype. -
getObjectLiteralCast
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.- Parameters:
callNode
- A CALL node.
-
getIndirectlyDeclaredProperties
Collection<String> getIndirectlyDeclaredProperties()Gets a collection of all properties that are defined indirectly on global objects. (For example, Closure defines superClass_ in the goog.inherits call). -
getAssertionFunctions
Collection<CodingConvention.AssertionFunctionSpec> getAssertionFunctions()Returns the set of AssertionFunction.
-