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

Unified Diff: third_party/WebKit/Source/devtools/scripts/jsdoc_validator/src/org/chromium/devtools/jsdoc/checks/ContextTrackingValidationCheck.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/ContextTrackingValidationCheck.java
diff --git a/third_party/WebKit/Source/devtools/scripts/jsdoc_validator/src/org/chromium/devtools/jsdoc/checks/ContextTrackingValidationCheck.java b/third_party/WebKit/Source/devtools/scripts/jsdoc_validator/src/org/chromium/devtools/jsdoc/checks/ContextTrackingValidationCheck.java
deleted file mode 100644
index 917228f499f54c7cf965bd4d1870fc254775a598..0000000000000000000000000000000000000000
--- a/third_party/WebKit/Source/devtools/scripts/jsdoc_validator/src/org/chromium/devtools/jsdoc/checks/ContextTrackingValidationCheck.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package org.chromium.devtools.jsdoc.checks;
-
-import com.google.javascript.jscomp.NodeUtil;
-import com.google.javascript.rhino.JSDocInfo;
-import com.google.javascript.rhino.Node;
-import com.google.javascript.rhino.Token;
-
-import org.chromium.devtools.jsdoc.ValidationCheck;
-import org.chromium.devtools.jsdoc.ValidatorContext;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ContextTrackingValidationCheck extends ValidationCheck {
- private ContextTrackingState state;
- private final List<ContextTrackingChecker> clients = new ArrayList<>(5);
-
- @Override
- protected void setContext(ValidatorContext context) {
- super.setContext(context);
- state = new ContextTrackingState(context);
- registerClient(new ProtoFollowsExtendsChecker());
- registerClient(new MethodAnnotationChecker());
- registerClient(new FunctionReceiverChecker());
- registerClient(new DisallowedGlobalPropertiesChecker());
- }
-
- @Override
- public void doVisit(Node node) {
- switch (node.getType()) {
- case Token.ASSIGN:
- case Token.VAR:
- enterAssignOrVarNode(node);
- break;
- case Token.FUNCTION:
- enterFunctionNode(node);
- break;
- default:
- break;
- }
-
- enterNode(node);
- }
-
- @Override
- public void didVisit(Node node) {
- leaveNode(node);
-
- switch (node.getType()) {
- case Token.ASSIGN:
- leaveAssignNode(node);
- break;
- case Token.FUNCTION:
- leaveFunctionNode(node);
- break;
- default:
- break;
- }
- }
-
- public void registerClient(ContextTrackingChecker client) {
- this.clients.add(client);
- client.setState(state);
- }
-
- private void enterNode(Node node) {
- for (ContextTrackingChecker client : clients) {
- client.enterNode(node);
- }
- }
-
- private void leaveNode(Node node) {
- for (ContextTrackingChecker client : clients) {
- client.leaveNode(node);
- }
- }
-
- private void enterFunctionNode(Node node) {
- TypeRecord parentType =
- state.getCurrentFunctionRecord() == null ? state.getCurrentTypeRecord() : null;
- Node nameNode = AstUtil.getFunctionNameNode(node);
- String functionName = nameNode == null ? null : state.getNodeText(nameNode);
- FunctionRecord functionRecord = new FunctionRecord(node, functionName,
- getFunctionParameterNames(node), parentType, state.getCurrentFunctionRecord());
- state.pushFunctionRecord(functionRecord);
- rememberTypeRecordIfNeeded(functionName, functionRecord.info);
- }
-
- @SuppressWarnings("unused")
- private void leaveFunctionNode(Node node) {
- state.functionRecords.removeLast();
- }
-
- private void enterAssignOrVarNode(Node node) {
- String assignedTypeName = getAssignedTypeName(node);
- if (assignedTypeName == null) {
- return;
- }
- if (AstUtil.isPrototypeName(assignedTypeName)) {
- // MyType.prototype = ...
- String typeName = AstUtil.getTypeNameFromPrototype(assignedTypeName);
- TypeRecord typeRecord = state.typeRecordsByTypeName.get(typeName);
- // We should push anything here to maintain a valid current type record.
- state.pushTypeRecord(typeRecord);
- state.pushFunctionRecord(null);
- return;
- }
- }
-
- private void leaveAssignNode(Node assignment) {
- String assignedTypeName = getAssignedTypeName(assignment);
- if (assignedTypeName == null) {
- return;
- }
- if (AstUtil.isPrototypeName(assignedTypeName)) {
- // Remove the current type record when leaving prototype object.
- state.typeRecords.removeLast();
- state.functionRecords.removeLast();
- return;
- }
- }
-
- private String getAssignedTypeName(Node assignment) {
- Node node = AstUtil.getAssignedTypeNameNode(assignment);
- return getNodeText(node);
- }
-
- private List<String> getFunctionParameterNames(Node functionNode) {
- List<String> parameterNames = new ArrayList<String>();
- Node parametersNode = NodeUtil.getFunctionParameters(functionNode);
- for (int i = 0, childCount = parametersNode.getChildCount(); i < childCount; ++i) {
- Node paramNode = parametersNode.getChildAtIndex(i);
- String paramName = state.getContext().getNodeText(paramNode);
- parameterNames.add(paramName);
- }
- return parameterNames;
- }
-
- private boolean rememberTypeRecordIfNeeded(String typeName, JSDocInfo info) {
- if (info == null) {
- return false;
- }
- if (typeName == null) {
- return info.isConstructor() || info.isInterface();
- }
- if (!info.isConstructor() && !info.isInterface()) {
- return false;
- }
- TypeRecord record = new TypeRecord(typeName, info);
- state.typeRecordsByTypeName.put(typeName, record);
- return true;
- }
-}

Powered by Google App Engine
This is Rietveld 408576698