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

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

Issue 2464463002: Revert of DevTools: clean up scripts folder (Closed)
Patch Set: Created 4 years, 2 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: third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/AstUtil.java
diff --git a/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/AstUtil.java b/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/AstUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..94bec2c7d64a8096625d0a8d8562f4d2da4982c1
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/AstUtil.java
@@ -0,0 +1,93 @@
+package org.chromium.devtools.jsdoc.checks;
+
+import com.google.common.base.Preconditions;
+import com.google.javascript.rhino.JSTypeExpression;
+import com.google.javascript.rhino.Node;
+import com.google.javascript.rhino.Token;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class AstUtil {
+
+ private static final String PROTOTYPE_SUFFIX = ".prototype";
+
+ static Node parentOfType(Node node, int tokenType) {
+ Node parent = node.getParent();
+ return (parent == null || parent.getType() != tokenType) ? null : parent;
+ }
+
+ /**
+ * Based on NodeUtil#getFunctionNameNode(Node).
+ */
+ static Node getFunctionNameNode(Node node) {
+ Preconditions.checkState(node.isFunction());
+
+ Node parent = node.getParent();
+ if (parent != null) {
+ switch (parent.getType()) {
+ case Token.NAME:
+ // var name = function() ...
+ // var name2 = function name1() ...
+ return parent;
+ // FIXME: Enable the setter and getter checks.
+ // case Token.SETTER_DEF:
+ // case Token.GETTER_DEF:
+ case Token.STRING_KEY:
+ return parent;
+ case Token.NUMBER:
+ return parent;
+ case Token.ASSIGN:
+ int nameType = parent.getFirstChild().getType();
+ // We only consider these types of name nodes as acceptable.
+ return nameType == Token.NAME || nameType == Token.GETPROP
+ ? parent.getFirstChild()
+ : null;
+ case Token.VAR:
+ return parent.getFirstChild();
+ default:
+ Node funNameNode = node.getFirstChild();
+ // Don't return the name node for anonymous functions
+ return funNameNode.getString().isEmpty() ? null : funNameNode;
+ }
+ }
+
+ return null;
+ }
+
+ static String getTypeNameFromPrototype(String value) {
+ return value.substring(0, value.length() - PROTOTYPE_SUFFIX.length());
+ }
+
+ static boolean isPrototypeName(String typeName) {
+ return typeName.endsWith(PROTOTYPE_SUFFIX);
+ }
+
+ static Node getAssignedTypeNameNode(Node assignment) {
+ Preconditions.checkState(assignment.isAssign() || assignment.isVar());
+ Node typeNameNode = assignment.getFirstChild();
+ if (typeNameNode.getType() != Token.GETPROP && typeNameNode.getType() != Token.NAME) {
+ return null;
+ }
+ return typeNameNode;
+ }
+
+ static List<Node> getArguments(Node functionCall) {
+ int childCount = functionCall.getChildCount();
+ if (childCount == 1) {
+ return Collections.emptyList();
+ }
+ List<Node> arguments = new ArrayList<>(childCount - 1);
+ for (int i = 1; i < childCount; ++i) {
+ arguments.add(functionCall.getChildAtIndex(i));
+ }
+ return arguments;
+ }
+
+ static String getAnnotationTypeString(JSTypeExpression expression) {
+ return expression.getRoot().getFirstChild().getString();
+ }
+
+ private AstUtil() {}
+}

Powered by Google App Engine
This is Rietveld 408576698