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

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

Issue 218993012: DevTools: [JsDocValidator] Handle types declared as top-level vars (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Move case to keep the order consistent between methods 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/AstUtil.java
diff --git a/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/AstUtil.java b/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/AstUtil.java
index e930753e756c595a39c5cb44173d26b6c2f51aff..503c9b180cc8892ae29e5b8befba72c1510d30da 100644
--- a/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/AstUtil.java
+++ b/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/AstUtil.java
@@ -6,17 +6,15 @@ 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 com.google.javascript.rhino.head.ast.ObjectProperty;
+import com.google.javascript.rhino.head.ast.VariableInitializer;
public class AstUtil {
private static final String PROTOTYPE_SUFFIX = ".prototype";
- static boolean hasParentOfType(AstNode node, int tokenType) {
+ static AstNode parentOfType(AstNode node, int tokenType) {
AstNode parent = node.getParent();
- if (parent == null) {
- return false;
- }
- return parent.getType() == tokenType;
+ return (parent == null || parent.getType() != tokenType) ? null : parent;
}
static AstNode getFunctionNameNode(FunctionNode functionNode) {
@@ -25,16 +23,24 @@ public class AstUtil {
return nameNode;
}
- if (AstUtil.hasParentOfType(functionNode, Token.COLON)) {
- return ((ObjectProperty) functionNode.getParent()).getLeft();
+ AstNode parentNode = functionNode.getParent();
+ if (parentNode == null) {
+ return null;
}
- if (AstUtil.hasParentOfType(functionNode, Token.ASSIGN)) {
- Assignment assignment = (Assignment) functionNode.getParent();
+ switch (parentNode.getType()) {
+ case Token.COLON:
+ return ((ObjectProperty) parentNode).getLeft();
+ case Token.ASSIGN:
+ Assignment assignment = (Assignment) parentNode;
if (assignment.getRight() == functionNode) {
return assignment.getLeft();
}
+ break;
+ case Token.VAR:
+ return ((VariableInitializer) parentNode).getTarget();
}
+
return null;
}
@@ -69,22 +75,24 @@ public class AstUtil {
}
// reader.onloadend = function() {...}
- if (hasParentOfType(functionNode, Token.ASSIGN)) {
- Assignment assignment = (Assignment) functionNode.getParent();
- if (assignment.getRight() == functionNode) {
- jsDocNode = assignment.getJsDocNode();
- if (jsDocNode != null) {
- return jsDocNode;
- }
- }
+ AstNode parentNode = functionNode.getParent();
+ if (parentNode == null) {
+ return null;
}
- if (hasParentOfType(functionNode, Token.COLON)) {
- jsDocNode = ((ObjectProperty) functionNode.getParent()).getLeft().getJsDocNode();
- if (jsDocNode != null) {
- return jsDocNode;
+ switch (parentNode.getType()) {
+ case Token.COLON:
+ return ((ObjectProperty) parentNode).getLeft().getJsDocNode();
+ case Token.ASSIGN:
+ Assignment assignment = (Assignment) parentNode;
+ if (assignment.getRight() == functionNode) {
+ return assignment.getJsDocNode();
}
+ break;
+ case Token.VAR:
+ return parentNode.getParent().getJsDocNode();
}
+
return null;
}

Powered by Google App Engine
This is Rietveld 408576698