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

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1718013002: In summaries, don't drop unsafe prefixes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 test.src.serialization.elements_test; 5 library test.src.serialization.elements_test;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/dart/element/type.dart'; 11 import 'package:analyzer/dart/element/type.dart';
12 import 'package:analyzer/src/dart/ast/ast.dart'; 12 import 'package:analyzer/src/dart/ast/ast.dart';
13 import 'package:analyzer/src/dart/element/element.dart'; 13 import 'package:analyzer/src/dart/element/element.dart';
14 import 'package:analyzer/src/dart/element/member.dart'; 14 import 'package:analyzer/src/dart/element/member.dart';
15 import 'package:analyzer/src/dart/element/type.dart'; 15 import 'package:analyzer/src/dart/element/type.dart';
16 import 'package:analyzer/src/generated/constant.dart' show DartObject; 16 import 'package:analyzer/src/generated/constant.dart' show DartObject;
17 import 'package:analyzer/src/generated/element_handle.dart'; 17 import 'package:analyzer/src/generated/element_handle.dart';
18 import 'package:analyzer/src/generated/engine.dart'; 18 import 'package:analyzer/src/generated/engine.dart';
19 import 'package:analyzer/src/generated/resolver.dart' 19 import 'package:analyzer/src/generated/resolver.dart'
20 show Namespace, TypeProvider; 20 show Namespace, TypeProvider;
21 import 'package:analyzer/src/generated/source.dart'; 21 import 'package:analyzer/src/generated/source.dart';
22 import 'package:analyzer/src/generated/testing/ast_factory.dart';
22 import 'package:analyzer/src/summary/idl.dart'; 23 import 'package:analyzer/src/summary/idl.dart';
23 import 'package:analyzer/src/summary/resynthesize.dart'; 24 import 'package:analyzer/src/summary/resynthesize.dart';
24 import 'package:analyzer/src/summary/summarize_elements.dart'; 25 import 'package:analyzer/src/summary/summarize_elements.dart';
25 import 'package:unittest/unittest.dart'; 26 import 'package:unittest/unittest.dart';
26 27
27 import '../../generated/resolver_test.dart'; 28 import '../../generated/resolver_test.dart';
28 import '../../reflective_tests.dart'; 29 import '../../reflective_tests.dart';
29 import 'summary_common.dart' show canonicalize; 30 import 'summary_common.dart' show canonicalize;
30 31
31 main() { 32 main() {
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // ConstantAstCloner does not copy static types, and constant values 342 // ConstantAstCloner does not copy static types, and constant values
342 // computer does not use static types. So, we don't set them during 343 // computer does not use static types. So, we don't set them during
343 // resynthesis and should not check them here. 344 // resynthesis and should not check them here.
344 if (o is ParenthesizedExpression) { 345 if (o is ParenthesizedExpression) {
345 // We don't resynthesize parenthesis, so just ignore it. 346 // We don't resynthesize parenthesis, so just ignore it.
346 compareConstAsts(r, o.expression, desc); 347 compareConstAsts(r, o.expression, desc);
347 } else if (o is SimpleIdentifier && r is SimpleIdentifier) { 348 } else if (o is SimpleIdentifier && r is SimpleIdentifier) {
348 expect(r.name, o.name, reason: desc); 349 expect(r.name, o.name, reason: desc);
349 compareElements(r.staticElement, o.staticElement, desc); 350 compareElements(r.staticElement, o.staticElement, desc);
350 } else if (o is PrefixedIdentifier && r is SimpleIdentifier) { 351 } else if (o is PrefixedIdentifier && r is SimpleIdentifier) {
351 // We often don't resynthesize prefixed identifiers. 352 // We don't resynthesize prefixed identifiers when the prefix refers to
352 // We use simple identifiers with correct elements. 353 // a PrefixElement or a ClassElement. We use simple identifiers with
353 compareConstAsts(r, o.identifier, desc); 354 // correct elements.
355 if (o.prefix.staticElement is PrefixElement ||
356 o.prefix.staticElement is ClassElement) {
357 compareConstAsts(r, o.identifier, desc);
358 } else {
359 fail('Prefix of type ${o.prefix.staticElement.runtimeType} should not'
360 ' have been elided');
361 }
362 } else if (o is PropertyAccess &&
363 o.target is PrefixedIdentifier &&
364 r is PrefixedIdentifier) {
365 // We don't resynthesize prefixed identifiers when the prefix refers to
366 // a PrefixElement or a ClassElement. Which means that if the original
367 // expression was e.g. `prefix.topLevelVariableName.length`, it will get
368 // resynthesized as `topLevelVariableName.length`
369 PrefixedIdentifier oTarget = o.target;
370 if (oTarget.prefix.staticElement is PrefixElement ||
371 oTarget.prefix.staticElement is ClassElement) {
372 compareConstAsts(r,
373 AstFactory.identifier(oTarget.identifier, o.propertyName), desc);
374 } else {
375 fail('Prefix of type ${oTarget.prefix.staticElement.runtimeType}'
376 ' should not have been elided');
377 }
354 } else if (o is PrefixedIdentifier && r is PrefixedIdentifier) { 378 } else if (o is PrefixedIdentifier && r is PrefixedIdentifier) {
355 compareConstAsts(r.prefix, o.prefix, desc); 379 compareConstAsts(r.prefix, o.prefix, desc);
356 compareConstAsts(r.identifier, o.identifier, desc); 380 compareConstAsts(r.identifier, o.identifier, desc);
357 } else if (o is PropertyAccess && r is PropertyAccess) { 381 } else if (o is PropertyAccess && r is PropertyAccess) {
358 compareConstAsts(r.target, o.target, desc); 382 compareConstAsts(r.target, o.target, desc);
359 expect(r.propertyName.name, o.propertyName.name, reason: desc); 383 expect(r.propertyName.name, o.propertyName.name, reason: desc);
360 compareElements( 384 compareElements(
361 r.propertyName.staticElement, o.propertyName.staticElement, desc); 385 r.propertyName.staticElement, o.propertyName.staticElement, desc);
362 } else if (o is PropertyAccess && r is SimpleIdentifier) { 386 } else if (o is PropertyAccess && r is SimpleIdentifier) {
363 // We don't resynthesize property access. 387 // We don't resynthesize property access.
(...skipping 3591 matching lines...) Expand 10 before | Expand all | Expand 10 after
3955 fail('Unexpectedly tried to get unlinked summary for $uri'); 3979 fail('Unexpectedly tried to get unlinked summary for $uri');
3956 } 3980 }
3957 return serializedUnit; 3981 return serializedUnit;
3958 } 3982 }
3959 3983
3960 @override 3984 @override
3961 bool hasLibrarySummary(String uri) { 3985 bool hasLibrarySummary(String uri) {
3962 return true; 3986 return true;
3963 } 3987 }
3964 } 3988 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698