Class CodingConventions.Proxy

java.lang.Object
com.google.javascript.jscomp.CodingConventions.Proxy
All Implemented Interfaces:
CodingConvention, Serializable
Direct Known Subclasses:
ClosureCodingConvention, GoogleCodingConvention, JqueryCodingConvention
Enclosing class:
CodingConventions

public static class CodingConventions.Proxy extends 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:
  • Field Details

  • Constructor Details

  • Method Details

    • isConstant

      public boolean isConstant(String variableName)
      Description copied from interface: CodingConvention
      This 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:
      isConstant in interface CodingConvention
      Parameters:
      variableName - potentially constant variable name
      Returns:
      true if the name should be treated as a constant.
    • isConstantKey

      public boolean isConstantKey(String keyName)
      Description copied from interface: CodingConvention
      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.
      Specified by:
      isConstantKey in interface CodingConvention
    • isValidEnumKey

      public boolean isValidEnumKey(String key)
      Description copied from interface: CodingConvention
      This checks that a given key may be used as a key for an enum.
      Specified by:
      isValidEnumKey in interface CodingConvention
      Parameters:
      key - the potential key to an enum
      Returns:
      true if the key may be used as an enum key, false otherwise
    • 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
      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
      Parameters:
      parameter - The parameter's node.
      Returns:
      true if the parameter should be treated as a variable length parameter.
    • isExported

      public boolean isExported(String name, boolean local)
      Description copied from interface: CodingConvention
      Checks whether a global variable or function name should be treated as exported, or externally referenceable.
      Specified by:
      isExported in interface CodingConvention
      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

      public final boolean isExported(String name)
      Description copied from interface: CodingConvention
      Should be isExported(name, true) || isExported(name, false);
      Specified by:
      isExported in interface CodingConvention
    • 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
      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

      public CodingConvention.SubclassRelationship getClassesDefinedByCall(Node callNode)
      Description copied from interface: CodingConvention
      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.
      Specified by:
      getClassesDefinedByCall in interface CodingConvention
      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
    • extractClassNameIfProvide

      public String extractClassNameIfProvide(Node node, Node parent)
      Description copied from interface: CodingConvention
      Convenience method for determining provided dependencies amongst different JS scripts.
      Specified by:
      extractClassNameIfProvide in interface CodingConvention
    • extractClassNameIfRequire

      public String extractClassNameIfRequire(Node node, Node parent)
      Description copied from interface: CodingConvention
      Convenience method for determining required dependencies amongst different JS scripts.
      Specified by:
      extractClassNameIfRequire in interface CodingConvention
    • getExportPropertyFunction

      public String getExportPropertyFunction()
      Description copied from interface: CodingConvention
      Function name used when exporting properties. Signature: fn(object, publicName, symbol).
      Specified by:
      getExportPropertyFunction in interface CodingConvention
      Returns:
      function name.
    • getExportSymbolFunction

      public String getExportSymbolFunction()
      Description copied from interface: CodingConvention
      Function name used when exporting symbols. Signature: fn(publicPath, object).
      Specified by:
      getExportSymbolFunction in interface CodingConvention
      Returns:
      function name.
    • 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
    • applySubclassRelationship

      public void applySubclassRelationship(FunctionType parentCtor, FunctionType childCtor, CodingConvention.SubclassType type)
      Description copied from interface: CodingConvention
      In many JS libraries, the function that produces inheritance also adds properties to the superclass and/or subclass.
      Specified by:
      applySubclassRelationship in interface CodingConvention
    • 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
      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. 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 interface CodingConvention
      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
    • isInlinableFunction

      public boolean isInlinableFunction(Node n)
      Specified by:
      isInlinableFunction in interface CodingConvention
      Returns:
      Whether the function is inlinable by convention.
    • getDelegateRelationship

      public CodingConvention.DelegateRelationship getDelegateRelationship(Node callNode)
      Specified by:
      getDelegateRelationship in interface CodingConvention
      Returns:
      the delegate relationship created by the call or null.
    • applyDelegateRelationship

      public void applyDelegateRelationship(ObjectType delegateSuperclass, ObjectType delegateBase, ObjectType delegator, FunctionType delegateProxy, FunctionType findDelegate)
      Description copied from interface: CodingConvention
      In many JS libraries, the function that creates a delegate relationship also adds properties to the delegator and delegate base.
      Specified by:
      applyDelegateRelationship in interface CodingConvention
    • getDelegateSuperclassName

      public String getDelegateSuperclassName()
      Specified by:
      getDelegateSuperclassName in interface CodingConvention
      Returns:
      the name of the delegate superclass.
    • checkForCallingConventionDefiningCalls

      public void checkForCallingConventionDefiningCalls(Node n, Map<String,String> delegateCallingConventions)
      Description copied from interface: CodingConvention
      Checks for function calls that set the calling conventions on delegate methods.
      Specified by:
      checkForCallingConventionDefiningCalls in interface CodingConvention
    • defineDelegateProxyPrototypeProperties

      public void defineDelegateProxyPrototypeProperties(JSTypeRegistry registry, StaticScope<JSType> scope, List<ObjectType> delegateProxyPrototypes, Map<String,String> delegateCallingConventions)
      Description copied from interface: CodingConvention
      Defines the delegate proxy prototype properties. Their types depend on properties of the delegate base methods.
      Specified by:
      defineDelegateProxyPrototypeProperties in interface CodingConvention
      delegateProxyPrototypes - List of delegate proxy prototypes.
    • getGlobalObject

      public String getGlobalObject()
      Description copied from interface: CodingConvention
      Gets the name of the global object.
      Specified by:
      getGlobalObject in interface CodingConvention
    • getAssertionFunctions

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

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

      public CodingConvention.Bind describeFunctionBind(Node n, boolean useTypeInfo)
      Description copied from interface: CodingConvention
      A Bind instance or null.
      Specified by:
      describeFunctionBind in interface CodingConvention
      useTypeInfo - If we believe type information is reliable enough to use to figure out what the bind function is.
    • 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
    • isPrototypeAlias

      public boolean isPrototypeAlias(Node getProp)
      Description copied from interface: CodingConvention
      Whether this GETPROP node is an alias for an object prototype.
      Specified by:
      isPrototypeAlias in interface CodingConvention
    • getObjectLiteralCast

      public CodingConvention.ObjectLiteralCast getObjectLiteralCast(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
      Parameters:
      callNode - A CALL node.
    • getIndirectlyDeclaredProperties

      public Collection<String> 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 interface CodingConvention