| Index: third_party/WebKit/Source/devtools/scripts/jsdoc_validator/src/org/chromium/devtools/jsdoc/checks/FunctionReceiverChecker.java
|
| diff --git a/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/FunctionReceiverChecker.java b/third_party/WebKit/Source/devtools/scripts/jsdoc_validator/src/org/chromium/devtools/jsdoc/checks/FunctionReceiverChecker.java
|
| similarity index 80%
|
| rename from third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/FunctionReceiverChecker.java
|
| rename to third_party/WebKit/Source/devtools/scripts/jsdoc_validator/src/org/chromium/devtools/jsdoc/checks/FunctionReceiverChecker.java
|
| index 21e8681173d6dde121007f68d2ec823f8dc0447e..d7b6c01ecb28048ca7901a1836cebc869a15c9e2 100644
|
| --- a/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/checks/FunctionReceiverChecker.java
|
| +++ b/third_party/WebKit/Source/devtools/scripts/jsdoc_validator/src/org/chromium/devtools/jsdoc/checks/FunctionReceiverChecker.java
|
| @@ -12,7 +12,6 @@ import java.util.Map;
|
| import java.util.Set;
|
|
|
| public final class FunctionReceiverChecker extends ContextTrackingChecker {
|
| -
|
| private static final Set<String> FUNCTIONS_WITH_CALLBACK_RECEIVER_AS_SECOND_ARGUMENT =
|
| new HashSet<>();
|
| private static final String SUPPRESSION_HINT = "This check can be suppressed using "
|
| @@ -34,19 +33,19 @@ public final class FunctionReceiverChecker extends ContextTrackingChecker {
|
| @Override
|
| void enterNode(Node node) {
|
| switch (node.getType()) {
|
| - case Token.CALL:
|
| - handleCall(node);
|
| - break;
|
| - case Token.FUNCTION: {
|
| - handleFunction(node);
|
| - break;
|
| - }
|
| - case Token.THIS: {
|
| - handleThis();
|
| - break;
|
| - }
|
| - default:
|
| - break;
|
| + case Token.CALL:
|
| + handleCall(node);
|
| + break;
|
| + case Token.FUNCTION: {
|
| + handleFunction(node);
|
| + break;
|
| + }
|
| + case Token.THIS: {
|
| + handleThis();
|
| + break;
|
| + }
|
| + default:
|
| + break;
|
| }
|
| }
|
|
|
| @@ -62,24 +61,23 @@ public final class FunctionReceiverChecker extends ContextTrackingChecker {
|
| saveSymbolicArguments(functionName, argumentNodes, actualArguments);
|
|
|
| boolean isBindCall = partCount > 1 && "bind".equals(functionName);
|
| - if (isBindCall && partCount == 3 && "this".equals(firstPart) &&
|
| - !(actualArguments.size() > 0 && "this".equals(actualArguments.get(0)))) {
|
| - reportErrorAtNodeStart(functionCall,
|
| - "Member function can only be bound to 'this' as the receiver");
|
| - return;
|
| + if (isBindCall && partCount == 3 && "this".equals(firstPart)
|
| + && !(actualArguments.size() > 0 && "this".equals(actualArguments.get(0)))) {
|
| + reportErrorAtNodeStart(
|
| + functionCall, "Member function can only be bound to 'this' as the receiver");
|
| + return;
|
| }
|
| if (partCount > 2 || "this".equals(firstPart)) {
|
| return;
|
| }
|
| boolean hasReceiver = isBindCall && isReceiverSpecified(actualArguments);
|
| - hasReceiver |= (partCount == 2) &&
|
| - ("call".equals(functionName) || "apply".equals(functionName)) &&
|
| - isReceiverSpecified(actualArguments);
|
| + hasReceiver |= (partCount == 2)
|
| + && ("call".equals(functionName) || "apply".equals(functionName))
|
| + && isReceiverSpecified(actualArguments);
|
| getOrCreateSetByKey(callSitesByFunctionName, firstPart)
|
| .add(new CallSite(hasReceiver, functionCall));
|
| }
|
|
|
| -
|
| private void handleFunction(Node node) {
|
| Preconditions.checkState(node.isFunction());
|
| FunctionRecord function = getState().getCurrentFunctionRecord();
|
| @@ -127,27 +125,27 @@ public final class FunctionReceiverChecker extends ContextTrackingChecker {
|
| if (argumentCount >= 2) {
|
| receiverPresence = CheckedReceiverPresence.PRESENT;
|
| }
|
| - } else if ("addEventListener".equals(functionName) ||
|
| - "removeEventListener".equals(functionName)) {
|
| + } else if ("addEventListener".equals(functionName)
|
| + || "removeEventListener".equals(functionName)) {
|
| String receiverArgument = argumentCount < 3 ? "" : arguments.get(2);
|
| switch (receiverArgument) {
|
| - case "":
|
| - case "true":
|
| - case "false":
|
| - receiverPresence = CheckedReceiverPresence.MISSING;
|
| - break;
|
| - case "this":
|
| - receiverPresence = CheckedReceiverPresence.PRESENT;
|
| - break;
|
| - default:
|
| - receiverPresence = CheckedReceiverPresence.IGNORE;
|
| + case "":
|
| + case "true":
|
| + case "false":
|
| + receiverPresence = CheckedReceiverPresence.MISSING;
|
| + break;
|
| + case "this":
|
| + receiverPresence = CheckedReceiverPresence.PRESENT;
|
| + break;
|
| + default:
|
| + receiverPresence = CheckedReceiverPresence.IGNORE;
|
| }
|
| }
|
|
|
| for (int i = 0; i < argumentCount; ++i) {
|
| String argumentText = arguments.get(i);
|
| - getOrCreateSetByKey(symbolicArgumentsByName, argumentText).add(
|
| - new SymbolicArgument(receiverPresence, argumentNodes.get(i)));
|
| + getOrCreateSetByKey(symbolicArgumentsByName, argumentText)
|
| + .add(new SymbolicArgument(receiverPresence, argumentNodes.get(i)));
|
| }
|
| }
|
|
|
| @@ -199,9 +197,8 @@ public final class FunctionReceiverChecker extends ContextTrackingChecker {
|
| return;
|
| }
|
| int errorTargetOffset = functionNameNode == null
|
| - ? (function.info == null
|
| - ? function.functionNode.getSourceOffset()
|
| - : function.info.getOriginalCommentPosition())
|
| + ? (function.info == null ? function.functionNode.getSourceOffset()
|
| + : function.info.getOriginalCommentPosition())
|
| : functionNameNode.getSourceOffset();
|
| boolean hasThisAnnotation = function.hasThisAnnotation();
|
| if (hasThisAnnotation == functionReferencesThis(function)) {
|
| @@ -209,14 +206,12 @@ public final class FunctionReceiverChecker extends ContextTrackingChecker {
|
| }
|
| if (hasThisAnnotation) {
|
| if (!function.isTopLevelFunction()) {
|
| - reportErrorAtOffset(
|
| - errorTargetOffset,
|
| + reportErrorAtOffset(errorTargetOffset,
|
| "@this annotation found for function not referencing 'this'");
|
| }
|
| return;
|
| } else {
|
| - reportErrorAtOffset(
|
| - errorTargetOffset,
|
| + reportErrorAtOffset(errorTargetOffset,
|
| "@this annotation is required for functions referencing 'this'");
|
| }
|
| }
|
| @@ -255,28 +250,23 @@ public final class FunctionReceiverChecker extends ContextTrackingChecker {
|
| if (argument.receiverPresence == CheckedReceiverPresence.IGNORE) {
|
| continue;
|
| }
|
| - boolean receiverProvided =
|
| - argument.receiverPresence == CheckedReceiverPresence.PRESENT;
|
| + boolean receiverProvided = argument.receiverPresence == CheckedReceiverPresence.PRESENT;
|
| if (referencesThis == receiverProvided) {
|
| continue;
|
| }
|
| if (referencesThis) {
|
| - reportErrorAtNodeStart(argument.node,
|
| - "Function referencing 'this' used as argument without " +
|
| - "a receiver. " + SUPPRESSION_HINT);
|
| + reportErrorAtNodeStart(
|
| + argument.node, "Function referencing 'this' used as argument without "
|
| + + "a receiver. " + SUPPRESSION_HINT);
|
| } else {
|
| - reportErrorAtNodeStart(argument.node,
|
| - "Function not referencing 'this' used as argument with " +
|
| - "a receiver. " + SUPPRESSION_HINT);
|
| + reportErrorAtNodeStart(
|
| + argument.node, "Function not referencing 'this' used as argument with "
|
| + + "a receiver. " + SUPPRESSION_HINT);
|
| }
|
| }
|
| }
|
|
|
| - private static enum CheckedReceiverPresence {
|
| - PRESENT,
|
| - MISSING,
|
| - IGNORE
|
| - }
|
| + private static enum CheckedReceiverPresence { PRESENT, MISSING, IGNORE }
|
|
|
| private static class SymbolicArgument {
|
| CheckedReceiverPresence receiverPresence;
|
|
|