OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:analyzer/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
7 import 'package:analyzer/dart/ast/token.dart'; | 7 import 'package:analyzer/dart/ast/token.dart'; |
8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
9 import 'package:analyzer/dart/element/type.dart'; | 9 import 'package:analyzer/dart/element/type.dart'; |
10 import 'package:analyzer/src/dart/element/element.dart'; | 10 import 'package:analyzer/src/dart/element/element.dart'; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 return AstTestFactory.prefixExpression(TokenType.BANG, operand); | 255 return AstTestFactory.prefixExpression(TokenType.BANG, operand); |
256 } | 256 } |
257 | 257 |
258 if (expr is kernel.LogicalExpression) { | 258 if (expr is kernel.LogicalExpression) { |
259 var operator = _toBinaryOperatorTokenType(expr.operator); | 259 var operator = _toBinaryOperatorTokenType(expr.operator); |
260 var left = build(expr.left); | 260 var left = build(expr.left); |
261 var right = build(expr.right); | 261 var right = build(expr.right); |
262 return AstTestFactory.binaryExpression(left, operator, right); | 262 return AstTestFactory.binaryExpression(left, operator, right); |
263 } | 263 } |
264 | 264 |
| 265 if (expr is kernel.Let) { |
| 266 var body = expr.body; |
| 267 if (body is kernel.ConditionalExpression) { |
| 268 var condition = body.condition; |
| 269 var otherwiseExpr = body.otherwise; |
| 270 if (condition is kernel.MethodInvocation) { |
| 271 var equalsReceiver = condition.receiver; |
| 272 if (equalsReceiver is kernel.VariableGet && |
| 273 condition.name.name == '==' && |
| 274 condition.arguments.positional.length == 1 && |
| 275 condition.arguments.positional[0] is kernel.NullLiteral && |
| 276 otherwiseExpr is kernel.VariableGet && |
| 277 otherwiseExpr.variable == equalsReceiver.variable) { |
| 278 var left = build(expr.variable.initializer); |
| 279 var right = build(body.then); |
| 280 return AstTestFactory.binaryExpression( |
| 281 left, TokenType.QUESTION_QUESTION, right); |
| 282 } |
| 283 } |
| 284 } |
| 285 } |
| 286 |
265 if (expr is kernel.MethodInvocation) { | 287 if (expr is kernel.MethodInvocation) { |
266 kernel.Member member = expr.interfaceTarget; | 288 kernel.Member member = expr.interfaceTarget; |
267 if (member is kernel.Procedure) { | 289 if (member is kernel.Procedure) { |
268 if (member.kind == kernel.ProcedureKind.Operator) { | 290 if (member.kind == kernel.ProcedureKind.Operator) { |
269 var left = build(expr.receiver); | 291 var left = build(expr.receiver); |
270 String operatorName = expr.name.name; | 292 String operatorName = expr.name.name; |
271 List<kernel.Expression> args = expr.arguments.positional; | 293 List<kernel.Expression> args = expr.arguments.positional; |
272 if (args.isEmpty) { | 294 if (args.isEmpty) { |
273 if (operatorName == 'unary-') { | 295 if (operatorName == 'unary-') { |
274 return AstTestFactory.prefixExpression(TokenType.MINUS, left); | 296 return AstTestFactory.prefixExpression(TokenType.MINUS, left); |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 for (var typeParameter in ctx.typeParameters) { | 869 for (var typeParameter in ctx.typeParameters) { |
848 if (typeParameter.name == name) { | 870 if (typeParameter.name == name) { |
849 return typeParameter; | 871 return typeParameter; |
850 } | 872 } |
851 } | 873 } |
852 } | 874 } |
853 } | 875 } |
854 throw new StateError('Not found $kernelTypeParameter in $context'); | 876 throw new StateError('Not found $kernelTypeParameter in $context'); |
855 } | 877 } |
856 } | 878 } |
OLD | NEW |