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

Unified Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java

Issue 14592005: Report CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
index ab69d17a64973804be7a11ba42e7529d41c44aa0..dc72175cf662527033df76a450b90e0daff6e6cc 100644
--- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
@@ -479,6 +479,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
checkForNonVoidReturnTypeForSetter(node.getReturnType());
} else if (node.isOperator()) {
checkForOptionalParameterInOperator(node);
+ checkForWrongNumberOfParametersForOperator(node);
checkForNonVoidReturnTypeForOperator(node);
}
checkForConcreteClassWithAbstractMember(node);
@@ -1903,6 +1904,62 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This verifies the passed operator-method declaration, has correct number of parameters.
+ * <p>
+ * This method assumes that the method declaration was tested to be an operator declaration before
+ * being called.
+ *
+ * @param node the method declaration to evaluate
+ * @return {@code true} if and only if an error code is generated on the passed node
+ * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR
+ */
+ private boolean checkForWrongNumberOfParametersForOperator(MethodDeclaration node) {
+ // prepare number of parameters
+ FormalParameterList parameterList = node.getParameters();
+ if (parameterList == null) {
+ return false;
+ }
+ int numParameters = parameterList.getParameters().size();
+ // prepare operator name
+ SimpleIdentifier nameNode = node.getName();
+ if (nameNode == null) {
+ return false;
+ }
+ String name = nameNode.getName();
+ // check for exact number of parameters
+ int expected = -1;
+ if ("[]=".equals(name)) {
+ expected = 2;
+ } else if ("<".equals(name) || ">".equals(name) || "<=".equals(name) || ">=".equals(name)
+ || "==".equals(name) || "+".equals(name) || "/".equals(name) || "~/".equals(name)
+ || "*".equals(name) || "%".equals(name) || "|".equals(name) || "^".equals(name)
+ || "&".equals(name) || "<<".equals(name) || ">>".equals(name) || "[]".equals(name)) {
+ expected = 1;
+ } else if ("~".equals(name)) {
+ expected = 0;
+ }
+ if (expected != -1 && numParameters != expected) {
+ errorReporter.reportError(
+ CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR,
+ nameNode,
+ name,
+ expected,
+ numParameters);
+ return true;
+ }
+ // check for operator "-"
+ if ("-".equals(name) && numParameters > 1) {
+ errorReporter.reportError(
+ CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS,
+ nameNode,
+ numParameters);
+ return true;
+ }
+ // OK
+ return false;
+ }
+
+ /**
* This verifies if the passed setter parameter list have only one parameter.
* <p>
* This method assumes that the method declaration was tested to be a setter before being called.

Powered by Google App Engine
This is Rietveld 408576698