OLD | NEW |
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.src.context.context_test; | 5 library analyzer.test.src.context.context_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 1806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1817 _analyzeAll_assertFinished(); | 1817 _analyzeAll_assertFinished(); |
1818 expect(context.getResolvedCompilationUnit2(source, source), isNotNull); | 1818 expect(context.getResolvedCompilationUnit2(source, source), isNotNull); |
1819 // new contents | 1819 // new contents |
1820 contentCache.setContents(source, newContents); | 1820 contentCache.setContents(source, newContents); |
1821 context.handleContentsChanged(source, oldContents, newContents, true); | 1821 context.handleContentsChanged(source, oldContents, newContents, true); |
1822 // there is some work to do | 1822 // there is some work to do |
1823 AnalysisResult analysisResult = context.performAnalysisTask(); | 1823 AnalysisResult analysisResult = context.performAnalysisTask(); |
1824 expect(analysisResult.changeNotices, isNotNull); | 1824 expect(analysisResult.changeNotices, isNotNull); |
1825 } | 1825 } |
1826 | 1826 |
1827 void test_handleContentsChanged_incremental_newContentsNull() { | |
1828 context.analysisOptions = new AnalysisOptionsImpl()..incremental = true; | |
1829 ContentCache contentCache = new ContentCache(); | |
1830 context.contentCache = contentCache; | |
1831 // old contents | |
1832 String oldContents = 'foo() {}'; | |
1833 Source source = resourceProvider.getFile('/test.dart').createSource(); | |
1834 contentCache.setContents(source, oldContents); | |
1835 expect(context.computeLibraryElement(source), isNotNull); | |
1836 // new contents | |
1837 String newContents = null; | |
1838 contentCache.setContents(source, newContents); | |
1839 context.handleContentsChanged(source, oldContents, newContents, true); | |
1840 expect(context.getLibraryElement(source), isNull); | |
1841 } | |
1842 | |
1843 void test_handleContentsChanged_noOriginal_sameAsFile() { | 1827 void test_handleContentsChanged_noOriginal_sameAsFile() { |
1844 ContentCache contentCache = new ContentCache(); | 1828 ContentCache contentCache = new ContentCache(); |
1845 context.contentCache = contentCache; | 1829 context.contentCache = contentCache; |
1846 // Add the source. | 1830 // Add the source. |
1847 String code = 'foo() {}'; | 1831 String code = 'foo() {}'; |
1848 Source source = addSource("/test.dart", code); | 1832 Source source = addSource("/test.dart", code); |
1849 _analyzeAll_assertFinished(); | 1833 _analyzeAll_assertFinished(); |
1850 expect(context.getResolvedCompilationUnit2(source, source), isNotNull); | 1834 expect(context.getResolvedCompilationUnit2(source, source), isNotNull); |
1851 // Update the content cache, and notify that we updated the source. | 1835 // Update the content cache, and notify that we updated the source. |
1852 // We pass "null" as "originalContents" because the was no one. | 1836 // We pass "null" as "originalContents" because the was no one. |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2691 // set priority sources, AnalysisDriver is reset | 2675 // set priority sources, AnalysisDriver is reset |
2692 context.analysisPriorityOrder = <Source>[source]; | 2676 context.analysisPriorityOrder = <Source>[source]; |
2693 expect(context.driver.currentWorkOrder, isNull); | 2677 expect(context.driver.currentWorkOrder, isNull); |
2694 // analysis continues | 2678 // analysis continues |
2695 context.performAnalysisTask(); | 2679 context.performAnalysisTask(); |
2696 expect(context.driver.currentWorkOrder, isNotNull); | 2680 expect(context.driver.currentWorkOrder, isNotNull); |
2697 } | 2681 } |
2698 | 2682 |
2699 Future test_setChangedContents_libraryWithPart() { | 2683 Future test_setChangedContents_libraryWithPart() { |
2700 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 2684 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
2701 options.incremental = true; | |
2702 context.analysisOptions = options; | 2685 context.analysisOptions = options; |
2703 SourcesChangedListener listener = new SourcesChangedListener(); | 2686 SourcesChangedListener listener = new SourcesChangedListener(); |
2704 context.onSourcesChanged.listen(listener.onData); | 2687 context.onSourcesChanged.listen(listener.onData); |
2705 String oldCode = r''' | 2688 String oldCode = r''' |
2706 library lib; | 2689 library lib; |
2707 part 'part.dart'; | 2690 part 'part.dart'; |
2708 int a = 0;'''; | 2691 int a = 0;'''; |
2709 Source librarySource = addSource("/lib.dart", oldCode); | 2692 Source librarySource = addSource("/lib.dart", oldCode); |
2710 String partContents = r''' | 2693 String partContents = r''' |
2711 part of lib; | 2694 part of lib; |
(...skipping 16 matching lines...) Expand all Loading... |
2728 listener.assertEvent(wereSourcesAdded: true); | 2711 listener.assertEvent(wereSourcesAdded: true); |
2729 listener.assertEvent(wereSourcesAdded: true); | 2712 listener.assertEvent(wereSourcesAdded: true); |
2730 listener.assertEvent(changedSources: [librarySource]); | 2713 listener.assertEvent(changedSources: [librarySource]); |
2731 listener.assertNoMoreEvents(); | 2714 listener.assertNoMoreEvents(); |
2732 }); | 2715 }); |
2733 } | 2716 } |
2734 | 2717 |
2735 void test_setChangedContents_notResolved() { | 2718 void test_setChangedContents_notResolved() { |
2736 AnalysisOptionsImpl options = | 2719 AnalysisOptionsImpl options = |
2737 new AnalysisOptionsImpl.from(context.analysisOptions); | 2720 new AnalysisOptionsImpl.from(context.analysisOptions); |
2738 options.incremental = true; | |
2739 context.analysisOptions = options; | 2721 context.analysisOptions = options; |
2740 String oldCode = r''' | 2722 String oldCode = r''' |
2741 library lib; | 2723 library lib; |
2742 int a = 0;'''; | 2724 int a = 0;'''; |
2743 Source librarySource = addSource("/lib.dart", oldCode); | 2725 Source librarySource = addSource("/lib.dart", oldCode); |
2744 int offset = oldCode.indexOf("int a") + 4; | 2726 int offset = oldCode.indexOf("int a") + 4; |
2745 String newCode = r''' | 2727 String newCode = r''' |
2746 library lib; | 2728 library lib; |
2747 int ya = 0;'''; | 2729 int ya = 0;'''; |
2748 context.setChangedContents(librarySource, newCode, offset, 0, 1); | 2730 context.setChangedContents(librarySource, newCode, offset, 0, 1); |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3126 * Initialize the visitor. | 3108 * Initialize the visitor. |
3127 */ | 3109 */ |
3128 _ElementGatherer(); | 3110 _ElementGatherer(); |
3129 | 3111 |
3130 @override | 3112 @override |
3131 void visitElement(Element element) { | 3113 void visitElement(Element element) { |
3132 elements[element] = element; | 3114 elements[element] = element; |
3133 super.visitElement(element); | 3115 super.visitElement(element); |
3134 } | 3116 } |
3135 } | 3117 } |
OLD | NEW |