public class GoogleCodingConvention extends CodingConventions.Proxy
CodingConvention.AssertionFunctionSpec, CodingConvention.Bind, CodingConvention.Cache, CodingConvention.DelegateRelationship, CodingConvention.ObjectLiteralCast, CodingConvention.SubclassRelationship, CodingConvention.SubclassType
nextConvention
Constructor and Description |
---|
GoogleCodingConvention()
By default, decorate the ClosureCodingConvention.
|
GoogleCodingConvention(CodingConvention convention)
Decorates a wrapped CodingConvention.
|
Modifier and Type | Method and Description |
---|---|
String |
getPackageName(StaticSourceFile source) |
boolean |
hasPrivacyConvention()
Whether this CodingConvention includes a convention for what private names should look like.
|
boolean |
isClassFactoryCall(Node callNode)
Checks if the given method is a call to a class factory, such a factory returns a
unique class.
|
boolean |
isConstant(String name)
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 name)
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,
boolean local)
Checks whether a global variable or function name should be treated as
exported, or externally referenceable.
|
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 |
isValidEnumKey(String key)
This checks that a given
key 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.
|
applyDelegateRelationship, applySingletonGetterNew, applySingletonGetterOld, applySubclassRelationship, blockRenamingForProperty, checkForCallingConventionDefiningCalls, defineDelegateProxyPrototypeProperties, describeCachingCall, describeFunctionBind, describeFunctionBind, extractClassNameIfProvide, extractClassNameIfRequire, extractIsModuleFile, getAbstractMethodName, getAssertionFunctions, getClassesDefinedByCall, getDelegateRelationship, getDelegateSuperclassName, getExportPropertyFunction, getExportSymbolFunction, getGlobalObject, getIndirectlyDeclaredProperties, getObjectLiteralCast, getSingletonGetterClassName, identifyTypeDeclarationCall, isAliasingGlobalThis, isExported, isFunctionCallThatAlwaysThrows, isInlinableFunction, isPropertyRenameFunction, isPropertyTestFunction, isPrototypeAlias, isSuperClassReference
public GoogleCodingConvention()
public GoogleCodingConvention(CodingConvention convention)
public boolean isConstant(String name)
This enforces the Google const name convention, that the first character after the last $ must be an upper-case letter and all subsequent letters must be upper case. The name must be at least 2 characters long.
Examples:
aaa Not constant - lower-case letters in the name A Not constant - too short goog$A Constant - letters after the $ are upper-case. AA17 Constant - digits can appear after the first letter goog$7A Not constant - first character after the $ must be upper case. $A Constant - doesn't have to be anything in front of the $
isConstant
in interface CodingConvention
isConstant
in class CodingConventions.Proxy
name
- potentially constant variable nametrue
if the name should be treated as a constant.public boolean isConstantKey(String name)
CodingConvention
isConstantKey
in interface CodingConvention
isConstantKey
in class CodingConventions.Proxy
public boolean isValidEnumKey(String key)
key
may be used as a key for an enum.
This enforces Google's convention about enum key names. They must match
the regular expression [A-Z0-9][A-Z0-9_]*
.
Examples:
isValidEnumKey
in interface CodingConvention
isValidEnumKey
in class CodingConventions.Proxy
key
- the potential key to an enumtrue
if the key
may be used as an enum key,
false
otherwisepublic boolean isOptionalParameter(Node parameter)
In Google code, parameter names beginning with opt_
are
treated as optional arguments.
isOptionalParameter
in interface CodingConvention
isOptionalParameter
in class CodingConventions.Proxy
parameter
- The parameter's node.true
if the parameter should be treated as an optional
parameter.public boolean isVarArgsParameter(Node parameter)
CodingConvention
isVarArgsParameter
in interface CodingConvention
isVarArgsParameter
in class CodingConventions.Proxy
parameter
- The parameter's node.true
if the parameter should be treated as a variable
length parameter.public boolean isExported(String name, boolean local)
In Google code, any global name starting with an underscore is considered exported.
isExported
in interface CodingConvention
isExported
in class CodingConventions.Proxy
name
- A global variable or function name.local
- true
if the name is a local variable.true
if the name should be considered exported.public boolean isClassFactoryCall(Node callNode)
CodingConvention
isClassFactoryCall
in interface CodingConvention
isClassFactoryCall
in class CodingConventions.Proxy
callNode
- A CALL node.public String getPackageName(StaticSourceFile source)
In Google code, the package name of a source file is its file path. Exceptions: if a source file's parent directory is "test", "tests", or "testing", that directory is stripped from the package name. If a file is generated, strip the "genfiles" prefix to try to match the package of the generating file.
getPackageName
in interface CodingConvention
getPackageName
in class CodingConventions.Proxy
public boolean isPrivate(String name)
In Google code, private names end with an underscore, and exported
names are never considered private (see isExported(java.lang.String, boolean)
).
isPrivate
in interface CodingConvention
isPrivate
in class CodingConventions.Proxy
name
- The name of a global variable or function, or a method or
property.true
if the name should be considered private.public boolean hasPrivacyConvention()
CodingConvention
hasPrivacyConvention
in interface CodingConvention
hasPrivacyConvention
in class CodingConventions.Proxy
Copyright © 2009-2017 Google. All Rights Reserved.