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

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

Issue 14655016: Report CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix 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 81d93872d18633ae149bfa5d1607d9f8f3f9392d..b61fcbf8f1b2a156dbddac38030a180031cc8189 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
@@ -68,6 +68,7 @@ import com.google.dart.engine.ast.VariableDeclaration;
import com.google.dart.engine.ast.VariableDeclarationList;
import com.google.dart.engine.ast.VariableDeclarationStatement;
import com.google.dart.engine.ast.WhileStatement;
+import com.google.dart.engine.ast.WithClause;
import com.google.dart.engine.ast.visitor.RecursiveASTVisitor;
import com.google.dart.engine.element.ClassElement;
import com.google.dart.engine.element.ConstructorElement;
@@ -257,6 +258,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
node.getName(),
CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME);
checkForMemberWithClassName();
+ checkForMixinDeclaresConstructor(node.getWithClause());
// initialize initialFieldElementsMap
ClassElement classElement = node.getElement();
if (classElement != null) {
@@ -282,6 +284,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
checkForBuiltInIdentifierAsName(
node.getName(),
CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME);
+ checkForMixinDeclaresConstructor(node.getWithClause());
return super.visitClassTypeAlias(node);
}
@@ -1423,26 +1426,6 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
- * This verifies that the passed constructor has at most one 'super' initializer.
- *
- * @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_SUPER_INITIALIZERS
- */
- private boolean checkForMultipleSuperInitializers(ConstructorDeclaration node) {
- int numSuperInitializers = 0;
- for (ConstructorInitializer initializer : node.getInitializers()) {
- if (initializer instanceof SuperConstructorInvocation) {
- numSuperInitializers++;
- if (numSuperInitializers > 1) {
- errorReporter.reportError(CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS, initializer);
- }
- }
- }
- return numSuperInitializers > 0;
- }
-
- /**
* This verifies that the {@link #enclosingClass} does not define members with the same name as
* the enclosing class.
*
@@ -1474,6 +1457,58 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This verifies that the passed 'with' clause does not apply mixin with an explicitly declared
+ * constructor.
+ *
+ * @param node the 'with' clause to evaluate
+ * @return {@code true} if and only if an error code is generated on the passed node
+ * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR
+ */
+ private boolean checkForMixinDeclaresConstructor(WithClause withClause) {
+ if (withClause == null) {
+ return false;
+ }
+ boolean problemReported = false;
+ for (TypeName mixinName : withClause.getMixinTypes()) {
+ Type mixinType = mixinName.getType();
+ if (!(mixinType instanceof InterfaceType)) {
+ return false;
+ }
+ ClassElement mixinElement = ((InterfaceType) mixinType).getElement();
+ for (ConstructorElement constructor : mixinElement.getConstructors()) {
+ if (!constructor.isSynthetic() && !constructor.isFactory()) {
+ errorReporter.reportError(
+ CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR,
+ mixinName,
+ mixinElement.getName());
+ problemReported = true;
+ }
+ }
+ }
+ return problemReported;
+ }
+
+ /**
+ * This verifies that the passed constructor has at most one 'super' initializer.
+ *
+ * @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_SUPER_INITIALIZERS
+ */
+ private boolean checkForMultipleSuperInitializers(ConstructorDeclaration node) {
+ int numSuperInitializers = 0;
+ for (ConstructorInitializer initializer : node.getInitializers()) {
+ if (initializer instanceof SuperConstructorInvocation) {
+ numSuperInitializers++;
+ if (numSuperInitializers > 1) {
+ errorReporter.reportError(CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS, initializer);
+ }
+ }
+ }
+ return numSuperInitializers > 0;
+ }
+
+ /**
* Checks to ensure that native function bodies can only in SDK code.
*
* @param node the native function body to test

Powered by Google App Engine
This is Rietveld 408576698