com.google.javascript.jscomp
Class ClosureCodingConvention

java.lang.Object
  extended by com.google.javascript.jscomp.CodingConventions.Proxy
      extended by com.google.javascript.jscomp.ClosureCodingConvention
All Implemented Interfaces:
CodingConvention, Serializable

public 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.AssertionFunctionSpec, CodingConvention.Bind, CodingConvention.DelegateRelationship, CodingConvention.ObjectLiteralCast, CodingConvention.SubclassRelationship, CodingConvention.SubclassType
 
Field Summary
 
Fields inherited from class com.google.javascript.jscomp.CodingConventions.Proxy
nextConvention
 
Constructor Summary
ClosureCodingConvention()
           
ClosureCodingConvention(CodingConvention wrapped)
           
 
Method Summary
 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)
          Closure's goog.inherits adds a superClass_ property to the subclass, and a constructor property.
 CodingConvention.Bind describeFunctionBind(Node n)
          A Bind instance or null.
 String extractClassNameIfProvide(Node node, Node parent)
          Exctracts X from goog.provide('X'), if the applied Node is goog.
 String extractClassNameIfRequire(Node node, Node parent)
          Exctracts X from goog.require('X'), if the applied Node is goog.
 String getAbstractMethodName()
          Function name for abstract methods.
 Collection<CodingConvention.AssertionFunctionSpec> getAssertionFunctions()
          Returns the set of AssertionFunction.
 CodingConvention.SubclassRelationship getClassesDefinedByCall(Node callNode)
          Checks if the given method defines a subclass relationship, and if it does, returns information on that relationship.
 String getExportPropertyFunction()
          Use closure's implementation.
 String getExportSymbolFunction()
          Use closure's implementation.
 String getGlobalObject()
          Gets the name of the global object.
 CodingConvention.ObjectLiteralCast getObjectLiteralCast(NodeTraversal t, Node callNode)
          Checks if the given method performs a object literal cast, and if it does, returns information on the cast.
 String 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.
 List<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.
 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 isPrivate(String name)
          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 isSuperClassReference(String propertyName)
          Returns true if passed a string referring to the superclass.
 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 com.google.javascript.jscomp.CodingConventions.Proxy
applyDelegateRelationship, checkForCallingConventionDefiningCalls, defineDelegateProxyPrototypeProperties, getDelegateRelationship, getDelegateSuperclassName, isConstant, isConstantKey, isExported, isExported, isPrototypeAlias, isValidEnumKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClosureCodingConvention

public ClosureCodingConvention()

ClosureCodingConvention

public ClosureCodingConvention(CodingConvention wrapped)
Method Detail

applySubclassRelationship

public void applySubclassRelationship(FunctionType parentCtor,
                                      FunctionType childCtor,
                                      CodingConvention.SubclassType type)
Closure's goog.inherits adds a superClass_ property to the subclass, and a constructor property.

Specified by:
applySubclassRelationship in interface CodingConvention
Overrides:
applySubclassRelationship in class CodingConventions.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 inherits and mixin).

Specified by:
getClassesDefinedByCall in interface CodingConvention
Overrides:
getClassesDefinedByCall in class CodingConventions.Proxy
Parameters:
callNode - A CALL node.

isSuperClassReference

public boolean isSuperClassReference(String propertyName)
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 interface CodingConvention
Overrides:
isSuperClassReference in class CodingConventions.Proxy

extractClassNameIfProvide

public String extractClassNameIfProvide(Node node,
                                        Node parent)
Exctracts X from goog.provide('X'), if the applied Node is goog.

Specified by:
extractClassNameIfProvide in interface CodingConvention
Overrides:
extractClassNameIfProvide in class CodingConventions.Proxy
Returns:
The extracted class name, or null.

extractClassNameIfRequire

public String extractClassNameIfRequire(Node node,
                                        Node parent)
Exctracts X from goog.require('X'), if the applied Node is goog.

Specified by:
extractClassNameIfRequire in interface CodingConvention
Overrides:
extractClassNameIfRequire in class CodingConventions.Proxy
Returns:
The extracted class name, or null.

getExportPropertyFunction

public String getExportPropertyFunction()
Use closure's implementation.

Specified by:
getExportPropertyFunction in interface CodingConvention
Overrides:
getExportPropertyFunction in class CodingConventions.Proxy
Returns:
closure's function name for exporting properties.

getExportSymbolFunction

public String getExportSymbolFunction()
Use closure's implementation.

Specified by:
getExportSymbolFunction in interface CodingConvention
Overrides:
getExportSymbolFunction in class CodingConventions.Proxy
Returns:
closure's function name for exporting symbols.

identifyTypeDeclarationCall

public List<String> identifyTypeDeclarationCall(Node n)
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 interface CodingConvention
Overrides:
identifyTypeDeclarationCall in class CodingConventions.Proxy

getAbstractMethodName

public String 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 interface CodingConvention
Overrides:
getAbstractMethodName in class CodingConventions.Proxy
Returns:
function name.

getSingletonGetterClassName

public String getSingletonGetterClassName(Node callNode)
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.

Specified by:
getSingletonGetterClassName in interface CodingConvention
Overrides:
getSingletonGetterClassName in class CodingConventions.Proxy
Parameters:
callNode - A CALL node.

applySingletonGetter

public void applySingletonGetter(FunctionType functionType,
                                 FunctionType getterType,
                                 ObjectType objectType)
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 interface CodingConvention
Overrides:
applySingletonGetter in class CodingConventions.Proxy

getGlobalObject

public String getGlobalObject()
Description copied from interface: CodingConvention
Gets the name of the global object.

Specified by:
getGlobalObject in interface CodingConvention
Overrides:
getGlobalObject in class CodingConventions.Proxy

isPropertyTestFunction

public boolean isPropertyTestFunction(Node call)
Description copied from interface: CodingConvention
Whether this CALL function is testing for the existence of a property.

Specified by:
isPropertyTestFunction in interface CodingConvention
Overrides:
isPropertyTestFunction in class CodingConventions.Proxy

getObjectLiteralCast

public CodingConvention.ObjectLiteralCast getObjectLiteralCast(NodeTraversal t,
                                                               Node callNode)
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 interface CodingConvention
Overrides:
getObjectLiteralCast in class CodingConventions.Proxy
Parameters:
t - The node traversal.
callNode - A CALL node.

isOptionalParameter

public boolean isOptionalParameter(Node parameter)
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 interface CodingConvention
Overrides:
isOptionalParameter in class CodingConventions.Proxy
Parameters:
parameter - The parameter's node.
Returns:
true if the parameter should be treated as an optional parameter.

isVarArgsParameter

public boolean isVarArgsParameter(Node parameter)
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 interface CodingConvention
Overrides:
isVarArgsParameter in class CodingConventions.Proxy
Parameters:
parameter - The parameter's node.
Returns:
true if the parameter should be treated as a variable length parameter.

isPrivate

public boolean isPrivate(String name)
Description copied from interface: CodingConvention
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.

Specified by:
isPrivate in interface CodingConvention
Overrides:
isPrivate in class CodingConventions.Proxy
Parameters:
name - The name of a global variable or function, or a method or property.
Returns:
true if the name should be considered private.

getAssertionFunctions

public Collection<CodingConvention.AssertionFunctionSpec> getAssertionFunctions()
Description copied from interface: CodingConvention
Returns the set of AssertionFunction.

Specified by:
getAssertionFunctions in interface CodingConvention
Overrides:
getAssertionFunctions in class CodingConventions.Proxy

describeFunctionBind

public CodingConvention.Bind describeFunctionBind(Node n)
Description copied from interface: CodingConvention
A Bind instance or null.

Specified by:
describeFunctionBind in interface CodingConvention
Overrides:
describeFunctionBind in class CodingConventions.Proxy