Class CodingConventions.Proxy
- java.lang.Object
-
- com.google.javascript.jscomp.CodingConventions.Proxy
-
- All Implemented Interfaces:
CodingConvention,java.io.Serializable
- Direct Known Subclasses:
ChromeCodingConvention,ClosureCodingConvention,GoogleCodingConvention
- Enclosing class:
- CodingConventions
@Immutable public static class CodingConventions.Proxy extends java.lang.Object implements CodingConvention
A convention that wraps another. When you want to support a new library, you should subclass this delegate, and override the methods that you want to customize. This way, a person using jQuery and Closure Library can create a new coding convention by creating a jQueryCodingConvention that delegates to a ClosureCodingConvention that delegates to a DefaultCodingConvention.- 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 Modifier and Type Field Description protected CodingConventionnextConvention
-
Constructor Summary
Constructors Modifier Constructor Description protectedProxy(CodingConvention convention)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyDelegateRelationship(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.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)In many JS libraries, the function that produces inheritance also adds properties to the superclass and/or subclass.booleanblockRenamingForProperty(java.lang.String name)Check whether the property name is eligible for renaming.voidcheckForCallingConventionDefinitions(Node n, java.util.Map<java.lang.String,java.lang.String> delegateCallingConventions)Checks for getprops that set the calling conventions on delegate methods.voiddefineDelegateProxyPrototypeProperties(JSTypeRegistry registry, java.util.List<NominalTypeBuilder> delegateProxies, java.util.Map<java.lang.String,java.lang.String> delegateCallingConventions)Defines the delegate proxy prototype properties.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)A Bind instance or null.CodingConvention.BinddescribeFunctionBind(Node n, boolean callerChecksTypes, boolean iCheckTypes)A Bind instance or null.java.lang.StringextractClassNameIfProvide(Node node, Node parent)Convenience method for determining provided dependencies amongst different JS scripts.java.lang.StringextractClassNameIfRequire(Node node, Node parent)Convenience method for determining required dependencies amongst different JS scripts.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.java.util.Collection<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.CodingConvention.DelegateRelationshipgetDelegateRelationship(Node callNode)java.lang.StringgetDelegateSuperclassName()java.lang.StringgetExportPropertyFunction()Function name used when exporting properties.java.lang.StringgetExportSymbolFunction()Function name used when exporting symbols.java.lang.StringgetGlobalObject()Gets the name of the global object.java.util.Collection<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.StringgetPackageName(StaticSourceFile source)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.booleanhasPrivacyConvention()Whether this CodingConvention includes a convention for what private names should look like.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.booleanisClassFactoryCall(Node callNode)Checks if the given method is a call to a class factory, such a factory returns a unique class.booleanisConstant(java.lang.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.booleanisConstantKey(java.lang.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.booleanisExported(java.lang.String name)Equivalent to `isExported(name, true) || isExported(name, false);`booleanisExported(java.lang.String name, boolean local)Checks whether a global variable or function name should be treated as exported, or externally referenceable.booleanisFunctionCallThatAlwaysThrows(Node n)Used by CheckMissingReturn.booleanisInlinableFunction(Node n)booleanisOptionalParameter(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.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.booleanisPrototypeAlias(Node getProp)Whether this GETPROP node is an alias for an object prototype.booleanisSuperClassReference(java.lang.String propertyName)Returns true if passed a string referring to the superclass.booleanisValidEnumKey(java.lang.String key)This checks that a givenkeymay be used as a key for an enum.booleanisVarArgsParameter(Node parameter)This checks whether a given parameter should be treated as a marker for a variable argument list function.
-
-
-
Field Detail
-
nextConvention
protected final CodingConvention nextConvention
-
-
Constructor Detail
-
Proxy
protected Proxy(CodingConvention convention)
-
-
Method Detail
-
isConstant
public boolean isConstant(java.lang.String variableName)
Description copied from interface:CodingConventionThis 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:
isConstantin interfaceCodingConvention- Parameters:
variableName- potentially constant variable name- Returns:
trueif the name should be treated as a constant.
-
isConstantKey
public boolean isConstantKey(java.lang.String keyName)
Description copied from interface:CodingConventionThis 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:
isConstantKeyin interfaceCodingConvention
-
isValidEnumKey
public boolean isValidEnumKey(java.lang.String key)
Description copied from interface:CodingConventionThis checks that a givenkeymay be used as a key for an enum.- Specified by:
isValidEnumKeyin interfaceCodingConvention- Parameters:
key- the potential key to an enum- Returns:
trueif thekeymay be used as an enum key,falseotherwise
-
isOptionalParameter
public boolean isOptionalParameter(Node parameter)
Description copied from interface:CodingConventionThis 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:
isOptionalParameterin interfaceCodingConvention- Parameters:
parameter- The parameter's node.- Returns:
trueif the parameter should be treated as an optional parameter.
-
isVarArgsParameter
public boolean isVarArgsParameter(Node parameter)
Description copied from interface:CodingConventionThis 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:
isVarArgsParameterin interfaceCodingConvention- Parameters:
parameter- The parameter's node.- Returns:
trueif the parameter should be treated as a variable length parameter.
-
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
-
isExported
public boolean isExported(java.lang.String name, boolean local)Description copied from interface:CodingConventionChecks whether a global variable or function name should be treated as exported, or externally referenceable.- Specified by:
isExportedin interfaceCodingConvention- Parameters:
name- A global variable or function name.local-trueif the name is a local variable.- Returns:
trueif the name should be considered exported.
-
isExported
public final boolean isExported(java.lang.String name)
Description copied from interface:CodingConventionEquivalent 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:
isExportedin interfaceCodingConvention
-
getPackageName
public java.lang.String getPackageName(StaticSourceFile source)
- Specified by:
getPackageNamein interfaceCodingConvention- Returns:
- the package name for the given source file, or null if no package name is known.
-
blockRenamingForProperty
public boolean blockRenamingForProperty(java.lang.String name)
Description copied from interface:CodingConventionCheck whether the property name is eligible for renaming. This method will not block removal or collapsing of the property; it will just block renaming if the property is not optimized away.- Specified by:
blockRenamingForPropertyin interfaceCodingConvention- Parameters:
name- A property name.- Returns:
trueif the name can not be renamed.
-
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- Parameters:
name- The name of a global variable or function, or a method or property.- Returns:
trueif the name should be considered private.
-
hasPrivacyConvention
public boolean hasPrivacyConvention()
Description copied from interface:CodingConventionWhether this CodingConvention includes a convention for what private names should look like.- Specified by:
hasPrivacyConventionin interfaceCodingConvention
-
getClassesDefinedByCall
public CodingConvention.SubclassRelationship getClassesDefinedByCall(Node callNode)
Description copied from interface:CodingConventionChecks 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:
getClassesDefinedByCallin interfaceCodingConvention- 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- 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
-
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
-
extractClassNameIfProvide
public java.lang.String extractClassNameIfProvide(Node node, Node parent)
Description copied from interface:CodingConventionConvenience method for determining provided dependencies amongst different JS scripts.- Specified by:
extractClassNameIfProvidein interfaceCodingConvention
-
extractClassNameIfRequire
public java.lang.String extractClassNameIfRequire(Node node, Node parent)
Description copied from interface:CodingConventionConvenience method for determining required dependencies amongst different JS scripts.- Specified by:
extractClassNameIfRequirein interfaceCodingConvention
-
getExportPropertyFunction
public java.lang.String getExportPropertyFunction()
Description copied from interface:CodingConventionFunction name used when exporting properties. Signature: fn(object, publicName, symbol).- Specified by:
getExportPropertyFunctionin interfaceCodingConvention- Returns:
- function name.
-
getExportSymbolFunction
public java.lang.String getExportSymbolFunction()
Description copied from interface:CodingConventionFunction name used when exporting symbols. Signature: fn(publicPath, object).- Specified by:
getExportSymbolFunctionin interfaceCodingConvention- Returns:
- function name.
-
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
-
applySubclassRelationship
public void applySubclassRelationship(NominalTypeBuilder parent, NominalTypeBuilder child, CodingConvention.SubclassType type)
Description copied from interface:CodingConventionIn many JS libraries, the function that produces inheritance also adds properties to the superclass and/or subclass.- Specified by:
applySubclassRelationshipin interfaceCodingConvention
-
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- 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- 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
-
isInlinableFunction
public boolean isInlinableFunction(Node n)
- Specified by:
isInlinableFunctionin interfaceCodingConvention- Returns:
- Whether the function is inlinable by convention.
-
getDelegateRelationship
public CodingConvention.DelegateRelationship getDelegateRelationship(Node callNode)
- Specified by:
getDelegateRelationshipin 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:CodingConventionIn many JS libraries, the function that creates a delegate relationship also adds properties to the delegator and delegate base.- Specified by:
applyDelegateRelationshipin interfaceCodingConvention
-
getDelegateSuperclassName
public java.lang.String getDelegateSuperclassName()
- Specified by:
getDelegateSuperclassNamein interfaceCodingConvention- Returns:
- the name of the delegate superclass.
-
checkForCallingConventionDefinitions
public void checkForCallingConventionDefinitions(Node n, java.util.Map<java.lang.String,java.lang.String> delegateCallingConventions)
Description copied from interface:CodingConventionChecks for getprops that set the calling conventions on delegate methods.- Specified by:
checkForCallingConventionDefinitionsin interfaceCodingConvention
-
defineDelegateProxyPrototypeProperties
public void defineDelegateProxyPrototypeProperties(JSTypeRegistry registry, java.util.List<NominalTypeBuilder> delegateProxies, java.util.Map<java.lang.String,java.lang.String> delegateCallingConventions)
Description copied from interface:CodingConventionDefines the delegate proxy prototype properties. Their types depend on properties of the delegate base methods.- Specified by:
defineDelegateProxyPrototypePropertiesin interfaceCodingConventiondelegateProxies- List of delegate proxy types.
-
getGlobalObject
public java.lang.String getGlobalObject()
Description copied from interface:CodingConventionGets the name of the global object.- Specified by:
getGlobalObjectin interfaceCodingConvention
-
getAssertionFunctions
public java.util.Collection<CodingConvention.AssertionFunctionSpec> getAssertionFunctions()
Description copied from interface:CodingConventionReturns the set of AssertionFunction.- Specified by:
getAssertionFunctionsin interfaceCodingConvention
-
describeFunctionBind
public CodingConvention.Bind describeFunctionBind(Node n)
Description copied from interface:CodingConventionA Bind instance or null.- Specified by:
describeFunctionBindin interfaceCodingConvention
-
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 interfaceCodingConventioncallerChecksTypes- 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
-
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
-
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
-
isPrototypeAlias
public boolean isPrototypeAlias(Node getProp)
Description copied from interface:CodingConventionWhether this GETPROP node is an alias for an object prototype.- Specified by:
isPrototypeAliasin interfaceCodingConvention
-
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- Parameters:
callNode- A CALL node.
-
getIndirectlyDeclaredProperties
public java.util.Collection<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
-
-