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,java.io.Serializable
@Immutable public final class ClosureCodingConvention extends CodingConventions.Proxy
This describes the Closure-specific JavaScript coding conventions.- See Also:
- Serialized Form
-
-
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 Constructor Description ClosureCodingConvention()ClosureCodingConvention(CodingConvention wrapped)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplySingletonGetter(NominalTypeBuilder classType, FunctionType getterType)In many JS libraries, the function that adds a singleton getter to a class adds properties to the class.voidapplySubclassRelationship(NominalTypeBuilder parent, NominalTypeBuilder child, CodingConvention.SubclassType type)Closure's goog.inherits adds asuperClass_property to the subclass, and aconstructorproperty.CodingConvention.CachedescribeCachingCall(Node node)Builds aCodingConvention.Cacheinstance from the given call node and returns that instance, or null if theNodedoes not resemble a cache utility call.CodingConvention.BinddescribeFunctionBind(Node n, boolean callerChecksTypes, boolean iCheckTypes)A Bind instance or null.java.lang.StringextractClassNameIfProvide(Node node, Node parent)Extracts X from goog.provide('X'), if the applied Node is goog.java.lang.StringextractClassNameIfRequire(Node node, Node parent)Extracts X from goog.require('X'), if the applied Node is goog.booleanextractIsModuleFile(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).java.lang.StringgetAbstractMethodName()Function name for abstract methods.com.google.common.collect.ImmutableCollection<CodingConvention.AssertionFunctionSpec>getAssertionFunctions()Returns the set of AssertionFunction.CodingConvention.SubclassRelationshipgetClassesDefinedByCall(Node callNode)Checks if the given method defines a subclass relationship, and if it does, returns information on that relationship.java.lang.StringgetExportPropertyFunction()Use closure's implementation.java.lang.StringgetExportSymbolFunction()Use closure's implementation.java.lang.StringgetGlobalObject()Gets the name of the global object.com.google.common.collect.ImmutableCollection<java.lang.String>getIndirectlyDeclaredProperties()Gets a collection of all properties that are defined indirectly on global objects.CodingConvention.ObjectLiteralCastgetObjectLiteralCast(Node callNode)Checks if the given method performs a object literal cast, and if it does, returns information on the cast.java.lang.StringgetSingletonGetterClassName(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.java.util.List<java.lang.String>identifyTypeDeclarationCall(Node n)Checks if the given CALL node is forward-declaring any types, and returns the name of the types if it is.booleanisAliasingGlobalThis(Node n)Whether this statement is creating an alias of the global objectbooleanisClassFactoryCall(Node callNode)Checks if the given method is a call to a class factory, such a factory returns a unique class.booleanisFunctionCallThatAlwaysThrows(Node n)Used by CheckMissingReturn.booleanisPrivate(java.lang.String name)Checks whether a name should be considered private.booleanisPropertyRenameFunction(java.lang.String name)Whether this CALL function is returning the string name for a property, but allows renaming.booleanisPropertyTestFunction(Node call)Whether this CALL function is testing for the existence of a property.booleanisSuperClassReference(java.lang.String propertyName)Returns true if passed a string referring to the superclass.-
Methods inherited from class com.google.javascript.jscomp.CodingConventions.Proxy
applyDelegateRelationship, blockRenamingForProperty, checkForCallingConventionDefinitions, defineDelegateProxyPrototypeProperties, describeFunctionBind, getDelegateRelationship, getDelegateSuperclassName, getPackageName, hasPrivacyConvention, isConstant, isConstantKey, isExported, isExported, isInlinableFunction, isOptionalParameter, isPrototypeAlias, isValidEnumKey, isVarArgsParameter
-
-
-
-
Constructor Detail
-
ClosureCodingConvention
public ClosureCodingConvention()
-
ClosureCodingConvention
public ClosureCodingConvention(CodingConvention wrapped)
-
-
Method Detail
-
applySubclassRelationship
public void applySubclassRelationship(NominalTypeBuilder parent, NominalTypeBuilder child, CodingConvention.SubclassType type)
Closure's goog.inherits adds asuperClass_property to the subclass, and aconstructorproperty.- Specified by:
applySubclassRelationshipin interfaceCodingConvention- Overrides:
applySubclassRelationshipin classCodingConventions.Proxy
-
getClassesDefinedByCall
public CodingConvention.SubclassRelationship getClassesDefinedByCall(Node callNode)
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
inheritsandmixin).- Specified by:
getClassesDefinedByCallin interfaceCodingConvention- Overrides:
getClassesDefinedByCallin classCodingConventions.Proxy- Parameters:
callNode- A CALL node.
-
isClassFactoryCall
public boolean isClassFactoryCall(Node callNode)
Description copied from interface:CodingConventionChecks if the given method is a call to a class factory, such a factory returns a unique class.- Specified by:
isClassFactoryCallin interfaceCodingConvention- Overrides:
isClassFactoryCallin classCodingConventions.Proxy- Parameters:
callNode- A CALL node.
-
isSuperClassReference
public boolean isSuperClassReference(java.lang.String propertyName)
Description copied from interface:CodingConventionReturns 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:
isSuperClassReferencein interfaceCodingConvention- Overrides:
isSuperClassReferencein classCodingConventions.Proxy
-
extractIsModuleFile
public boolean extractIsModuleFile(Node node, Node parent)
Description copied from interface:CodingConventionConvenience 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:
extractIsModuleFilein interfaceCodingConvention- Overrides:
extractIsModuleFilein 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
public java.lang.String extractClassNameIfProvide(Node node, Node parent)
Extracts X from goog.provide('X'), if the applied Node is goog.- Specified by:
extractClassNameIfProvidein interfaceCodingConvention- Overrides:
extractClassNameIfProvidein classCodingConventions.Proxy- Returns:
- The extracted class name, or null.
-
extractClassNameIfRequire
public java.lang.String extractClassNameIfRequire(Node node, Node parent)
Extracts X from goog.require('X'), if the applied Node is goog.- Specified by:
extractClassNameIfRequirein interfaceCodingConvention- Overrides:
extractClassNameIfRequirein classCodingConventions.Proxy- Returns:
- The extracted class name, or null.
-
getExportPropertyFunction
public java.lang.String getExportPropertyFunction()
Use closure's implementation.- Specified by:
getExportPropertyFunctionin interfaceCodingConvention- Overrides:
getExportPropertyFunctionin classCodingConventions.Proxy- Returns:
- closure's function name for exporting properties.
-
getExportSymbolFunction
public java.lang.String getExportSymbolFunction()
Use closure's implementation.- Specified by:
getExportSymbolFunctionin interfaceCodingConvention- Overrides:
getExportSymbolFunctionin classCodingConventions.Proxy- Returns:
- closure's function name for exporting symbols.
-
identifyTypeDeclarationCall
public java.util.List<java.lang.String> identifyTypeDeclarationCall(Node n)
Description copied from interface:CodingConventionChecks if the given CALL node is forward-declaring any types, and returns the name of the types if it is.- Specified by:
identifyTypeDeclarationCallin interfaceCodingConvention- Overrides:
identifyTypeDeclarationCallin classCodingConventions.Proxy
-
getAbstractMethodName
public java.lang.String getAbstractMethodName()
Description copied from interface:CodingConventionFunction 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:
getAbstractMethodNamein interfaceCodingConvention- Overrides:
getAbstractMethodNamein classCodingConventions.Proxy- Returns:
- function name.
-
getSingletonGetterClassName
public java.lang.String getSingletonGetterClassName(Node callNode)
Description copied from interface:CodingConventionChecks 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:
getSingletonGetterClassNamein interfaceCodingConvention- Overrides:
getSingletonGetterClassNamein classCodingConventions.Proxy- Parameters:
callNode- A CALL node.
-
applySingletonGetter
public void applySingletonGetter(NominalTypeBuilder classType, FunctionType getterType)
Description copied from interface:CodingConventionIn many JS libraries, the function that adds a singleton getter to a class adds properties to the class.- Specified by:
applySingletonGetterin interfaceCodingConvention- Overrides:
applySingletonGetterin classCodingConventions.Proxy
-
getGlobalObject
public java.lang.String getGlobalObject()
Description copied from interface:CodingConventionGets the name of the global object.- Specified by:
getGlobalObjectin interfaceCodingConvention- Overrides:
getGlobalObjectin classCodingConventions.Proxy
-
isAliasingGlobalThis
public boolean isAliasingGlobalThis(Node n)
Description copied from interface:CodingConventionWhether this statement is creating an alias of the global object- Specified by:
isAliasingGlobalThisin interfaceCodingConvention- Overrides:
isAliasingGlobalThisin classCodingConventions.Proxy
-
isPropertyTestFunction
public boolean isPropertyTestFunction(Node call)
Description copied from interface:CodingConventionWhether this CALL function is testing for the existence of a property.- Specified by:
isPropertyTestFunctionin interfaceCodingConvention- Overrides:
isPropertyTestFunctionin classCodingConventions.Proxy
-
isPropertyRenameFunction
public boolean isPropertyRenameFunction(java.lang.String name)
Description copied from interface:CodingConventionWhether this CALL function is returning the string name for a property, but allows renaming.- Specified by:
isPropertyRenameFunctionin interfaceCodingConvention- Overrides:
isPropertyRenameFunctionin classCodingConventions.Proxy
-
isFunctionCallThatAlwaysThrows
public boolean isFunctionCallThatAlwaysThrows(Node n)
Description copied from interface:CodingConventionUsed 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:
isFunctionCallThatAlwaysThrowsin interfaceCodingConvention- Overrides:
isFunctionCallThatAlwaysThrowsin classCodingConventions.Proxy
-
getObjectLiteralCast
public CodingConvention.ObjectLiteralCast getObjectLiteralCast(Node callNode)
Description copied from interface:CodingConventionChecks 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:
getObjectLiteralCastin interfaceCodingConvention- Overrides:
getObjectLiteralCastin classCodingConventions.Proxy- Parameters:
callNode- A CALL node.
-
isPrivate
public boolean isPrivate(java.lang.String name)
Description copied from interface:CodingConventionChecks 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.- Specified by:
isPrivatein interfaceCodingConvention- Overrides:
isPrivatein classCodingConventions.Proxy- Parameters:
name- The name of a global variable or function, or a method or property.- Returns:
trueif the name should be considered private.
-
getAssertionFunctions
public com.google.common.collect.ImmutableCollection<CodingConvention.AssertionFunctionSpec> getAssertionFunctions()
Description copied from interface:CodingConventionReturns the set of AssertionFunction.- Specified by:
getAssertionFunctionsin interfaceCodingConvention- Overrides:
getAssertionFunctionsin classCodingConventions.Proxy
-
describeFunctionBind
public CodingConvention.Bind describeFunctionBind(Node n, boolean callerChecksTypes, boolean iCheckTypes)
Description copied from interface:CodingConventionA 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:
describeFunctionBindin interfaceCodingConvention- Overrides:
describeFunctionBindin classCodingConventions.ProxycallerChecksTypes- 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
public CodingConvention.Cache describeCachingCall(Node node)
Description copied from interface:CodingConventionBuilds aCodingConvention.Cacheinstance from the given call node and returns that instance, or null if theNodedoes 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:
describeCachingCallin interfaceCodingConvention- Overrides:
describeCachingCallin classCodingConventions.Proxy
-
getIndirectlyDeclaredProperties
public com.google.common.collect.ImmutableCollection<java.lang.String> getIndirectlyDeclaredProperties()
Description copied from interface:CodingConventionGets a collection of all properties that are defined indirectly on global objects. (For example, Closure defines superClass_ in the goog.inherits call).- Specified by:
getIndirectlyDeclaredPropertiesin interfaceCodingConvention- Overrides:
getIndirectlyDeclaredPropertiesin classCodingConventions.Proxy
-
-