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

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 2156873002: Invalidate resolution if a unit instantiate a class with the unnamed constructor change. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 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.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 2766 matching lines...) Expand 10 before | Expand all | Expand 10 after
2777 bar() {} 2777 bar() {}
2778 } 2778 }
2779 '''); 2779 ''');
2780 _assertValidForChangedLibrary(a); 2780 _assertValidForChangedLibrary(a);
2781 _assertInvalid(a, LIBRARY_ERRORS_READY); 2781 _assertInvalid(a, LIBRARY_ERRORS_READY);
2782 _assertValidForDependentLibrary(b); 2782 _assertValidForDependentLibrary(b);
2783 _assertValidAllLibraryUnitResults(b); 2783 _assertValidAllLibraryUnitResults(b);
2784 _assertValid(b, LIBRARY_ERRORS_READY); 2784 _assertValid(b, LIBRARY_ERRORS_READY);
2785 } 2785 }
2786 2786
2787 void test_class_constructor_named_changeName() {
2788 // Update a.dart: change A.named() to A.named2().
2789 // b.dart is invalid, because it references A.named().
2790 _verifyTwoLibrariesInvalidatesResolution(
2791 r'''
2792 class A {
2793 A.named();
2794 }
2795 ''',
2796 r'''
2797 class A {
2798 A.named2();
2799 }
2800 ''',
2801 r'''
2802 import 'a.dart';
2803 main() {
2804 new A.named();
2805 }
2806 ''');
2807 }
2808
2809 void test_class_constructor_named_parameters_add() {
2810 // Update a.dart: add a new parameter to A.named().
2811 // b.dart is invalid, because it references A.named().
2812 _verifyTwoLibrariesInvalidatesResolution(
2813 r'''
2814 class A {
2815 A.named();
2816 }
2817 ''',
2818 r'''
2819 class A {
2820 A.named(int p);
2821 }
2822 ''',
2823 r'''
2824 import 'a.dart';
2825 main() {
2826 new A.named();
2827 }
2828 ''');
2829 }
2830
2831 void test_class_constructor_named_parameters_remove() {
2832 // Update a.dart: remove a new parameter of A.named().
2833 // b.dart is invalid, because it references A.named().
2834 _verifyTwoLibrariesInvalidatesResolution(
2835 r'''
2836 class A {
2837 A.named(int p);
2838 }
2839 ''',
2840 r'''
2841 class A {
2842 A.named();
2843 }
2844 ''',
2845 r'''
2846 import 'a.dart';
2847 main() {
2848 new A.named();
2849 }
2850 ''');
2851 }
2852
2853 void test_class_constructor_named_remove_notUsed() {
2854 // Update a.dart: remove A.foo().
2855 // b.dart is valid, because it does not reference A.foo().
2856 _verifyTwoLibrariesAllValid(
2857 r'''
2858 class A {
2859 A.foo();
2860 A.bar();
2861 }
2862 ''',
2863 r'''
2864 class A {
2865 A.bar();
2866 }
2867 ''',
2868 r'''
2869 import 'a.dart';
2870 main() {
2871 new A.bar();
2872 }
2873 ''');
2874 }
2875
2876 void test_class_constructor_named_remove_used() {
2877 // Update a.dart: remove A.named().
2878 // b.dart is invalid, because it references A.named().
2879 _verifyTwoLibrariesInvalidatesResolution(
2880 r'''
2881 class A {
2882 A.named();
2883 }
2884 ''',
2885 r'''
2886 class A {
2887 }
2888 ''',
2889 r'''
2890 import 'a.dart';
2891 main() {
2892 new A.named();
2893 }
2894 ''');
2895 }
2896
2897 void test_class_constructor_unnamed_parameters_remove() {
2898 // Update a.dart: change A().
2899 // b.dart is invalid, because it references A().
2900 _verifyTwoLibrariesInvalidatesResolution(
2901 r'''
2902 class A {
2903 A(int a, int b);
2904 }
2905 ''',
2906 r'''
2907 class A {
2908 A(int a);
2909 }
2910 ''',
2911 r'''
2912 import 'a.dart';
2913 main() {
2914 new A(1, 2);
2915 }
2916 ''');
2917 }
2918
2919 void test_class_constructor_unnamed_remove_notUsed() {
2920 // Update a.dart: remove A().
2921 // b.dart is invalid, because it instantiates A.
2922 _verifyTwoLibrariesInvalidatesResolution(
2923 r'''
2924 class A {
2925 A();
2926 A.named();
2927 }
2928 ''',
2929 r'''
2930 class A {
2931 A.named();
2932 }
2933 ''',
2934 r'''
2935 import 'a.dart';
2936 main() {
2937 new A.named();
2938 }
2939 ''');
2940 }
2941
2942 void test_class_constructor_unnamed_remove_used() {
2943 // Update a.dart: remove A.named().
2944 // b.dart is invalid, because it references A.named().
2945 _verifyTwoLibrariesInvalidatesResolution(
2946 r'''
2947 class A {
2948 A();
2949 }
2950 ''',
2951 r'''
2952 class A {
2953 }
2954 ''',
2955 r'''
2956 import 'a.dart';
2957 main() {
2958 new A();
2959 }
2960 ''');
2961 }
2962
2787 void test_class_method_change_notUsed() { 2963 void test_class_method_change_notUsed() {
2788 Source a = addSource( 2964 Source a = addSource(
2789 '/a.dart', 2965 '/a.dart',
2790 r''' 2966 r'''
2791 class A { 2967 class A {
2792 foo() {} 2968 foo() {}
2793 bar() {} 2969 bar() {}
2794 } 2970 }
2795 '''); 2971 ''');
2796 Source b = addSource( 2972 Source b = addSource(
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
3866 } 4042 }
3867 } 4043 }
3868 4044
3869 void _performPendingAnalysisTasks([int maxTasks = 512]) { 4045 void _performPendingAnalysisTasks([int maxTasks = 512]) {
3870 for (int i = 0; context.performAnalysisTask().hasMoreWork; i++) { 4046 for (int i = 0; context.performAnalysisTask().hasMoreWork; i++) {
3871 if (i > maxTasks) { 4047 if (i > maxTasks) {
3872 fail('Analysis did not terminate.'); 4048 fail('Analysis did not terminate.');
3873 } 4049 }
3874 } 4050 }
3875 } 4051 }
4052
4053 void _verifyTwoLibrariesAllValid(
4054 String firstCodeA, String secondCodeA, String codeB) {
4055 Source a = addSource('/a.dart', firstCodeA);
4056 Source b = addSource('/b.dart', codeB);
4057 _performPendingAnalysisTasks();
4058 context.setContents(a, secondCodeA);
4059 _assertValidForChangedLibrary(a);
4060 _assertInvalid(a, LIBRARY_ERRORS_READY);
4061 _assertValidForDependentLibrary(b);
4062 _assertValidAllResolution(b);
4063 _assertValidAllErrors(b);
4064 }
4065
4066 void _verifyTwoLibrariesInvalidatesResolution(
4067 String firstCodeA, String secondCodeA, String codeB) {
4068 Source a = addSource('/a.dart', firstCodeA);
4069 Source b = addSource('/b.dart', codeB);
4070 _performPendingAnalysisTasks();
4071 context.setContents(a, secondCodeA);
4072 _assertValidForChangedLibrary(a);
4073 _assertInvalid(a, LIBRARY_ERRORS_READY);
4074 _assertValidForDependentLibrary(b);
4075 _assertInvalid(b, LIBRARY_ERRORS_READY);
4076 _assertInvalidUnits(b, RESOLVED_UNIT4);
4077 }
3876 } 4078 }
3877 4079
3878 class _AnalysisContextImplTest_Source_exists_true extends TestSource { 4080 class _AnalysisContextImplTest_Source_exists_true extends TestSource {
3879 @override 4081 @override
3880 bool exists() => true; 4082 bool exists() => true;
3881 } 4083 }
3882 4084
3883 class _AnalysisContextImplTest_Source_getModificationStamp_fromSource 4085 class _AnalysisContextImplTest_Source_getModificationStamp_fromSource
3884 extends TestSource { 4086 extends TestSource {
3885 int stamp; 4087 int stamp;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
3975 * Initialize the visitor. 4177 * Initialize the visitor.
3976 */ 4178 */
3977 _ElementGatherer(); 4179 _ElementGatherer();
3978 4180
3979 @override 4181 @override
3980 void visitElement(Element element) { 4182 void visitElement(Element element) {
3981 elements[element] = element; 4183 elements[element] = element;
3982 super.visitElement(element); 4184 super.visitElement(element);
3983 } 4185 }
3984 } 4186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698