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

Unified Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ElementResolver.java

Issue 14671018: Report CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Check if name is resolved not to the enclosing ClassElement 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/resolver/ElementResolver.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ElementResolver.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ElementResolver.java
index 580bbacd73445b16aec5901a1dd89aa0262c85df..6675545e0e82524d93049d55b854fb722eab0f35 100644
--- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ElementResolver.java
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ElementResolver.java
@@ -218,6 +218,19 @@ public class ElementResolver extends SimpleASTVisitor<Void> {
}
/**
+ * @return {@code true} if the given identifier is the return type of a factory constructor
+ * declaration.
+ */
+ private static boolean isFactoryConstructorReturnType(SimpleIdentifier node) {
+ ASTNode parent = node.getParent();
+ if (parent instanceof ConstructorDeclaration) {
+ ConstructorDeclaration constructor = (ConstructorDeclaration) parent;
+ return constructor.getReturnType() == node && constructor.getFactoryKeyword() != null;
+ }
+ return false;
+ }
+
+ /**
* Checks if the given 'super' expression is used in the valid context.
*
* @param node the 'super' expression to analyze
@@ -907,7 +920,9 @@ public class ElementResolver extends SimpleASTVisitor<Void> {
// Otherwise, the node should be resolved.
//
Element element = resolveSimpleIdentifier(node);
- if (element == null) {
+ if (isFactoryConstructorReturnType(node) && element != resolver.getEnclosingClass()) {
+ resolver.reportError(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS, node);
+ } else if (element == null) {
// TODO(brianwilkerson) Recover from this error.
if (isConstructorReturnType(node)) {
resolver.reportError(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node);
@@ -917,6 +932,7 @@ public class ElementResolver extends SimpleASTVisitor<Void> {
} else if (element instanceof ExecutableElement) {
staticElementMap.put(node, (ExecutableElement) element);
}
+
recordResolution(node, element);
return null;
}

Powered by Google App Engine
This is Rietveld 408576698