| Index: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/StaticTypeAnalyzer.java
|
| diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/StaticTypeAnalyzer.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/StaticTypeAnalyzer.java
|
| index 6cbe31773b80ec2778b2e7e804b8bc43d0e0c99b..eae7b2c6cc55d4aae2f9cfa2276a7c0972ac0604 100644
|
| --- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/StaticTypeAnalyzer.java
|
| +++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/StaticTypeAnalyzer.java
|
| @@ -13,6 +13,7 @@
|
| */
|
| package com.google.dart.engine.internal.resolver;
|
|
|
| +import com.google.common.annotations.VisibleForTesting;
|
| import com.google.dart.engine.ast.ASTNode;
|
| import com.google.dart.engine.ast.AdjacentStrings;
|
| import com.google.dart.engine.ast.ArgumentDefinitionTest;
|
| @@ -215,6 +216,17 @@ public class StaticTypeAnalyzer extends SimpleASTVisitor<Void> {
|
| }
|
|
|
| /**
|
| + * Return a table mapping nodes in the AST to the element produced based on static type
|
| + * information.
|
| + *
|
| + * @return the static element map
|
| + */
|
| + @VisibleForTesting
|
| + public HashMap<ASTNode, ExecutableElement> getStaticElementMap() {
|
| + return staticElementMap;
|
| + }
|
| +
|
| + /**
|
| * Set the type of the class being analyzed to the given type.
|
| *
|
| * @param thisType the type representing the class containing the nodes being analyzed
|
| @@ -374,25 +386,7 @@ public class StaticTypeAnalyzer extends SimpleASTVisitor<Void> {
|
| public Void visitBinaryExpression(BinaryExpression node) {
|
| ExecutableElement staticMethodElement = staticElementMap.get(node);
|
| Type staticType = computeReturnType(staticMethodElement);
|
| - TokenType operator = node.getOperator().getType();
|
| - if (operator == TokenType.AMPERSAND_AMPERSAND || operator == TokenType.BAR_BAR
|
| - || operator == TokenType.EQ_EQ || operator == TokenType.BANG_EQ) {
|
| - staticType = typeProvider.getBoolType();
|
| - } else if (operator == TokenType.MINUS || operator == TokenType.PERCENT
|
| - || operator == TokenType.PLUS || operator == TokenType.STAR
|
| - || operator == TokenType.TILDE_SLASH) {
|
| - Type intType = typeProvider.getIntType();
|
| - if (getStaticType(node.getLeftOperand()) == intType
|
| - && getStaticType(node.getRightOperand()) == intType) {
|
| - staticType = intType;
|
| - }
|
| - } else if (operator == TokenType.SLASH) {
|
| - Type doubleType = typeProvider.getDoubleType();
|
| - if (getStaticType(node.getLeftOperand()) == doubleType
|
| - || getStaticType(node.getRightOperand()) == doubleType) {
|
| - staticType = doubleType;
|
| - }
|
| - }
|
| + staticType = refineBinaryExpressionType(node, staticType);
|
| recordStaticType(node, staticType);
|
|
|
| MethodElement propagatedMethodElement = node.getElement();
|
| @@ -1627,6 +1621,42 @@ public class StaticTypeAnalyzer extends SimpleASTVisitor<Void> {
|
| }
|
|
|
| /**
|
| + * Attempts to make a better guess for the static type of the given binary expression.
|
| + *
|
| + * @param node the binary expression to analyze
|
| + * @param staticType the static type of the expression as resolved
|
| + * @return the better type guess, or the same static type as given
|
| + */
|
| + private Type refineBinaryExpressionType(BinaryExpression node, Type staticType) {
|
| + TokenType operator = node.getOperator().getType();
|
| + // bool
|
| + if (operator == TokenType.AMPERSAND_AMPERSAND || operator == TokenType.BAR_BAR
|
| + || operator == TokenType.EQ_EQ || operator == TokenType.BANG_EQ) {
|
| + return typeProvider.getBoolType();
|
| + }
|
| + // int op double
|
| + if (operator == TokenType.MINUS || operator == TokenType.PERCENT || operator == TokenType.PLUS
|
| + || operator == TokenType.STAR) {
|
| + Type doubleType = typeProvider.getDoubleType();
|
| + if (getStaticType(node.getLeftOperand()) == doubleType
|
| + || getStaticType(node.getRightOperand()) == doubleType) {
|
| + return doubleType;
|
| + }
|
| + }
|
| + // int op int
|
| + if (operator == TokenType.MINUS || operator == TokenType.PERCENT || operator == TokenType.PLUS
|
| + || operator == TokenType.STAR || operator == TokenType.TILDE_SLASH) {
|
| + Type intType = typeProvider.getIntType();
|
| + if (getStaticType(node.getLeftOperand()) == intType
|
| + && getStaticType(node.getRightOperand()) == intType) {
|
| + staticType = intType;
|
| + }
|
| + }
|
| + // default
|
| + return staticType;
|
| + }
|
| +
|
| + /**
|
| * Set the return type and parameter type information for the given function type based on the
|
| * given return type and parameter elements.
|
| *
|
|
|