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

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

Issue 17826013: Use InheritanceManager to lookup 'iterator' getter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments. Created 7 years, 6 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/ResolverVisitor.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ResolverVisitor.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ResolverVisitor.java
index 3b558ab0f65e54f5066072da7866199962e19e5c..d278872b9dec49293dacb65e09d4dd29e5a54c05 100644
--- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ResolverVisitor.java
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ResolverVisitor.java
@@ -73,7 +73,6 @@ import com.google.dart.engine.element.ExecutableElement;
import com.google.dart.engine.element.LibraryElement;
import com.google.dart.engine.element.LocalVariableElement;
import com.google.dart.engine.element.ParameterElement;
-import com.google.dart.engine.element.PropertyAccessorElement;
import com.google.dart.engine.element.PropertyInducingElement;
import com.google.dart.engine.element.VariableElement;
import com.google.dart.engine.error.AnalysisErrorListener;
@@ -95,6 +94,11 @@ import java.util.HashMap;
*/
public class ResolverVisitor extends ScopedVisitor {
/**
+ * The manager for the inheritance mappings.
+ */
+ private final InheritanceManager inheritanceManager;
+
+ /**
* The object used to resolve the element associated with the current node.
*/
private ElementResolver elementResolver;
@@ -130,6 +134,7 @@ public class ResolverVisitor extends ScopedVisitor {
*/
public ResolverVisitor(Library library, Source source, TypeProvider typeProvider) {
super(library, source, typeProvider);
+ this.inheritanceManager = library.getInheritanceManager();
this.elementResolver = new ElementResolver(this);
this.typeAnalyzer = new StaticTypeAnalyzer(this);
}
@@ -145,8 +150,9 @@ public class ResolverVisitor extends ScopedVisitor {
* during resolution
*/
public ResolverVisitor(LibraryElement definingLibrary, Source source, TypeProvider typeProvider,
- AnalysisErrorListener errorListener) {
+ InheritanceManager inheritanceManager, AnalysisErrorListener errorListener) {
super(definingLibrary, source, typeProvider, errorListener);
+ this.inheritanceManager = inheritanceManager;
this.elementResolver = new ElementResolver(this);
this.typeAnalyzer = new StaticTypeAnalyzer(this);
}
@@ -773,7 +779,9 @@ public class ResolverVisitor extends ScopedVisitor {
if (loopVariable != null && iterator != null) {
LocalVariableElement loopElement = loopVariable.getElement();
if (loopElement != null) {
- override(loopElement, getIteratorElementType(iterator));
+ Type iteratorElementType = getIteratorElementType(iterator);
+ override(loopElement, iteratorElementType);
+ recordPropagatedType(loopVariable.getIdentifier(), iteratorElementType);
}
}
body.accept(this);
@@ -832,23 +840,23 @@ public class ResolverVisitor extends ScopedVisitor {
private Type getIteratorElementType(Expression iteratorExpression) {
Type expressionType = iteratorExpression.getStaticType();
if (expressionType instanceof InterfaceType) {
- PropertyAccessorElement iterator = ((InterfaceType) expressionType).lookUpGetter(
- "iterator",
- getDefiningLibrary());
- if (iterator == null) {
+ InterfaceType interfaceType = (InterfaceType) expressionType;
+ FunctionType iteratorFunction = inheritanceManager.lookupMemberType(interfaceType, "iterator");
+ if (iteratorFunction == null) {
// TODO(brianwilkerson) Should we report this error?
return null;
}
- Type iteratorType = iterator.getType().getReturnType();
+ Type iteratorType = iteratorFunction.getReturnType();
if (iteratorType instanceof InterfaceType) {
- PropertyAccessorElement current = ((InterfaceType) iteratorType).lookUpGetter(
- "current",
- getDefiningLibrary());
- if (current == null) {
+ InterfaceType iteratorInterfaceType = (InterfaceType) iteratorType;
+ FunctionType currentFunction = inheritanceManager.lookupMemberType(
+ iteratorInterfaceType,
+ "current");
+ if (currentFunction == null) {
// TODO(brianwilkerson) Should we report this error?
return null;
}
- return current.getType().getReturnType();
+ return currentFunction.getReturnType();
}
}
return null;
@@ -1017,4 +1025,16 @@ public class ResolverVisitor extends ScopedVisitor {
propagateTrueState(((ParenthesizedExpression) condition).getExpression());
}
}
+
+ /**
+ * Record that the propagated type of the given node is the given type.
+ *
+ * @param expression the node whose type is to be recorded
+ * @param type the propagated type of the node
+ */
+ private void recordPropagatedType(Expression expression, Type type) {
+ if (type != null && !type.isDynamic()) {
+ expression.setPropagatedType(type);
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698