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

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

Issue 15316011: Report MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS and other redirection related. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments 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 4fd859780bf0a5c385dc637fe17867ec2749659a..9db388c3184781527d5b63a19a5eafc6cc5f9799 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
@@ -347,6 +347,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
checkForConstConstructorWithNonFinalField(node);
checkForConflictingConstructorNameAndMember(node);
checkForAllFinalInitializedErrorCodes(node);
+ checkForRedirectingConstructorErrorCodes(node);
checkForMultipleSuperInitializers(node);
checkForRecursiveConstructorRedirect(node);
checkForRecursiveFactoryRedirect(node);
@@ -396,7 +397,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
@Override
public Void visitFieldFormalParameter(FieldFormalParameter node) {
checkForConstFormalParameter(node);
- checkForFieldInitializerOutsideConstructor(node);
+ checkForFieldInitializingFormalRedirectingConstructor(node);
return super.visitFieldFormalParameter(node);
}
@@ -1671,7 +1672,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
* @return {@code true} if and only if an error code is generated on the passed node
* @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR
*/
- private boolean checkForFieldInitializerOutsideConstructor(FieldFormalParameter node) {
+ private boolean checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParameter node) {
ConstructorDeclaration constructor = node.getAncestor(ConstructorDeclaration.class);
if (constructor == null) {
errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, node);
@@ -2417,6 +2418,52 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This checks the passed constructor declaration has a valid combination of redirected
+ * constructor invocation(s), super constructor invocations and field initializers.
+ *
+ * @param node the constructor declaration to evaluate
+ * @return {@code true} if and only if an error code is generated on the passed node
+ * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS
+ * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR
+ * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR
+ */
+ private boolean checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) {
+ int numProblems = 0;
+ // check if there are redirected invocations
+ int numRedirections = 0;
+ for (ConstructorInitializer initializer : node.getInitializers()) {
+ if (initializer instanceof RedirectingConstructorInvocation) {
+ if (numRedirections > 0) {
+ errorReporter.reportError(
+ CompileTimeErrorCode.MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS,
+ initializer);
+ numProblems++;
+ }
+ numRedirections++;
+ }
+ }
+ // check for other initializers
+ if (numRedirections > 0) {
+ for (ConstructorInitializer initializer : node.getInitializers()) {
+ if (initializer instanceof SuperConstructorInvocation) {
+ errorReporter.reportError(
+ CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR,
+ initializer);
+ numProblems++;
+ }
+ if (initializer instanceof ConstructorFieldInitializer) {
+ errorReporter.reportError(
+ CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR,
+ initializer);
+ numProblems++;
+ }
+ }
+ }
+ // done
+ return numProblems != 0;
+ }
+
+ /**
* This checks if the passed constructor declaration has redirected constructor with compatible
* function type.
*

Powered by Google App Engine
This is Rietveld 408576698