| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library engine.resolver_test; | 5 library engine.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/context/context.dart' as newContext; | 9 import 'package:analyzer/src/context/context.dart' as newContext; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 10093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10104 | 10104 |
| 10105 void test_visitBinaryExpression_logicalOr() { | 10105 void test_visitBinaryExpression_logicalOr() { |
| 10106 // false || true | 10106 // false || true |
| 10107 Expression node = AstFactory.binaryExpression( | 10107 Expression node = AstFactory.binaryExpression( |
| 10108 AstFactory.booleanLiteral(false), TokenType.BAR_BAR, | 10108 AstFactory.booleanLiteral(false), TokenType.BAR_BAR, |
| 10109 AstFactory.booleanLiteral(true)); | 10109 AstFactory.booleanLiteral(true)); |
| 10110 expect(_analyze(node), same(_typeProvider.boolType)); | 10110 expect(_analyze(node), same(_typeProvider.boolType)); |
| 10111 _listener.assertNoErrors(); | 10111 _listener.assertNoErrors(); |
| 10112 } | 10112 } |
| 10113 | 10113 |
| 10114 void test_visitBinaryExpression_minusID_propagated() { |
| 10115 // a - b |
| 10116 BinaryExpression node = AstFactory.binaryExpression( |
| 10117 _propagatedVariable(_typeProvider.intType, 'a'), TokenType.MINUS, |
| 10118 _propagatedVariable(_typeProvider.doubleType, 'b')); |
| 10119 node.propagatedElement = getMethod(_typeProvider.numType, "+"); |
| 10120 _analyze(node); |
| 10121 expect(node.propagatedType, same(_typeProvider.doubleType)); |
| 10122 _listener.assertNoErrors(); |
| 10123 } |
| 10124 |
| 10114 void test_visitBinaryExpression_notEquals() { | 10125 void test_visitBinaryExpression_notEquals() { |
| 10115 // 2 != 3 | 10126 // 2 != 3 |
| 10116 Expression node = AstFactory.binaryExpression( | 10127 Expression node = AstFactory.binaryExpression( |
| 10117 _resolvedInteger(2), TokenType.BANG_EQ, _resolvedInteger(3)); | 10128 _resolvedInteger(2), TokenType.BANG_EQ, _resolvedInteger(3)); |
| 10118 expect(_analyze(node), same(_typeProvider.boolType)); | 10129 expect(_analyze(node), same(_typeProvider.boolType)); |
| 10119 _listener.assertNoErrors(); | 10130 _listener.assertNoErrors(); |
| 10120 } | 10131 } |
| 10121 | 10132 |
| 10122 void test_visitBinaryExpression_plusID() { | 10133 void test_visitBinaryExpression_plusID() { |
| 10123 // 1 + 2.0 | 10134 // 1 + 2.0 |
| 10124 BinaryExpression node = AstFactory.binaryExpression( | 10135 BinaryExpression node = AstFactory.binaryExpression( |
| 10125 _resolvedInteger(1), TokenType.PLUS, _resolvedDouble(2.0)); | 10136 _resolvedInteger(1), TokenType.PLUS, _resolvedDouble(2.0)); |
| 10126 node.staticElement = getMethod(_typeProvider.numType, "+"); | 10137 node.staticElement = getMethod(_typeProvider.numType, "+"); |
| 10127 expect(_analyze(node), same(_typeProvider.doubleType)); | 10138 expect(_analyze(node), same(_typeProvider.doubleType)); |
| 10128 _listener.assertNoErrors(); | 10139 _listener.assertNoErrors(); |
| 10129 } | 10140 } |
| 10130 | 10141 |
| 10131 void test_visitBinaryExpression_plusII() { | 10142 void test_visitBinaryExpression_plusII() { |
| 10132 // 1 + 2 | 10143 // 1 + 2 |
| 10133 BinaryExpression node = AstFactory.binaryExpression( | 10144 BinaryExpression node = AstFactory.binaryExpression( |
| 10134 _resolvedInteger(1), TokenType.PLUS, _resolvedInteger(2)); | 10145 _resolvedInteger(1), TokenType.PLUS, _resolvedInteger(2)); |
| 10135 node.staticElement = getMethod(_typeProvider.numType, "+"); | 10146 node.staticElement = getMethod(_typeProvider.numType, "+"); |
| 10136 expect(_analyze(node), same(_typeProvider.intType)); | 10147 expect(_analyze(node), same(_typeProvider.intType)); |
| 10137 _listener.assertNoErrors(); | 10148 _listener.assertNoErrors(); |
| 10138 } | 10149 } |
| 10139 | 10150 |
| 10151 void test_visitBinaryExpression_plusII_propagated() { |
| 10152 // a + b |
| 10153 BinaryExpression node = AstFactory.binaryExpression( |
| 10154 _propagatedVariable(_typeProvider.intType, 'a'), TokenType.PLUS, |
| 10155 _propagatedVariable(_typeProvider.intType, 'b')); |
| 10156 node.propagatedElement = getMethod(_typeProvider.numType, "+"); |
| 10157 _analyze(node); |
| 10158 expect(node.propagatedType, same(_typeProvider.intType)); |
| 10159 _listener.assertNoErrors(); |
| 10160 } |
| 10161 |
| 10140 void test_visitBinaryExpression_slash() { | 10162 void test_visitBinaryExpression_slash() { |
| 10141 // 2 / 2 | 10163 // 2 / 2 |
| 10142 BinaryExpression node = AstFactory.binaryExpression( | 10164 BinaryExpression node = AstFactory.binaryExpression( |
| 10143 _resolvedInteger(2), TokenType.SLASH, _resolvedInteger(2)); | 10165 _resolvedInteger(2), TokenType.SLASH, _resolvedInteger(2)); |
| 10144 node.staticElement = getMethod(_typeProvider.numType, "/"); | 10166 node.staticElement = getMethod(_typeProvider.numType, "/"); |
| 10145 expect(_analyze(node), same(_typeProvider.doubleType)); | 10167 expect(_analyze(node), same(_typeProvider.doubleType)); |
| 10146 _listener.assertNoErrors(); | 10168 _listener.assertNoErrors(); |
| 10147 } | 10169 } |
| 10148 | 10170 |
| 10149 void test_visitBinaryExpression_star_notSpecial() { | 10171 void test_visitBinaryExpression_star_notSpecial() { |
| (...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11097 } catch (exception) { | 11119 } catch (exception) { |
| 11098 throw new IllegalArgumentException( | 11120 throw new IllegalArgumentException( |
| 11099 "Could not create analyzer", exception); | 11121 "Could not create analyzer", exception); |
| 11100 } | 11122 } |
| 11101 } | 11123 } |
| 11102 | 11124 |
| 11103 DartType _flatten(DartType type) => | 11125 DartType _flatten(DartType type) => |
| 11104 StaticTypeAnalyzer.flattenFutures(_typeProvider, type); | 11126 StaticTypeAnalyzer.flattenFutures(_typeProvider, type); |
| 11105 | 11127 |
| 11106 /** | 11128 /** |
| 11129 * Return a simple identifier that has been resolved to a variable element wit
h the given type. |
| 11130 * |
| 11131 * @param type the type of the variable being represented |
| 11132 * @param variableName the name of the variable |
| 11133 * @return a simple identifier that has been resolved to a variable element wi
th the given type |
| 11134 */ |
| 11135 SimpleIdentifier _propagatedVariable( |
| 11136 InterfaceType type, String variableName) { |
| 11137 SimpleIdentifier identifier = AstFactory.identifier3(variableName); |
| 11138 VariableElementImpl element = |
| 11139 ElementFactory.localVariableElement(identifier); |
| 11140 element.type = type; |
| 11141 identifier.staticType = _typeProvider.dynamicType; |
| 11142 identifier.propagatedElement = element; |
| 11143 identifier.propagatedType = type; |
| 11144 return identifier; |
| 11145 } |
| 11146 |
| 11147 /** |
| 11107 * Return an integer literal that has been resolved to the correct type. | 11148 * Return an integer literal that has been resolved to the correct type. |
| 11108 * | 11149 * |
| 11109 * @param value the value of the literal | 11150 * @param value the value of the literal |
| 11110 * @return an integer literal that has been resolved to the correct type | 11151 * @return an integer literal that has been resolved to the correct type |
| 11111 */ | 11152 */ |
| 11112 DoubleLiteral _resolvedDouble(double value) { | 11153 DoubleLiteral _resolvedDouble(double value) { |
| 11113 DoubleLiteral literal = AstFactory.doubleLiteral(value); | 11154 DoubleLiteral literal = AstFactory.doubleLiteral(value); |
| 11114 literal.staticType = _typeProvider.doubleType; | 11155 literal.staticType = _typeProvider.doubleType; |
| 11115 return literal; | 11156 return literal; |
| 11116 } | 11157 } |
| (...skipping 2758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13875 // check propagated type | 13916 // check propagated type |
| 13876 FunctionType propagatedType = node.propagatedType as FunctionType; | 13917 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 13877 expect(propagatedType.returnType, test.typeProvider.stringType); | 13918 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 13878 } on AnalysisException catch (e, stackTrace) { | 13919 } on AnalysisException catch (e, stackTrace) { |
| 13879 thrownException[0] = new CaughtException(e, stackTrace); | 13920 thrownException[0] = new CaughtException(e, stackTrace); |
| 13880 } | 13921 } |
| 13881 } | 13922 } |
| 13882 return null; | 13923 return null; |
| 13883 } | 13924 } |
| 13884 } | 13925 } |
| OLD | NEW |