Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(973)

Unified Diff: Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/RequiredThisAnnotationChecker.java

Issue 202813004: DevTools: [JsDocValidator] Make sure function receivers agree with @this annotations (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address misunderstood comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/RequiredThisAnnotationChecker.java
diff --git a/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/RequiredThisAnnotationChecker.java b/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/RequiredThisAnnotationChecker.java
index 02a39c07498bdfb91bc98c765ac887c8c4e7f898..490438c3a98d505449b1511d9ddd07788c1b3c2a 100644
--- a/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/RequiredThisAnnotationChecker.java
+++ b/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/RequiredThisAnnotationChecker.java
@@ -2,7 +2,6 @@ package org.chromium.devtools.jsdoc.checks;
import com.google.javascript.rhino.head.Token;
import com.google.javascript.rhino.head.ast.AstNode;
-import com.google.javascript.rhino.head.ast.Comment;
import com.google.javascript.rhino.head.ast.FunctionNode;
import java.util.HashSet;
@@ -33,20 +32,23 @@ public final class RequiredThisAnnotationChecker extends ContextTrackingChecker
}
ContextTrackingState state = getState();
- FunctionRecord record = state.getCurrentFunctionRecord();
- if (!functionsRequiringThisAnnotation.contains(record)) {
+ FunctionRecord function = state.getCurrentFunctionRecord();
+ FunctionNode functionNode = (FunctionNode) node;
+ if (!functionsRequiringThisAnnotation.contains(function)) {
+ AstNode functionNameNode = AstUtil.getFunctionNameNode(functionNode);
+ if (functionNameNode != null && !function.isTopLevelFunction() &&
+ AstUtil.hasThisAnnotation(functionNode, getContext())) {
+ reportErrorAtNodeStart(
+ functionNameNode,
+ "@this annotation found for function not referencing 'this'");
+ }
return;
}
- FunctionNode functionNode = (FunctionNode) node;
AstNode functionNameNode = AstUtil.getFunctionNameNode(functionNode);
- if (functionNameNode != null && shouldAddThisAnnotation(functionNode)) {
- state.getContext().reportErrorInNode(functionNameNode, 0,
+ if (functionNameNode != null && !AstUtil.hasThisAnnotation(functionNode, getContext())) {
+ reportErrorAtNodeStart(
+ functionNameNode,
"@this annotation is required for functions referencing 'this'");
}
}
-
- private boolean shouldAddThisAnnotation(FunctionNode node) {
- Comment comment = AstUtil.getJsDocNode(node);
- return comment == null || !getContext().getNodeText(comment).contains("@this");
- }
}

Powered by Google App Engine
This is Rietveld 408576698