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

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

Issue 14657012: Report CTEC.AMBIGUOUS_EXPORT (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Move implementation to ErrorVerifier 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 18d00a087f0bc6edee3e08a7e2725bc69259a809..6a074e4b36bdc616494a029bd56ade0db77f52a8 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
@@ -31,6 +31,7 @@ import com.google.dart.engine.ast.ConstructorName;
import com.google.dart.engine.ast.ContinueStatement;
import com.google.dart.engine.ast.DefaultFormalParameter;
import com.google.dart.engine.ast.DoStatement;
+import com.google.dart.engine.ast.ExportDirective;
import com.google.dart.engine.ast.Expression;
import com.google.dart.engine.ast.ExpressionStatement;
import com.google.dart.engine.ast.ExtendsClause;
@@ -76,6 +77,7 @@ import com.google.dart.engine.element.ClassElement;
import com.google.dart.engine.element.ConstructorElement;
import com.google.dart.engine.element.Element;
import com.google.dart.engine.element.ExecutableElement;
+import com.google.dart.engine.element.ExportElement;
import com.google.dart.engine.element.FieldElement;
import com.google.dart.engine.element.LibraryElement;
import com.google.dart.engine.element.MethodElement;
@@ -91,6 +93,8 @@ import com.google.dart.engine.internal.element.FieldFormalParameterElementImpl;
import com.google.dart.engine.internal.error.ErrorReporter;
import com.google.dart.engine.internal.resolver.InheritanceManager;
import com.google.dart.engine.internal.resolver.TypeProvider;
+import com.google.dart.engine.internal.scope.Namespace;
+import com.google.dart.engine.internal.scope.NamespaceBuilder;
import com.google.dart.engine.internal.type.DynamicTypeImpl;
import com.google.dart.engine.internal.type.VoidTypeImpl;
import com.google.dart.engine.parser.ParserErrorCode;
@@ -105,6 +109,7 @@ import com.google.dart.engine.type.TypeVariableType;
import com.google.dart.engine.utilities.dart.ParameterKind;
import java.util.HashMap;
+import java.util.Set;
/**
* Instances of the class {@code ErrorVerifier} traverse an AST structure looking for additional
@@ -201,6 +206,11 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
private HashMap<FieldElement, INIT_STATE> initialFieldElementsMap;
/**
+ * A table mapping names to the export elements exported them.
+ */
+ private HashMap<String, ExportElement> exportedNames = new HashMap<String, ExportElement>();
+
+ /**
* A list of types used by the {@link CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS} and
* {@link CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS} error codes.
*/
@@ -326,6 +336,12 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
@Override
+ public Void visitExportDirective(ExportDirective node) {
+ checkForAmbiguousExport(node);
+ return super.visitExportDirective(node);
+ }
+
+ @Override
public Void visitExtendsClause(ExtendsClause node) {
checkForExtendsDisallowedClass(node);
return super.visitExtendsClause(node);
@@ -819,6 +835,45 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This verifies that the export namespace of the passed export directive does not export any name
+ * already exported by other export directive.
+ *
+ * @param node the export directive node to report problem on
+ * @return {@code true} if and only if an error code is generated on the passed node
+ * @see CompileTimeErrorCode#AMBIGUOUS_EXPORT
+ */
+ private boolean checkForAmbiguousExport(ExportDirective node) {
+ // prepare ExportElement
+ if (!(node.getElement() instanceof ExportElement)) {
+ return false;
+ }
+ ExportElement exportElement = (ExportElement) node.getElement();
+ // prepare exported library
+ LibraryElement exportedLibrary = exportElement.getExportedLibrary();
+ if (exportedLibrary == null) {
+ return false;
+ }
+ // check exported names
+ Namespace namespace = new NamespaceBuilder().createExportNamespace(exportElement);
+ Set<String> newNames = namespace.getDefinedNames().keySet();
+ for (String name : newNames) {
+ ExportElement prevElement = exportedNames.get(name);
+ if (prevElement != null && prevElement != exportElement) {
+ errorReporter.reportError(
+ CompileTimeErrorCode.AMBIGUOUS_EXPORT,
+ node,
+ name,
+ prevElement.getExportedLibrary().getDefiningCompilationUnit().getDisplayName(),
+ exportedLibrary.getDefiningCompilationUnit().getDisplayName());
+ return true;
+ } else {
+ exportedNames.put(name, exportElement);
+ }
+ }
+ return false;
+ }
+
+ /**
* This verifies that the passed argument definition test identifier is a parameter.
*
* @param node the {@link ArgumentDefinitionTest} to evaluate

Powered by Google App Engine
This is Rietveld 408576698