final class CheckJSDoc extends NodeTraversal.AbstractPostOrderCallback implements HotSwapCompilerPass
Modifier and Type | Field and Description |
---|---|
static DiagnosticType |
ANNOTATION_DEPRECATED |
(package private) static DiagnosticType |
ARROW_FUNCTION_AS_CONSTRUCTOR |
private AbstractCompiler |
compiler |
(package private) static DiagnosticType |
DEFAULT_PARAM_MUST_BE_MARKED_OPTIONAL |
static DiagnosticType |
DISALLOWED_MEMBER_JSDOC |
static DiagnosticType |
MISPLACED_ANNOTATION |
static DiagnosticType |
MISPLACED_MSG_ANNOTATION |
Constructor and Description |
---|
CheckJSDoc(AbstractCompiler compiler) |
Modifier and Type | Method and Description |
---|---|
private boolean |
hasClassLevelJsDoc(JSDocInfo info) |
void |
hotSwapScript(Node scriptRoot,
Node originalRoot)
Process the JS with root node root.
|
private boolean |
isClass(Node n) |
private boolean |
isClassDecl(Node n) |
private boolean |
isFunctionDecl(Node n) |
private boolean |
isNameIntializeWithClass(Node n) |
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
private void |
report(Node n,
DiagnosticType type,
java.lang.String... arguments) |
private void |
reportMisplaced(Node n,
java.lang.String annotationName,
java.lang.String note) |
private void |
validateArrowFunction(Node n)
Check that an arrow function is not annotated with .
|
private void |
validateClassLevelJsDoc(Node n,
JSDocInfo info)
Checks that class-level annotations like @interface/@extends are not used on member functions.
|
private void |
validateDefaultValue(Node n,
JSDocInfo info)
Check that an arrow function is not annotated with .
|
private void |
validateDeprecatedJsDoc(Node n,
JSDocInfo info)
Checks that deprecated annotations such as @expose are not present
|
private void |
validateFunctionJsDoc(Node n,
JSDocInfo info)
Checks that JSDoc intended for a function is actually attached to a
function.
|
private void |
validateMsgJsDoc(Node n,
JSDocInfo info)
Checks that annotations for messages (
@desc , @hidden ,
and @meaning )
are in the proper place, namely on names starting with MSG_ which
indicates they should be
extracted for translation. |
private void |
validateNoCollapse(Node n,
JSDocInfo info)
Warns when nocollapse annotations are present on nodes
which are not eligible for property collapsing.
|
private void |
validateNoSideEffects(Node n,
JSDocInfo info)
Check that @nosideeeffects annotations are only present in externs.
|
private void |
validateTempates(Node n,
JSDocInfo info) |
private void |
validateTypeAnnotations(Node n,
JSDocInfo info)
Check that JSDoc with a
@type annotation is in a valid place. |
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
shouldTraverse
public static final DiagnosticType MISPLACED_MSG_ANNOTATION
public static final DiagnosticType MISPLACED_ANNOTATION
public static final DiagnosticType ANNOTATION_DEPRECATED
public static final DiagnosticType DISALLOWED_MEMBER_JSDOC
static final DiagnosticType ARROW_FUNCTION_AS_CONSTRUCTOR
static final DiagnosticType DEFAULT_PARAM_MUST_BE_MARKED_OPTIONAL
private final AbstractCompiler compiler
CheckJSDoc(AbstractCompiler compiler)
public void process(Node externs, Node root)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treepublic void hotSwapScript(Node scriptRoot, Node originalRoot)
HotSwapCompilerPass
hotSwapScript
in interface HotSwapCompilerPass
scriptRoot
- Root node corresponding to the file that is modified,
should be of type Token.SCRIPT
.originalRoot
- Root node corresponding to the original version of the
file that is modified. Should be of type token.SCRIPT
.public void visit(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in postorder (after its children have been visited).
A node is visited only if all its parents should be traversed
(NodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)
).
Implementations can have side effects (e.g. modifying the parse tree).
visit
in interface NodeTraversal.Callback
private boolean isFunctionDecl(Node n)
private boolean isClassDecl(Node n)
private boolean isNameIntializeWithClass(Node n)
private boolean isClass(Node n)
private void validateClassLevelJsDoc(Node n, JSDocInfo info)
private boolean hasClassLevelJsDoc(JSDocInfo info)
private void validateDeprecatedJsDoc(Node n, JSDocInfo info)
private void validateNoCollapse(Node n, JSDocInfo info)
private void validateFunctionJsDoc(Node n, JSDocInfo info)
private void validateMsgJsDoc(Node n, JSDocInfo info)
@desc
, @hidden
,
and @meaning
)
are in the proper place, namely on names starting with MSG_ which
indicates they should be
extracted for translation. A later pass checks that the right side is
a call to goog.getMsg.private void validateTypeAnnotations(Node n, JSDocInfo info)
@type
annotation is in a valid place.private void reportMisplaced(Node n, java.lang.String annotationName, java.lang.String note)
private void report(Node n, DiagnosticType type, java.lang.String... arguments)
private void validateArrowFunction(Node n)
private void validateDefaultValue(Node n, JSDocInfo info)