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

Side by Side Diff: pkg/analyzer/test/generated/incremental_resolver_test.dart

Issue 1581293002: Issue 25064. Incrementally resolve comments only if both are documentation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.generated.incremental_resolver_test; 5 library analyzer.test.generated.incremental_resolver_test;
6 6
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/src/context/cache.dart'; 8 import 'package:analyzer/src/context/cache.dart';
9 import 'package:analyzer/src/dart/element/element.dart'; 9 import 'package:analyzer/src/dart/element/element.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
11 import 'package:analyzer/src/generated/engine.dart'; 11 import 'package:analyzer/src/generated/engine.dart';
12 import 'package:analyzer/src/generated/error.dart'; 12 import 'package:analyzer/src/generated/error.dart';
13 import 'package:analyzer/src/generated/incremental_logger.dart' as log; 13 import 'package:analyzer/src/generated/incremental_logger.dart' as lg;
14 import 'package:analyzer/src/generated/incremental_resolution_validator.dart'; 14 import 'package:analyzer/src/generated/incremental_resolution_validator.dart';
15 import 'package:analyzer/src/generated/incremental_resolver.dart'; 15 import 'package:analyzer/src/generated/incremental_resolver.dart';
16 import 'package:analyzer/src/generated/java_engine.dart'; 16 import 'package:analyzer/src/generated/java_engine.dart';
17 import 'package:analyzer/src/generated/parser.dart'; 17 import 'package:analyzer/src/generated/parser.dart';
18 import 'package:analyzer/src/generated/resolver.dart'; 18 import 'package:analyzer/src/generated/resolver.dart';
19 import 'package:analyzer/src/generated/scanner.dart'; 19 import 'package:analyzer/src/generated/scanner.dart';
20 import 'package:analyzer/src/generated/source_io.dart'; 20 import 'package:analyzer/src/generated/source_io.dart';
21 import 'package:analyzer/src/generated/testing/ast_factory.dart'; 21 import 'package:analyzer/src/generated/testing/ast_factory.dart';
22 import 'package:analyzer/src/generated/testing/element_factory.dart'; 22 import 'package:analyzer/src/generated/testing/element_factory.dart';
23 import 'package:analyzer/src/task/dart.dart'; 23 import 'package:analyzer/src/task/dart.dart';
(...skipping 3061 matching lines...) Expand 10 before | Expand all | Expand 10 after
3085 } 3085 }
3086 3086
3087 @override 3087 @override
3088 void resetWithOptions(AnalysisOptions options) { 3088 void resetWithOptions(AnalysisOptions options) {
3089 AnalysisContextFactory.contextWithCoreAndOptions(options); 3089 AnalysisContextFactory.contextWithCoreAndOptions(options);
3090 } 3090 }
3091 3091
3092 void setUp() { 3092 void setUp() {
3093 super.setUp(); 3093 super.setUp();
3094 test_resolveApiChanges = true; 3094 test_resolveApiChanges = true;
3095 log.logger = log.NULL_LOGGER; 3095 lg.logger = lg.NULL_LOGGER;
3096 } 3096 }
3097 3097
3098 void test_classMemberAccessor_body() { 3098 void test_classMemberAccessor_body() {
3099 _resolveUnit(r''' 3099 _resolveUnit(r'''
3100 class A { 3100 class A {
3101 int get test { 3101 int get test {
3102 return 1 + 2; 3102 return 1 + 2;
3103 } 3103 }
3104 }'''); 3104 }''');
3105 _resolve(_editString('+', '*'), _isFunctionBody); 3105 _resolve(_editString('+', '*'), _isFunctionBody);
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
3516 } 3516 }
3517 } 3517 }
3518 } 3518 }
3519 3519
3520 /** 3520 /**
3521 * The test for [poorMansIncrementalResolution] function and its integration 3521 * The test for [poorMansIncrementalResolution] function and its integration
3522 * into [AnalysisContext]. 3522 * into [AnalysisContext].
3523 */ 3523 */
3524 @reflectiveTest 3524 @reflectiveTest
3525 class PoorMansIncrementalResolutionTest extends ResolverTestCase { 3525 class PoorMansIncrementalResolutionTest extends ResolverTestCase {
3526 final _TestLogger logger = new _TestLogger();
3527
3526 Source source; 3528 Source source;
3527 String code; 3529 String code;
3528 LibraryElement oldLibrary; 3530 LibraryElement oldLibrary;
3529 CompilationUnit oldUnit; 3531 CompilationUnit oldUnit;
3530 CompilationUnitElement oldUnitElement; 3532 CompilationUnitElement oldUnitElement;
3531 3533
3532 void fail_updateErrors_removeExisting_duplicateMethodDeclaration() { 3534 void fail_updateErrors_removeExisting_duplicateMethodDeclaration() {
3533 // TODO(scheglov) We fail to remove the second "foo" declaration. 3535 // TODO(scheglov) We fail to remove the second "foo" declaration.
3534 // So, we still have the same duplicate declaration problem. 3536 // So, we still have the same duplicate declaration problem.
3535 _resolveUnit(r''' 3537 _resolveUnit(r'''
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
3879 print(0); 3881 print(0);
3880 } 3882 }
3881 '''); 3883 ''');
3882 _updateAndValidate(r''' 3884 _updateAndValidate(r'''
3883 main() { 3885 main() {
3884 print(0); 3886 print(0);
3885 } 3887 }
3886 '''); 3888 ''');
3887 } 3889 }
3888 3890
3891 void test_endOfLineComment_toDartDoc() {
3892 _resolveUnit(r'''
3893 class A {
3894 // text
3895 main() {
3896 print(42);
3897 }
3898 }''');
3899 _updateAndValidate(
3900 r'''
3901 class A {
3902 /// text
3903 main() {
3904 print(42);
3905 }
3906 }''',
3907 expectedSuccess: false);
3908 }
3909
3889 void test_false_constConstructor_initializer() { 3910 void test_false_constConstructor_initializer() {
3890 _resolveUnit(r''' 3911 _resolveUnit(r'''
3891 class C { 3912 class C {
3892 final int x; 3913 final int x;
3893 const C(this.x); 3914 const C(this.x);
3894 const C.foo() : x = 0; 3915 const C.foo() : x = 0;
3895 } 3916 }
3896 main() { 3917 main() {
3897 const {const C(0): 0, const C.foo(): 1}; 3918 const {const C(0): 0, const C.foo(): 1};
3898 } 3919 }
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
4690 } 4711 }
4691 4712
4692 /** 4713 /**
4693 * Reset the analysis context to have the 'incremental' option set to the 4714 * Reset the analysis context to have the 'incremental' option set to the
4694 * given value. 4715 * given value.
4695 */ 4716 */
4696 void _resetWithIncremental(bool enable) { 4717 void _resetWithIncremental(bool enable) {
4697 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); 4718 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
4698 analysisOptions.incremental = enable; 4719 analysisOptions.incremental = enable;
4699 analysisOptions.incrementalApi = enable; 4720 analysisOptions.incrementalApi = enable;
4700 // log.logger = log.PRINT_LOGGER; 4721 lg.logger = logger;
4701 log.logger = log.NULL_LOGGER;
4702 analysisContext2.analysisOptions = analysisOptions; 4722 analysisContext2.analysisOptions = analysisOptions;
4703 } 4723 }
4704 4724
4705 void _resolveUnit(String code) { 4725 void _resolveUnit(String code) {
4706 this.code = code; 4726 this.code = code;
4707 source = addSource(code); 4727 source = addSource(code);
4708 oldLibrary = resolve2(source); 4728 oldLibrary = resolve2(source);
4709 oldUnit = resolveCompilationUnit(source, oldLibrary); 4729 oldUnit = resolveCompilationUnit(source, oldLibrary);
4710 oldUnitElement = oldUnit.element; 4730 oldUnitElement = oldUnit.element;
4711 } 4731 }
(...skipping 11 matching lines...) Expand all
4723 bool runTasksBeforeIncremental: true}) { 4743 bool runTasksBeforeIncremental: true}) {
4724 // Run any pending tasks tasks. 4744 // Run any pending tasks tasks.
4725 if (runTasksBeforeIncremental) { 4745 if (runTasksBeforeIncremental) {
4726 _runTasks(); 4746 _runTasks();
4727 } 4747 }
4728 // Update the source - currently this may cause incremental resolution. 4748 // Update the source - currently this may cause incremental resolution.
4729 // Then request the updated resolved unit. 4749 // Then request the updated resolved unit.
4730 _resetWithIncremental(true); 4750 _resetWithIncremental(true);
4731 analysisContext2.setContents(source, newCode); 4751 analysisContext2.setContents(source, newCode);
4732 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary); 4752 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary);
4753 expect(logger.hasError, isFalse);
4733 List<AnalysisError> newErrors = analysisContext.computeErrors(source); 4754 List<AnalysisError> newErrors = analysisContext.computeErrors(source);
4734 LineInfo newLineInfo = analysisContext.getLineInfo(source); 4755 LineInfo newLineInfo = analysisContext.getLineInfo(source);
4735 // check for expected failure 4756 // check for expected failure
4736 if (!expectedSuccess) { 4757 if (!expectedSuccess) {
4737 expect(newUnit.element, isNot(same(oldUnitElement))); 4758 expect(newUnit.element, isNot(same(oldUnitElement)));
4738 return; 4759 return;
4739 } 4760 }
4740 // The existing CompilationUnit[Element] should be updated. 4761 // The existing CompilationUnit[Element] should be updated.
4741 expect(newUnit, same(oldUnit)); 4762 expect(newUnit, same(oldUnit));
4742 expect(newUnit.element, same(oldUnitElement)); 4763 expect(newUnit.element, same(oldUnitElement));
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
5015 return ResolutionContextBuilder.contextFor(node, listener).scope; 5036 return ResolutionContextBuilder.contextFor(node, listener).scope;
5016 } 5037 }
5017 } 5038 }
5018 5039
5019 class _Edit { 5040 class _Edit {
5020 final int offset; 5041 final int offset;
5021 final int length; 5042 final int length;
5022 final String replacement; 5043 final String replacement;
5023 _Edit(this.offset, this.length, this.replacement); 5044 _Edit(this.offset, this.length, this.replacement);
5024 } 5045 }
5046
5047 class _TestLogger implements lg.Logger {
5048 bool hasError = false;
5049
5050 @override
5051 void enter(String name) {}
5052
5053 @override
5054 void exit() {}
5055
5056 @override
5057 void log(Object obj) {}
5058
5059 @override
5060 void logException(Object exception, Object stackTrace) {
5061 hasError = true;
5062 }
5063
5064 @override
5065 lg.LoggingTimer startTimer() {
5066 return new lg.LoggingTimer(this);
5067 }
5068 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698