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

Unified Diff: pkg/analyzer/test/generated/incremental_resolver_test.dart

Issue 753803002: Use a poor man's incremental parser to perform incremental resolution. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/generated/incremental_resolver_test.dart
diff --git a/pkg/analyzer/test/generated/incremental_resolver_test.dart b/pkg/analyzer/test/generated/incremental_resolver_test.dart
index 27f5e67452668e97a4a5a19fd4c2a8311026f1ad..3d13061992e13cc9b7deff8608445378d4b7ead2 100644
--- a/pkg/analyzer/test/generated/incremental_resolver_test.dart
+++ b/pkg/analyzer/test/generated/incremental_resolver_test.dart
@@ -28,6 +28,7 @@ main() {
groupSep = ' | ';
runReflectiveTests(DeclarationMatcherTest);
runReflectiveTests(IncrementalResolverTest);
+ runReflectiveTests(PoorMansIncrementalResolutionTest);
runReflectiveTests(ScopeBuilderTest);
}
@@ -1362,6 +1363,175 @@ class B {
}
+/**
+ * The test for [poorMansIncrementalResolution] function and its integration
+ * into [AnalysisContext].
+ */
+class PoorMansIncrementalResolutionTest extends ResolverTestCase {
Brian Wilkerson 2014/11/24 15:09:14 It would be good to test some cases where incremen
scheglov 2014/11/24 18:59:06 Agree, but not in this CL.
+ Source source;
+ String code;
+ LibraryElement oldLibrary;
+ CompilationUnit oldUnit;
+ CompilationUnitElement oldUnitElement;
+
+ void setUp() {
+ super.setUp();
+ _resetWithIncremental(true);
+ }
+
+ void test_inBody_expression() {
+ _resolveUnit(r'''
+class A {
+ m() {
+ print(1);
+ }
+}
+''');
+ _updateAndValidate(r'''
+class A {
+ m() {
+ print(2 + 3);
+ }
+}
+''');
+ }
+
+ void test_inBody_insertStatement() {
+ _resolveUnit(r'''
+main() {
+ print(1);
+}
+''');
+ _updateAndValidate(r'''
+main() {
+ print(0);
+ print(1);
+}
+''');
+ }
+
+ void test_inBody_tokenToNode() {
+ _resolveUnit(r'''
+main() {
+ var v = 42;
+}
+''');
+ _updateAndValidate(r'''
+main() {
+ int v = 42;
+}
+''');
+ }
+
+ void test_twice() {
+ _resolveUnit(r'''
+main() {
+ print(1);
+}''');
+ _updateAndValidate(r'''
+main() {
+ print(12);
+}''', false);
+ _updateAndValidate(r'''
+main() {
+ print(1);
+}''', false);
+ }
+
+ void test_twice2() {
+ _resolveUnit(r'''
+class A {
+ m() {
+ int vvvvvvvv = 42;
+ print(vvvvvvvv);
+ }
+}''');
+ _updateAndValidate(r'''
+class A {
+ m() {
+ int vvvvvvvv2 = 42;
+ print(vvvvvvvv2);
+ }
+}''', false);
+ _updateAndValidate(r'''
+class A {
+ m() {
+ int vvvvvvvv = 42;
+ print(vvvvvvvv);
+ }
+}''', false);
+ }
+
+ void test_withImport() {
+ _resolveUnit(r'''
+import 'dart:async';
+import 'dart:io';
+main() {
+ print(1);
+}
+''');
+ _updateAndValidate(r'''
+import 'dart:async';
+import 'dart:io';
+main() {
+ print(2 + 3);
+}
+''');
+ }
+
+ /**
+ * Reset the analysis context to have the 'incremental' option set to the
+ * given value.
+ */
+ void _resetWithIncremental(bool enable) {
+ AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
+ analysisOptions.incremental = enable;
+ analysisContext2.analysisOptions = analysisOptions;
+ }
+
+ void _resolveUnit(String code) {
+ this.code = code;
+ source = addSource(code);
+ oldLibrary = resolve(source);
+ oldUnit = resolveCompilationUnit(source, oldLibrary);
+ oldUnitElement = oldUnit.element;
+ }
+
+ void _runTasks() {
+ AnalysisResult result = analysisContext.performAnalysisTask();
+ while (result.changeNotices != null) {
+ result = analysisContext.performAnalysisTask();
+ }
+ }
+
+ void _updateAndValidate(String newCode, [bool compareWithFull = true]) {
+ // Run any pending tasks tasks.
+ _runTasks();
+ // Update the source - currently this may cause incremental resolution.
+ // Then request the updated resolved unit.
+ _resetWithIncremental(true);
+ analysisContext2.setContents(source, newCode);
+ CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary);
+ // The existing CompilationUnitElement should be updated.
+ expect(newUnit.element, same(oldUnitElement));
+ // The only expected pending task should return the same resolved
+ // "newUnit", so all clients will get it using the usual way.
+ AnalysisResult analysisResult = analysisContext.performAnalysisTask();
+ ChangeNotice notice = analysisResult.changeNotices[0];
+ expect(notice.compilationUnit, same(newUnit));
+ // Resolve "newCode" from scratch.
+ if (compareWithFull) {
+ _resetWithIncremental(false);
+ source = addSource(newCode);
+ LibraryElement library = resolve(source);
+ CompilationUnit fullNewUnit = resolveCompilationUnit(source, library);
+ // Validate that "incremental" and "full" units have the same resolution.
+ _SameResolutionValidator.assertSameResolution(newUnit, fullNewUnit);
+ }
+ }
+}
+
+
class ScopeBuilderTest extends EngineTestCase {
void test_scopeFor_ClassDeclaration() {
GatheringErrorListener listener = new GatheringErrorListener();

Powered by Google App Engine
This is Rietveld 408576698