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

Side by Side Diff: pkg/analyzer/lib/src/kernel/resynthesize.dart

Issue 3002633002: Resynthesize assert constructor initializers and parameter references. (Closed)
Patch Set: Created 3 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 return _buildIdentifier(expr.targetReference, isGet: true); 222 return _buildIdentifier(expr.targetReference, isGet: true);
223 } 223 }
224 224
225 if (expr is kernel.PropertyGet) { 225 if (expr is kernel.PropertyGet) {
226 Expression target = build(expr.receiver); 226 Expression target = build(expr.receiver);
227 kernel.Reference reference = expr.interfaceTargetReference; 227 kernel.Reference reference = expr.interfaceTargetReference;
228 SimpleIdentifier identifier = _buildSimpleIdentifier(reference); 228 SimpleIdentifier identifier = _buildSimpleIdentifier(reference);
229 return AstTestFactory.propertyAccess(target, identifier); 229 return AstTestFactory.propertyAccess(target, identifier);
230 } 230 }
231 231
232 if (expr is kernel.VariableGet) {
233 String name = expr.variable.name;
234 Element contextConstructor = _contextElement;
235 if (contextConstructor is ConstructorElement) {
236 SimpleIdentifier identifier = AstTestFactory.identifier3(name);
237 ParameterElement parameter = contextConstructor.parameters.firstWhere(
238 (parameter) => parameter.name == name,
239 orElse: () => null);
240 identifier.staticElement = parameter;
241 return identifier;
242 }
243 }
244
232 if (expr is kernel.ConditionalExpression) { 245 if (expr is kernel.ConditionalExpression) {
233 var condition = build(expr.condition); 246 var condition = build(expr.condition);
234 var then = build(expr.then); 247 var then = build(expr.then);
235 var otherwise = build(expr.otherwise); 248 var otherwise = build(expr.otherwise);
236 return AstTestFactory.conditionalExpression(condition, then, otherwise); 249 return AstTestFactory.conditionalExpression(condition, then, otherwise);
237 } 250 }
238 251
239 if (expr is kernel.Not) { 252 if (expr is kernel.Not) {
240 kernel.Expression kernelOperand = expr.operand; 253 kernel.Expression kernelOperand = expr.operand;
241 var operand = build(kernelOperand); 254 var operand = build(kernelOperand);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 327
315 ConstructorInitializer buildInitializer(kernel.Initializer k) { 328 ConstructorInitializer buildInitializer(kernel.Initializer k) {
316 if (k is kernel.FieldInitializer) { 329 if (k is kernel.FieldInitializer) {
317 Expression value = build(k.value); 330 Expression value = build(k.value);
318 ConstructorFieldInitializer initializer = AstTestFactory 331 ConstructorFieldInitializer initializer = AstTestFactory
319 .constructorFieldInitializer(false, k.field.name.name, value); 332 .constructorFieldInitializer(false, k.field.name.name, value);
320 initializer.fieldName.staticElement = _getElement(k.fieldReference); 333 initializer.fieldName.staticElement = _getElement(k.fieldReference);
321 return initializer; 334 return initializer;
322 } 335 }
323 336
337 if (k is kernel.LocalInitializer) {
338 var invocation = k.variable.initializer;
339 if (invocation is kernel.MethodInvocation) {
340 var receiver = invocation.receiver;
341 if (receiver is kernel.FunctionExpression &&
342 invocation.name.name == 'call') {
343 var body = receiver.function.body;
344 if (body is kernel.AssertStatement) {
345 var condition = build(body.condition);
346 var message = body.message != null ? build(body.message) : null;
347 return AstTestFactory.assertInitializer(condition, message);
348 }
349 }
350 }
351 return null;
Paul Berry 2017/08/15 16:54:39 Do we ever expect to reach this? Does the caller
scheglov 2017/08/23 17:06:27 Done.
352 }
353
324 if (k is kernel.RedirectingInitializer) { 354 if (k is kernel.RedirectingInitializer) {
325 ConstructorElementImpl redirect = _getElement(k.targetReference); 355 ConstructorElementImpl redirect = _getElement(k.targetReference);
326 var arguments = _toArguments(k.arguments); 356 var arguments = _toArguments(k.arguments);
327 357
328 RedirectingConstructorInvocation invocation = 358 RedirectingConstructorInvocation invocation =
329 AstTestFactory.redirectingConstructorInvocation(arguments); 359 AstTestFactory.redirectingConstructorInvocation(arguments);
330 invocation.staticElement = redirect; 360 invocation.staticElement = redirect;
331 361
332 String name = k.target.name.name; 362 String name = k.target.name.name;
333 if (name.isNotEmpty) { 363 if (name.isNotEmpty) {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 variablesData.implicitAccessors 677 variablesData.implicitAccessors
648 .add(new PropertyAccessorElementImpl_ImplicitSetter(variable)); 678 .add(new PropertyAccessorElementImpl_ImplicitSetter(variable));
649 } 679 }
650 } 680 }
651 return variablesData; 681 return variablesData;
652 } 682 }
653 683
654 @override 684 @override
655 ConstructorInitializer getConstructorInitializer( 685 ConstructorInitializer getConstructorInitializer(
656 ConstructorElementImpl constructor, kernel.Initializer k) { 686 ConstructorElementImpl constructor, kernel.Initializer k) {
657 if (k is kernel.LocalInitializer || 687 if (k is kernel.FieldInitializer && k.isSynthetic ||
658 k is kernel.FieldInitializer && k.isSynthetic ||
659 k is kernel.SuperInitializer && k.isSynthetic) { 688 k is kernel.SuperInitializer && k.isSynthetic) {
660 return null; 689 return null;
661 } 690 }
662 return new _ExprBuilder(this, constructor).buildInitializer(k); 691 return new _ExprBuilder(this, constructor).buildInitializer(k);
663 } 692 }
664 693
665 @override 694 @override
666 Expression getExpression(ElementImpl context, kernel.Expression expression) { 695 Expression getExpression(ElementImpl context, kernel.Expression expression) {
667 return new _ExprBuilder(this, context).build(expression); 696 return new _ExprBuilder(this, context).build(expression);
668 } 697 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 for (var typeParameter in ctx.typeParameters) { 844 for (var typeParameter in ctx.typeParameters) {
816 if (typeParameter.name == name) { 845 if (typeParameter.name == name) {
817 return typeParameter; 846 return typeParameter;
818 } 847 }
819 } 848 }
820 } 849 }
821 } 850 }
822 throw new StateError('Not found $kernelTypeParameter in $context'); 851 throw new StateError('Not found $kernelTypeParameter in $context');
823 } 852 }
824 } 853 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698