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

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

Issue 1842433002: When summarize AST, include local variables in loops and try-catch. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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/test/generated/all_the_rest_test.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 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 4341 matching lines...) Expand 10 before | Expand all | Expand 10 after
4352 expect(aaa.isOnSwitchStatement, isFalse); 4352 expect(aaa.isOnSwitchStatement, isFalse);
4353 } 4353 }
4354 { 4354 {
4355 UnlinkedLabel bbb = labels.singleWhere((l) => l.name == 'bbb'); 4355 UnlinkedLabel bbb = labels.singleWhere((l) => l.name == 'bbb');
4356 expect(bbb, isNotNull); 4356 expect(bbb, isNotNull);
4357 expect(bbb.isOnSwitchMember, isFalse); 4357 expect(bbb.isOnSwitchMember, isFalse);
4358 expect(bbb.isOnSwitchStatement, isFalse); 4358 expect(bbb.isOnSwitchStatement, isFalse);
4359 } 4359 }
4360 } 4360 }
4361 4361
4362 test_executable_localVariables_catch() {
4363 String code = r'''
4364 f() { // 1
4365 try {
4366 throw 42;
4367 } on int catch (e, st) { // 2
4368 print(e);
4369 print(st);
4370 } // 3
4371 } // 4
4372 ''';
4373 UnlinkedExecutable executable = serializeExecutableText(code);
4374 List<UnlinkedVariable> variables = executable.localVariables;
4375 expect(variables, hasLength(2));
4376 {
4377 UnlinkedVariable e = variables.singleWhere((v) => v.name == 'e');
4378 _assertVariableVisible(code, e, 'on int catch (', '} // 3');
4379 checkTypeRef(e.type, 'dart:core', 'dart:core', 'int');
4380 }
4381 {
4382 UnlinkedVariable st = variables.singleWhere((v) => v.name == 'st');
4383 _assertVariableVisible(code, st, 'on int catch (', '} // 3');
4384 }
4385 }
4386
4362 test_executable_localVariables_empty() { 4387 test_executable_localVariables_empty() {
4363 UnlinkedExecutable executable = serializeExecutableText(r''' 4388 UnlinkedExecutable executable = serializeExecutableText(r'''
4364 f() { 4389 f() {
4365 } 4390 }
4366 '''); 4391 ''');
4367 expect(executable.localVariables, isEmpty); 4392 expect(executable.localVariables, isEmpty);
4368 } 4393 }
4369 4394
4395 test_executable_localVariables_forEachLoop() {
4396 String code = r'''
4397 f() { // 1
4398 for (int i in <int>[]) { // 2
4399 print(i);
4400 } // 3
4401 } // 4
4402 ''';
4403 UnlinkedExecutable executable = serializeExecutableText(code);
4404 List<UnlinkedVariable> variables = executable.localVariables;
4405 expect(variables, hasLength(1));
4406 {
4407 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i');
4408 _assertVariableVisible(code, i, 'for', '} // 3');
4409 checkTypeRef(i.type, 'dart:core', 'dart:core', 'int');
4410 }
4411 }
4412
4413 test_executable_localVariables_forLoop() {
4414 String code = r'''
4415 f() { // 1
4416 for (int i = 0, j = 0; i < 10; i++, j++) { // 2
4417 print(i);
4418 } // 3
4419 } // 4
4420 ''';
4421 UnlinkedExecutable executable = serializeExecutableText(code);
4422 List<UnlinkedVariable> variables = executable.localVariables;
4423 expect(variables, hasLength(2));
4424 {
4425 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i');
4426 _assertVariableVisible(code, i, 'for', '} // 3');
4427 checkTypeRef(i.type, 'dart:core', 'dart:core', 'int');
4428 }
4429 {
4430 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'j');
4431 _assertVariableVisible(code, i, 'for', '} // 3');
4432 checkTypeRef(i.type, 'dart:core', 'dart:core', 'int');
4433 }
4434 }
4435
4370 test_executable_localVariables_inConstructor() { 4436 test_executable_localVariables_inConstructor() {
4371 String code = r''' 4437 String code = r'''
4372 class C { 4438 class C {
4373 C() { // 1 4439 C() { // 1
4374 int v; 4440 int v;
4375 } // 2 4441 } // 2
4376 } 4442 }
4377 '''; 4443 ''';
4378 UnlinkedExecutable executable = 4444 UnlinkedExecutable executable =
4379 findExecutable('', executables: serializeClassText(code).executables); 4445 findExecutable('', executables: serializeClassText(code).executables);
(...skipping 3268 matching lines...) Expand 10 before | Expand all | Expand 10 after
7648 class _PrefixExpectation { 7714 class _PrefixExpectation {
7649 final ReferenceKind kind; 7715 final ReferenceKind kind;
7650 final String name; 7716 final String name;
7651 final String absoluteUri; 7717 final String absoluteUri;
7652 final String relativeUri; 7718 final String relativeUri;
7653 final int numTypeParameters; 7719 final int numTypeParameters;
7654 7720
7655 _PrefixExpectation(this.kind, this.name, 7721 _PrefixExpectation(this.kind, this.name,
7656 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); 7722 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0});
7657 } 7723 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/all_the_rest_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698