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

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

Issue 1936403002: Serialize / resynthesize 'isAsynchronous' and 'isGenerator' flags. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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
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 analyzer.test.src.summary.summary_common; 5 library analyzer.test.src.summary.summary_common;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/dart/scanner/reader.dart'; 10 import 'package:analyzer/src/dart/scanner/reader.dart';
(...skipping 3124 matching lines...) Expand 10 before | Expand all | Expand 10 after
3135 _assertUnlinkedConst(variable.constExpr, 3135 _assertUnlinkedConst(variable.constExpr,
3136 operators: [UnlinkedConstOperation.pushTrue]); 3136 operators: [UnlinkedConstOperation.pushTrue]);
3137 } 3137 }
3138 3138
3139 test_constructor() { 3139 test_constructor() {
3140 String text = 'class C { C(); }'; 3140 String text = 'class C { C(); }';
3141 UnlinkedExecutable executable = 3141 UnlinkedExecutable executable =
3142 findExecutable('', executables: serializeClassText(text).executables); 3142 findExecutable('', executables: serializeClassText(text).executables);
3143 expect(executable.kind, UnlinkedExecutableKind.constructor); 3143 expect(executable.kind, UnlinkedExecutableKind.constructor);
3144 expect(executable.returnType, isNull); 3144 expect(executable.returnType, isNull);
3145 expect(executable.isAsynchronous, isFalse);
3145 expect(executable.isExternal, isFalse); 3146 expect(executable.isExternal, isFalse);
3147 expect(executable.isGenerator, isFalse);
3146 expect(executable.nameOffset, text.indexOf('C();')); 3148 expect(executable.nameOffset, text.indexOf('C();'));
3147 expect(executable.periodOffset, 0); 3149 expect(executable.periodOffset, 0);
3148 expect(executable.nameEnd, 0); 3150 expect(executable.nameEnd, 0);
3149 expect(executable.isRedirectedConstructor, isFalse); 3151 expect(executable.isRedirectedConstructor, isFalse);
3150 expect(executable.redirectedConstructor, isNull); 3152 expect(executable.redirectedConstructor, isNull);
3151 expect(executable.redirectedConstructorName, isEmpty); 3153 expect(executable.redirectedConstructorName, isEmpty);
3152 expect(executable.visibleOffset, 0); 3154 expect(executable.visibleOffset, 0);
3153 expect(executable.visibleLength, 0); 3155 expect(executable.visibleLength, 0);
3154 } 3156 }
3155 3157
(...skipping 1575 matching lines...) Expand 10 before | Expand all | Expand 10 after
4731 UnlinkedExecutable executable = 4733 UnlinkedExecutable executable =
4732 serializeClassText('abstract class C { f() {} }').executables[0]; 4734 serializeClassText('abstract class C { f() {} }').executables[0];
4733 expect(executable.isAbstract, isFalse); 4735 expect(executable.isAbstract, isFalse);
4734 } 4736 }
4735 4737
4736 test_executable_function() { 4738 test_executable_function() {
4737 String text = ' f() {}'; 4739 String text = ' f() {}';
4738 UnlinkedExecutable executable = serializeExecutableText(text); 4740 UnlinkedExecutable executable = serializeExecutableText(text);
4739 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 4741 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
4740 expect(executable.returnType, isNull); 4742 expect(executable.returnType, isNull);
4743 expect(executable.isAsynchronous, isFalse);
4741 expect(executable.isExternal, isFalse); 4744 expect(executable.isExternal, isFalse);
4745 expect(executable.isGenerator, isFalse);
4742 expect(executable.nameOffset, text.indexOf('f')); 4746 expect(executable.nameOffset, text.indexOf('f'));
4743 expect(executable.visibleOffset, 0); 4747 expect(executable.visibleOffset, 0);
4744 expect(executable.visibleLength, 0); 4748 expect(executable.visibleLength, 0);
4745 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); 4749 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1));
4746 expect(unlinkedUnits[0].publicNamespace.names[0].kind, 4750 expect(unlinkedUnits[0].publicNamespace.names[0].kind,
4747 ReferenceKind.topLevelFunction); 4751 ReferenceKind.topLevelFunction);
4748 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f'); 4752 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f');
4749 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); 4753 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0);
4750 } 4754 }
4751 4755
4756 test_executable_function_async() {
4757 UnlinkedExecutable executable = serializeExecutableText(r'''
4758 import 'dart:async';
4759 Future f() async {}
4760 ''');
4761 expect(executable.isAsynchronous, isTrue);
4762 expect(executable.isGenerator, isFalse);
4763 }
4764
4765 test_executable_function_asyncStar() {
4766 UnlinkedExecutable executable = serializeExecutableText(r'''
4767 import 'dart:async';
4768 Stream f() async* {}
4769 ''');
4770 expect(executable.isAsynchronous, isTrue);
4771 expect(executable.isGenerator, isTrue);
4772 }
4773
4752 test_executable_function_explicit_return() { 4774 test_executable_function_explicit_return() {
4753 UnlinkedExecutable executable = 4775 UnlinkedExecutable executable =
4754 serializeExecutableText('dynamic f() => null;'); 4776 serializeExecutableText('dynamic f() => null;');
4755 checkDynamicTypeRef(executable.returnType); 4777 checkDynamicTypeRef(executable.returnType);
4756 } 4778 }
4757 4779
4758 test_executable_function_external() { 4780 test_executable_function_external() {
4759 UnlinkedExecutable executable = serializeExecutableText('external f();'); 4781 UnlinkedExecutable executable = serializeExecutableText('external f();');
4760 expect(executable.isExternal, isTrue); 4782 expect(executable.isExternal, isTrue);
4761 } 4783 }
4762 4784
4763 test_executable_function_private() { 4785 test_executable_function_private() {
4764 serializeExecutableText('_f() {}', executableName: '_f'); 4786 serializeExecutableText('_f() {}', executableName: '_f');
4765 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 4787 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
4766 } 4788 }
4767 4789
4768 test_executable_getter() { 4790 test_executable_getter() {
4769 String text = 'int get f => 1;'; 4791 String text = 'int get f => 1;';
4770 UnlinkedExecutable executable = serializeExecutableText(text); 4792 UnlinkedExecutable executable = serializeExecutableText(text);
4771 expect(executable.kind, UnlinkedExecutableKind.getter); 4793 expect(executable.kind, UnlinkedExecutableKind.getter);
4772 expect(executable.returnType, isNotNull); 4794 expect(executable.returnType, isNotNull);
4795 expect(executable.isAsynchronous, isFalse);
4773 expect(executable.isExternal, isFalse); 4796 expect(executable.isExternal, isFalse);
4797 expect(executable.isGenerator, isFalse);
4774 expect(executable.nameOffset, text.indexOf('f')); 4798 expect(executable.nameOffset, text.indexOf('f'));
4775 expect(findVariable('f'), isNull); 4799 expect(findVariable('f'), isNull);
4776 expect(findExecutable('f='), isNull); 4800 expect(findExecutable('f='), isNull);
4777 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); 4801 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1));
4778 expect(unlinkedUnits[0].publicNamespace.names[0].kind, 4802 expect(unlinkedUnits[0].publicNamespace.names[0].kind,
4779 ReferenceKind.topLevelPropertyAccessor); 4803 ReferenceKind.topLevelPropertyAccessor);
4780 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f'); 4804 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f');
4781 } 4805 }
4782 4806
4783 test_executable_getter_external() { 4807 test_executable_getter_external() {
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
5196 _assertVariableVisible(code, v, '{ // 1', '} // 2'); 5220 _assertVariableVisible(code, v, '{ // 1', '} // 2');
5197 checkTypeRef(v.type, 'dart:core', 'dart:core', 'int'); 5221 checkTypeRef(v.type, 'dart:core', 'dart:core', 'int');
5198 } 5222 }
5199 } 5223 }
5200 5224
5201 test_executable_member_function() { 5225 test_executable_member_function() {
5202 UnlinkedExecutable executable = findExecutable('f', 5226 UnlinkedExecutable executable = findExecutable('f',
5203 executables: serializeClassText('class C { f() {} }').executables); 5227 executables: serializeClassText('class C { f() {} }').executables);
5204 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 5228 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
5205 expect(executable.returnType, isNull); 5229 expect(executable.returnType, isNull);
5230 expect(executable.isAsynchronous, isFalse);
5206 expect(executable.isExternal, isFalse); 5231 expect(executable.isExternal, isFalse);
5232 expect(executable.isGenerator, isFalse);
5207 expect(executable.visibleOffset, 0); 5233 expect(executable.visibleOffset, 0);
5208 expect(executable.visibleLength, 0); 5234 expect(executable.visibleLength, 0);
5209 _assertCodeRange(executable.codeRange, 10, 6); 5235 _assertCodeRange(executable.codeRange, 10, 6);
5210 } 5236 }
5211 5237
5238 test_executable_member_function_async() {
5239 UnlinkedExecutable executable =
5240 findExecutable('f', executables: serializeClassText(r'''
5241 import 'dart:async';
5242 class C {
5243 Future f() async {}
5244 }
5245 ''').executables);
5246 expect(executable.isAsynchronous, isTrue);
5247 expect(executable.isGenerator, isFalse);
5248 }
5249
5250 test_executable_member_function_asyncStar() {
5251 UnlinkedExecutable executable =
5252 findExecutable('f', executables: serializeClassText(r'''
5253 import 'dart:async';
5254 class C {
5255 Stream f() async* {}
5256 }
5257 ''').executables);
5258 expect(executable.isAsynchronous, isTrue);
5259 expect(executable.isGenerator, isTrue);
5260 }
5261
5212 test_executable_member_function_explicit_return() { 5262 test_executable_member_function_explicit_return() {
5213 UnlinkedExecutable executable = findExecutable('f', 5263 UnlinkedExecutable executable = findExecutable('f',
5214 executables: 5264 executables:
5215 serializeClassText('class C { dynamic f() => null; }').executables); 5265 serializeClassText('class C { dynamic f() => null; }').executables);
5216 expect(executable.returnType, isNotNull); 5266 expect(executable.returnType, isNotNull);
5217 } 5267 }
5218 5268
5219 test_executable_member_function_external() { 5269 test_executable_member_function_external() {
5220 UnlinkedExecutable executable = findExecutable('f', 5270 UnlinkedExecutable executable = findExecutable('f',
5221 executables: 5271 executables:
5222 serializeClassText('class C { external f(); }').executables); 5272 serializeClassText('class C { external f(); }').executables);
5223 expect(executable.isExternal, isTrue); 5273 expect(executable.isExternal, isTrue);
5224 } 5274 }
5225 5275
5226 test_executable_member_getter() { 5276 test_executable_member_getter() {
5227 UnlinkedClass cls = serializeClassText('class C { int get f => 1; }'); 5277 UnlinkedClass cls = serializeClassText('class C { int get f => 1; }');
5228 UnlinkedExecutable executable = 5278 UnlinkedExecutable executable =
5229 findExecutable('f', executables: cls.executables, failIfAbsent: true); 5279 findExecutable('f', executables: cls.executables, failIfAbsent: true);
5230 expect(executable.kind, UnlinkedExecutableKind.getter); 5280 expect(executable.kind, UnlinkedExecutableKind.getter);
5231 expect(executable.returnType, isNotNull); 5281 expect(executable.returnType, isNotNull);
5282 expect(executable.isAsynchronous, isFalse);
5232 expect(executable.isExternal, isFalse); 5283 expect(executable.isExternal, isFalse);
5284 expect(executable.isGenerator, isFalse);
5233 _assertCodeRange(executable.codeRange, 10, 15); 5285 _assertCodeRange(executable.codeRange, 10, 15);
5234 expect(findVariable('f', variables: cls.fields), isNull); 5286 expect(findVariable('f', variables: cls.fields), isNull);
5235 expect(findExecutable('f=', executables: cls.executables), isNull); 5287 expect(findExecutable('f=', executables: cls.executables), isNull);
5236 } 5288 }
5237 5289
5238 test_executable_member_getter_external() { 5290 test_executable_member_getter_external() {
5239 UnlinkedClass cls = serializeClassText('class C { external int get f; }'); 5291 UnlinkedClass cls = serializeClassText('class C { external int get f; }');
5240 UnlinkedExecutable executable = 5292 UnlinkedExecutable executable =
5241 findExecutable('f', executables: cls.executables, failIfAbsent: true); 5293 findExecutable('f', executables: cls.executables, failIfAbsent: true);
5242 expect(executable.isExternal, isTrue); 5294 expect(executable.isExternal, isTrue);
5243 } 5295 }
5244 5296
5245 test_executable_member_setter() { 5297 test_executable_member_setter() {
5246 UnlinkedClass cls = serializeClassText('class C { void set f(value) {} }'); 5298 UnlinkedClass cls = serializeClassText('class C { void set f(value) {} }');
5247 UnlinkedExecutable executable = 5299 UnlinkedExecutable executable =
5248 findExecutable('f=', executables: cls.executables, failIfAbsent: true); 5300 findExecutable('f=', executables: cls.executables, failIfAbsent: true);
5249 expect(executable.kind, UnlinkedExecutableKind.setter); 5301 expect(executable.kind, UnlinkedExecutableKind.setter);
5250 expect(executable.returnType, isNotNull); 5302 expect(executable.returnType, isNotNull);
5303 expect(executable.isAsynchronous, isFalse);
5251 expect(executable.isExternal, isFalse); 5304 expect(executable.isExternal, isFalse);
5305 expect(executable.isGenerator, isFalse);
5252 _assertCodeRange(executable.codeRange, 10, 20); 5306 _assertCodeRange(executable.codeRange, 10, 20);
5253 expect(findVariable('f', variables: cls.fields), isNull); 5307 expect(findVariable('f', variables: cls.fields), isNull);
5254 expect(findExecutable('f', executables: cls.executables), isNull); 5308 expect(findExecutable('f', executables: cls.executables), isNull);
5255 } 5309 }
5256 5310
5257 test_executable_member_setter_external() { 5311 test_executable_member_setter_external() {
5258 UnlinkedClass cls = 5312 UnlinkedClass cls =
5259 serializeClassText('class C { external void set f(value); }'); 5313 serializeClassText('class C { external void set f(value); }');
5260 UnlinkedExecutable executable = 5314 UnlinkedExecutable executable =
5261 findExecutable('f=', executables: cls.executables, failIfAbsent: true); 5315 findExecutable('f=', executables: cls.executables, failIfAbsent: true);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
5295 } 5349 }
5296 5350
5297 test_executable_operator() { 5351 test_executable_operator() {
5298 UnlinkedExecutable executable = 5352 UnlinkedExecutable executable =
5299 serializeClassText('class C { C operator+(C c) => null; }').executables[ 5353 serializeClassText('class C { C operator+(C c) => null; }').executables[
5300 0]; 5354 0];
5301 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 5355 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
5302 expect(executable.name, '+'); 5356 expect(executable.name, '+');
5303 expect(executable.returnType, isNotNull); 5357 expect(executable.returnType, isNotNull);
5304 expect(executable.isAbstract, false); 5358 expect(executable.isAbstract, false);
5359 expect(executable.isAsynchronous, isFalse);
5305 expect(executable.isConst, false); 5360 expect(executable.isConst, false);
5306 expect(executable.isFactory, false); 5361 expect(executable.isFactory, false);
5362 expect(executable.isGenerator, isFalse);
5307 expect(executable.isStatic, false); 5363 expect(executable.isStatic, false);
5308 expect(executable.parameters, hasLength(1)); 5364 expect(executable.parameters, hasLength(1));
5309 checkTypeRef(executable.returnType, null, null, 'C'); 5365 checkTypeRef(executable.returnType, null, null, 'C');
5310 expect(executable.typeParameters, isEmpty); 5366 expect(executable.typeParameters, isEmpty);
5311 expect(executable.isExternal, false); 5367 expect(executable.isExternal, false);
5312 } 5368 }
5313 5369
5314 test_executable_operator_abstract() { 5370 test_executable_operator_abstract() {
5315 UnlinkedExecutable executable = 5371 UnlinkedExecutable executable =
5316 serializeClassText('class C { C operator+(C c); }', allowErrors: true) 5372 serializeClassText('class C { C operator+(C c); }', allowErrors: true)
5317 .executables[0]; 5373 .executables[0];
5318 expect(executable.isAbstract, true); 5374 expect(executable.isAbstract, true);
5375 expect(executable.isAsynchronous, isFalse);
5319 expect(executable.isExternal, false); 5376 expect(executable.isExternal, false);
5377 expect(executable.isGenerator, isFalse);
5320 } 5378 }
5321 5379
5322 test_executable_operator_equal() { 5380 test_executable_operator_equal() {
5323 UnlinkedExecutable executable = serializeClassText( 5381 UnlinkedExecutable executable = serializeClassText(
5324 'class C { bool operator==(Object other) => false; }') 5382 'class C { bool operator==(Object other) => false; }')
5325 .executables[0]; 5383 .executables[0];
5326 expect(executable.name, '=='); 5384 expect(executable.name, '==');
5327 } 5385 }
5328 5386
5329 test_executable_operator_external() { 5387 test_executable_operator_external() {
5330 UnlinkedExecutable executable = 5388 UnlinkedExecutable executable =
5331 serializeClassText('class C { external C operator+(C c); }') 5389 serializeClassText('class C { external C operator+(C c); }')
5332 .executables[0]; 5390 .executables[0];
5333 expect(executable.isAbstract, false); 5391 expect(executable.isAbstract, false);
5392 expect(executable.isAsynchronous, isFalse);
5334 expect(executable.isExternal, true); 5393 expect(executable.isExternal, true);
5394 expect(executable.isGenerator, isFalse);
5335 } 5395 }
5336 5396
5337 test_executable_operator_greater_equal() { 5397 test_executable_operator_greater_equal() {
5338 UnlinkedExecutable executable = 5398 UnlinkedExecutable executable =
5339 serializeClassText('class C { bool operator>=(C other) => false; }') 5399 serializeClassText('class C { bool operator>=(C other) => false; }')
5340 .executables[0]; 5400 .executables[0];
5341 expect(executable.name, '>='); 5401 expect(executable.name, '>=');
5342 } 5402 }
5343 5403
5344 test_executable_operator_index() { 5404 test_executable_operator_index() {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
5575 UnlinkedExecutable executable = serializeExecutableText('void f() {}'); 5635 UnlinkedExecutable executable = serializeExecutableText('void f() {}');
5576 checkVoidTypeRef(executable.returnType); 5636 checkVoidTypeRef(executable.returnType);
5577 } 5637 }
5578 5638
5579 test_executable_setter() { 5639 test_executable_setter() {
5580 String text = 'void set f(value) {}'; 5640 String text = 'void set f(value) {}';
5581 UnlinkedExecutable executable = 5641 UnlinkedExecutable executable =
5582 serializeExecutableText(text, executableName: 'f='); 5642 serializeExecutableText(text, executableName: 'f=');
5583 expect(executable.kind, UnlinkedExecutableKind.setter); 5643 expect(executable.kind, UnlinkedExecutableKind.setter);
5584 expect(executable.returnType, isNotNull); 5644 expect(executable.returnType, isNotNull);
5645 expect(executable.isAsynchronous, isFalse);
5585 expect(executable.isExternal, isFalse); 5646 expect(executable.isExternal, isFalse);
5647 expect(executable.isGenerator, isFalse);
5586 expect(executable.nameOffset, text.indexOf('f')); 5648 expect(executable.nameOffset, text.indexOf('f'));
5587 expect(findVariable('f'), isNull); 5649 expect(findVariable('f'), isNull);
5588 expect(findExecutable('f'), isNull); 5650 expect(findExecutable('f'), isNull);
5589 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); 5651 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1));
5590 expect(unlinkedUnits[0].publicNamespace.names[0].kind, 5652 expect(unlinkedUnits[0].publicNamespace.names[0].kind,
5591 ReferenceKind.topLevelPropertyAccessor); 5653 ReferenceKind.topLevelPropertyAccessor);
5592 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f='); 5654 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f=');
5593 } 5655 }
5594 5656
5595 test_executable_setter_external() { 5657 test_executable_setter_external() {
(...skipping 3945 matching lines...) Expand 10 before | Expand all | Expand 10 after
9541 class _PrefixExpectation { 9603 class _PrefixExpectation {
9542 final ReferenceKind kind; 9604 final ReferenceKind kind;
9543 final String name; 9605 final String name;
9544 final String absoluteUri; 9606 final String absoluteUri;
9545 final String relativeUri; 9607 final String relativeUri;
9546 final int numTypeParameters; 9608 final int numTypeParameters;
9547 9609
9548 _PrefixExpectation(this.kind, this.name, 9610 _PrefixExpectation(this.kind, this.name,
9549 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); 9611 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0});
9550 } 9612 }
OLDNEW
« pkg/analyzer/lib/src/summary/idl.dart ('K') | « pkg/analyzer/test/src/summary/resynthesize_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698