| 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 2691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2702 // This makes B changed. | 2702 // This makes B changed. |
| 2703 // b.dart is invalid, because it references B. | 2703 // b.dart is invalid, because it references B. |
| 2704 context.setContents( | 2704 context.setContents( |
| 2705 a, | 2705 a, |
| 2706 r''' | 2706 r''' |
| 2707 class A { | 2707 class A { |
| 2708 m2() {} | 2708 m2() {} |
| 2709 } | 2709 } |
| 2710 class B extends A {} | 2710 class B extends A {} |
| 2711 '''); | 2711 '''); |
| 2712 _assertValidForChangedLibrary(a); |
| 2713 _assertValidForDependentLibrary(b); |
| 2712 _assertInvalid(a, LIBRARY_ERRORS_READY); | 2714 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 2713 _assertInvalid(b, LIBRARY_ERRORS_READY); | 2715 _assertInvalid(b, LIBRARY_ERRORS_READY); |
| 2714 } | 2716 } |
| 2715 | 2717 |
| 2716 void test_class_private_member() { | 2718 void test_class_private_member() { |
| 2717 Source a = addSource( | 2719 Source a = addSource( |
| 2718 '/a.dart', | 2720 '/a.dart', |
| 2719 r''' | 2721 r''' |
| 2720 class A { | 2722 class A { |
| 2721 A(); | 2723 A(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2748 A._privateConstructor2(); | 2750 A._privateConstructor2(); |
| 2749 | 2751 |
| 2750 foo() {} | 2752 foo() {} |
| 2751 | 2753 |
| 2752 int _privateField2; | 2754 int _privateField2; |
| 2753 _privateMethod2() {} | 2755 _privateMethod2() {} |
| 2754 int get _privateGetter2 => null; | 2756 int get _privateGetter2 => null; |
| 2755 void set _privateSetter2(_) {} | 2757 void set _privateSetter2(_) {} |
| 2756 } | 2758 } |
| 2757 '''); | 2759 '''); |
| 2760 _assertValidForChangedLibrary(a); |
| 2758 _assertInvalid(a, LIBRARY_ERRORS_READY); | 2761 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 2762 _assertValidForDependentLibrary(b); |
| 2763 _assertValidAllLibraryUnitResults(b); |
| 2759 _assertValid(b, LIBRARY_ERRORS_READY); | 2764 _assertValid(b, LIBRARY_ERRORS_READY); |
| 2760 } | 2765 } |
| 2761 | 2766 |
| 2762 void test_private_class() { | 2767 void test_private_class() { |
| 2763 Source a = addSource( | 2768 Source a = addSource( |
| 2764 '/a.dart', | 2769 '/a.dart', |
| 2765 r''' | 2770 r''' |
| 2766 class _A {} | 2771 class _A {} |
| 2767 class _B2 {} | 2772 class _B2 {} |
| 2768 '''); | 2773 '''); |
| 2769 Source b = addSource( | 2774 Source b = addSource( |
| 2770 '/b.dart', | 2775 '/b.dart', |
| 2771 r''' | 2776 r''' |
| 2772 import 'a.dart'; | 2777 import 'a.dart'; |
| 2773 main() { | 2778 main() { |
| 2774 new _A(); | 2779 new _A(); |
| 2775 new _B(); | 2780 new _B(); |
| 2776 } | 2781 } |
| 2777 '''); | 2782 '''); |
| 2778 _performPendingAnalysisTasks(); | 2783 _performPendingAnalysisTasks(); |
| 2779 // Update a.dart: change _A and _B2 | 2784 // Update a.dart: change _A and _B2 |
| 2780 // b.dart is valid, because _A, _B, _A2 and _B2 are all private, | 2785 // b.dart is valid, because _A, _B, _A2 and _B2 are all private, |
| 2781 // so b.dart cannot see them. | 2786 // so b.dart cannot see them. |
| 2782 context.setContents( | 2787 context.setContents( |
| 2783 a, | 2788 a, |
| 2784 r''' | 2789 r''' |
| 2785 class _A2 {} | 2790 class _A2 {} |
| 2786 class _B {} | 2791 class _B {} |
| 2787 '''); | 2792 '''); |
| 2793 _assertValidForChangedLibrary(a); |
| 2788 _assertInvalid(a, LIBRARY_ERRORS_READY); | 2794 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 2795 _assertValidForDependentLibrary(b); |
| 2796 _assertValidAllLibraryUnitResults(b); |
| 2789 _assertValid(b, LIBRARY_ERRORS_READY); | 2797 _assertValid(b, LIBRARY_ERRORS_READY); |
| 2790 } | 2798 } |
| 2791 | 2799 |
| 2792 void test_private_topLevelVariable() { | 2800 void test_private_topLevelVariable() { |
| 2793 Source a = addSource( | 2801 Source a = addSource( |
| 2794 '/a.dart', | 2802 '/a.dart', |
| 2795 r''' | 2803 r''' |
| 2796 int _V = 1; | 2804 int _V = 1; |
| 2797 '''); | 2805 '''); |
| 2798 Source b = addSource( | 2806 Source b = addSource( |
| 2799 '/b.dart', | 2807 '/b.dart', |
| 2800 r''' | 2808 r''' |
| 2801 import 'a.dart'; | 2809 import 'a.dart'; |
| 2802 main() { | 2810 main() { |
| 2803 print(_V); | 2811 print(_V); |
| 2804 } | 2812 } |
| 2805 '''); | 2813 '''); |
| 2806 _performPendingAnalysisTasks(); | 2814 _performPendingAnalysisTasks(); |
| 2807 // Update a.dart: change _V | 2815 // Update a.dart: change _V |
| 2808 // b.dart is valid, because _V is private and b.dart cannot see it. | 2816 // b.dart is valid, because _V is private and b.dart cannot see it. |
| 2809 context.setContents( | 2817 context.setContents( |
| 2810 a, | 2818 a, |
| 2811 r''' | 2819 r''' |
| 2812 int _V = 2; | 2820 int _V = 2; |
| 2813 '''); | 2821 '''); |
| 2822 _assertValidForChangedLibrary(a); |
| 2814 _assertInvalid(a, LIBRARY_ERRORS_READY); | 2823 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 2824 _assertValidForDependentLibrary(b); |
| 2825 _assertValidAllLibraryUnitResults(b); |
| 2815 _assertValid(b, LIBRARY_ERRORS_READY); | 2826 _assertValid(b, LIBRARY_ERRORS_READY); |
| 2816 } | 2827 } |
| 2817 | 2828 |
| 2818 void test_sequence_class_give_take() { | 2829 void test_sequence_class_give_take() { |
| 2819 Source a = addSource( | 2830 Source a = addSource( |
| 2820 '/a.dart', | 2831 '/a.dart', |
| 2821 r''' | 2832 r''' |
| 2822 class A {} | 2833 class A {} |
| 2823 class B {} | 2834 class B {} |
| 2824 class C {} | 2835 class C {} |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2836 expect(context.getErrors(b).errors, hasLength(1)); | 2847 expect(context.getErrors(b).errors, hasLength(1)); |
| 2837 // Update a.dart: remove C, add C2. | 2848 // Update a.dart: remove C, add C2. |
| 2838 // b.dart is invalid, because it references C2. | 2849 // b.dart is invalid, because it references C2. |
| 2839 context.setContents( | 2850 context.setContents( |
| 2840 a, | 2851 a, |
| 2841 r''' | 2852 r''' |
| 2842 class A {} | 2853 class A {} |
| 2843 class B {} | 2854 class B {} |
| 2844 class C2 {} | 2855 class C2 {} |
| 2845 '''); | 2856 '''); |
| 2857 _assertValidForChangedLibrary(a); |
| 2846 _assertInvalid(a, LIBRARY_ERRORS_READY); | 2858 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 2859 _assertValidForDependentLibrary(b); |
| 2847 _assertInvalid(b, LIBRARY_ERRORS_READY); | 2860 _assertInvalid(b, LIBRARY_ERRORS_READY); |
| 2848 _assertUnitInvalid(b, RESOLVED_UNIT); | 2861 _assertInvalidUnits(b, RESOLVED_UNIT4); |
| 2849 // Now b.dart is analyzed and the error is fixed. | 2862 // Now b.dart is analyzed and the error is fixed. |
| 2850 _performPendingAnalysisTasks(); | 2863 _performPendingAnalysisTasks(); |
| 2851 expect(context.getErrors(b).errors, hasLength(0)); | 2864 expect(context.getErrors(b).errors, hasLength(0)); |
| 2852 // Update a.dart: remove C2, add C. | 2865 // Update a.dart: remove C2, add C. |
| 2853 // b.dart is invalid, because it references C2. | 2866 // b.dart is invalid, because it references C2. |
| 2854 context.setContents( | 2867 context.setContents( |
| 2855 a, | 2868 a, |
| 2856 r''' | 2869 r''' |
| 2857 class A {} | 2870 class A {} |
| 2858 class B {} | 2871 class B {} |
| 2859 class C {} | 2872 class C {} |
| 2860 '''); | 2873 '''); |
| 2874 _assertValidForChangedLibrary(a); |
| 2861 _assertInvalid(a, LIBRARY_ERRORS_READY); | 2875 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 2876 _assertValidForDependentLibrary(b); |
| 2862 _assertInvalid(b, LIBRARY_ERRORS_READY); | 2877 _assertInvalid(b, LIBRARY_ERRORS_READY); |
| 2878 _assertInvalidUnits(b, RESOLVED_UNIT4); |
| 2863 // Now b.dart is analyzed and it again has the error. | 2879 // Now b.dart is analyzed and it again has the error. |
| 2864 _performPendingAnalysisTasks(); | 2880 _performPendingAnalysisTasks(); |
| 2865 expect(context.getErrors(b).errors, hasLength(1)); | 2881 expect(context.getErrors(b).errors, hasLength(1)); |
| 2866 } | 2882 } |
| 2867 | 2883 |
| 2868 void test_sequence_noChange_thenChange() { | 2884 void test_sequence_noChange_thenChange() { |
| 2869 Source a = addSource( | 2885 Source a = addSource( |
| 2870 '/a.dart', | 2886 '/a.dart', |
| 2871 r''' | 2887 r''' |
| 2872 class A { | 2888 class A { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2895 context.setContents( | 2911 context.setContents( |
| 2896 a, | 2912 a, |
| 2897 r''' | 2913 r''' |
| 2898 class A { | 2914 class A { |
| 2899 A(); | 2915 A(); |
| 2900 } | 2916 } |
| 2901 class B { | 2917 class B { |
| 2902 B(); | 2918 B(); |
| 2903 } | 2919 } |
| 2904 '''); | 2920 '''); |
| 2921 _assertValidForChangedLibrary(a); |
| 2905 _assertInvalid(a, LIBRARY_ERRORS_READY); | 2922 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 2906 _assertValid(b, LIBRARY_ELEMENT); | 2923 _assertValidForDependentLibrary(b); |
| 2924 _assertValidAllLibraryUnitResults(b); |
| 2925 _assertValid(b, LIBRARY_ERRORS_READY); |
| 2907 // The a.dart's unit and element are updated incrementally. | 2926 // The a.dart's unit and element are updated incrementally. |
| 2908 // They are the same instances as initially. | 2927 // They are the same instances as initially. |
| 2909 // So, all the references from other units are still valid. | 2928 // So, all the references from other units are still valid. |
| 2910 { | 2929 { |
| 2911 LibrarySpecificUnit target = new LibrarySpecificUnit(a, a); | 2930 LibrarySpecificUnit target = new LibrarySpecificUnit(a, a); |
| 2912 expect(analysisCache.getValue(target, RESOLVED_UNIT1), same(unitA)); | 2931 expect(analysisCache.getValue(target, RESOLVED_UNIT1), same(unitA)); |
| 2913 expect(unitA.element, same(unitElementA)); | 2932 expect(unitA.element, same(unitElementA)); |
| 2914 expect(unitElementA.library, same(libraryElementA)); | 2933 expect(unitElementA.library, same(libraryElementA)); |
| 2915 } | 2934 } |
| 2916 // Analyze. | 2935 // Analyze. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2930 a, | 2949 a, |
| 2931 r''' | 2950 r''' |
| 2932 class A { | 2951 class A { |
| 2933 A(); | 2952 A(); |
| 2934 m() {} | 2953 m() {} |
| 2935 } | 2954 } |
| 2936 class B { | 2955 class B { |
| 2937 B(); | 2956 B(); |
| 2938 } | 2957 } |
| 2939 '''); | 2958 '''); |
| 2959 _assertValidForChangedLibrary(a); |
| 2940 _assertInvalid(a, LIBRARY_ERRORS_READY); | 2960 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 2941 _assertInvalid(b, LIBRARY_ELEMENT); | 2961 _assertValidForDependentLibrary(b); |
| 2962 _assertInvalid(b, LIBRARY_ERRORS_READY); |
| 2963 _assertInvalidUnits(b, RESOLVED_UNIT4); |
| 2942 // The a.dart's unit and element are the same. | 2964 // The a.dart's unit and element are the same. |
| 2943 { | 2965 { |
| 2944 LibrarySpecificUnit target = new LibrarySpecificUnit(a, a); | 2966 LibrarySpecificUnit target = new LibrarySpecificUnit(a, a); |
| 2945 expect(analysisCache.getValue(target, RESOLVED_UNIT1), same(unitA)); | 2967 expect(analysisCache.getValue(target, RESOLVED_UNIT1), same(unitA)); |
| 2946 expect(unitA.element, same(unitElementA)); | 2968 expect(unitA.element, same(unitElementA)); |
| 2947 expect(unitElementA.library, same(libraryElementA)); | 2969 expect(unitElementA.library, same(libraryElementA)); |
| 2948 } | 2970 } |
| 2949 // Analyze. | 2971 // Analyze. |
| 2950 _performPendingAnalysisTasks(); | 2972 _performPendingAnalysisTasks(); |
| 2951 expect(context.getErrors(a).errors, hasLength(0)); | 2973 expect(context.getErrors(a).errors, hasLength(0)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2975 entryA.setState(RESOLVED_UNIT, CacheState.FLUSHED); | 2997 entryA.setState(RESOLVED_UNIT, CacheState.FLUSHED); |
| 2976 entryA.setState(RESOLVED_UNIT1, CacheState.FLUSHED); | 2998 entryA.setState(RESOLVED_UNIT1, CacheState.FLUSHED); |
| 2977 entryA.setState(RESOLVED_UNIT2, CacheState.FLUSHED); | 2999 entryA.setState(RESOLVED_UNIT2, CacheState.FLUSHED); |
| 2978 entryA.setState(RESOLVED_UNIT3, CacheState.FLUSHED); | 3000 entryA.setState(RESOLVED_UNIT3, CacheState.FLUSHED); |
| 2979 context.setContents( | 3001 context.setContents( |
| 2980 a, | 3002 a, |
| 2981 r''' | 3003 r''' |
| 2982 class A {} | 3004 class A {} |
| 2983 class B2 {} | 3005 class B2 {} |
| 2984 '''); | 3006 '''); |
| 3007 _assertValidAllLibraryUnitResults(b); |
| 2985 _assertValid(b, LIBRARY_ERRORS_READY); | 3008 _assertValid(b, LIBRARY_ERRORS_READY); |
| 2986 } | 3009 } |
| 2987 | 3010 |
| 2988 void test_unusedName_class_add() { | 3011 void test_unusedName_class_add() { |
| 2989 Source a = addSource( | 3012 Source a = addSource( |
| 2990 '/a.dart', | 3013 '/a.dart', |
| 2991 r''' | 3014 r''' |
| 2992 class A {} | 3015 class A {} |
| 2993 class B {} | 3016 class B {} |
| 2994 class C {} | 3017 class C {} |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3007 // The class B is not referenced. | 3030 // The class B is not referenced. |
| 3008 // a.dart is invalid. | 3031 // a.dart is invalid. |
| 3009 // b.dart is valid. | 3032 // b.dart is valid. |
| 3010 context.setContents( | 3033 context.setContents( |
| 3011 a, | 3034 a, |
| 3012 r''' | 3035 r''' |
| 3013 class A {} | 3036 class A {} |
| 3014 class B2 {} | 3037 class B2 {} |
| 3015 class C {} | 3038 class C {} |
| 3016 '''); | 3039 '''); |
| 3040 _assertValidForChangedLibrary(a); |
| 3017 _assertInvalid(a, LIBRARY_ERRORS_READY); | 3041 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 3018 _assertValid(a, LINE_INFO); | |
| 3019 _assertUnitValid(a, RESOLVED_UNIT1); | |
| 3020 _assertUnitInvalid(a, RESOLVED_UNIT); | 3042 _assertUnitInvalid(a, RESOLVED_UNIT); |
| 3043 _assertValidForDependentLibrary(b); |
| 3044 _assertValidAllLibraryUnitResults(b); |
| 3021 _assertValid(b, LIBRARY_ERRORS_READY); | 3045 _assertValid(b, LIBRARY_ERRORS_READY); |
| 3022 _assertUnitValid(b, RESOLVED_UNIT); | |
| 3023 } | 3046 } |
| 3024 | 3047 |
| 3025 void test_usedName_class_name_asHole_inBody() { | 3048 void test_usedName_class_name_asHole_inBody() { |
| 3026 Source a = addSource( | 3049 Source a = addSource( |
| 3027 '/a.dart', | 3050 '/a.dart', |
| 3028 r''' | 3051 r''' |
| 3029 class A {} | 3052 class A {} |
| 3030 class B {} | 3053 class B {} |
| 3031 class C {} | 3054 class C {} |
| 3032 '''); | 3055 '''); |
| 3033 Source b = addSource( | 3056 Source b = addSource( |
| 3034 '/b.dart', | 3057 '/b.dart', |
| 3035 r''' | 3058 r''' |
| 3036 import 'a.dart'; | 3059 import 'a.dart'; |
| 3037 main() { | 3060 main() { |
| 3038 new A(); | 3061 new A(); |
| 3039 new C2(); | 3062 new C2(); |
| 3040 } | 3063 } |
| 3041 '''); | 3064 '''); |
| 3042 _performPendingAnalysisTasks(); | 3065 _performPendingAnalysisTasks(); |
| 3043 // Update a.dart: remove C, add C2. | 3066 // Update a.dart: remove C, add C2. |
| 3044 // b.dart is invalid, because it references C2. | 3067 // b.dart is invalid, because it references C2. |
| 3045 context.setContents( | 3068 context.setContents( |
| 3046 a, | 3069 a, |
| 3047 r''' | 3070 r''' |
| 3048 class A {} | 3071 class A {} |
| 3049 class B {} | 3072 class B {} |
| 3050 class C2 {} | 3073 class C2 {} |
| 3051 '''); | 3074 '''); |
| 3075 _assertValidForChangedLibrary(a); |
| 3052 _assertInvalid(a, LIBRARY_ERRORS_READY); | 3076 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 3077 _assertValidForDependentLibrary(b); |
| 3053 _assertInvalid(b, LIBRARY_ERRORS_READY); | 3078 _assertInvalid(b, LIBRARY_ERRORS_READY); |
| 3054 _assertInvalidUnits(b, RESOLVED_UNIT2); | 3079 _assertInvalidUnits(b, RESOLVED_UNIT4); |
| 3055 _assertInvalidLibraryElements(b, LIBRARY_ELEMENT2); | |
| 3056 } | 3080 } |
| 3057 | 3081 |
| 3058 void test_usedName_class_name_asSuper() { | 3082 void test_usedName_class_name_asSuper() { |
| 3059 Source a = addSource( | 3083 Source a = addSource( |
| 3060 '/a.dart', | 3084 '/a.dart', |
| 3061 r''' | 3085 r''' |
| 3062 class A {} | 3086 class A {} |
| 3063 '''); | 3087 '''); |
| 3064 Source b = addSource( | 3088 Source b = addSource( |
| 3065 '/b.dart', | 3089 '/b.dart', |
| 3066 r''' | 3090 r''' |
| 3067 import 'a.dart'; | 3091 import 'a.dart'; |
| 3068 class B extends A {} | 3092 class B extends A {} |
| 3069 '''); | 3093 '''); |
| 3070 _performPendingAnalysisTasks(); | 3094 _performPendingAnalysisTasks(); |
| 3071 // Update a.dart: remove A, add A2. | 3095 // Update a.dart: remove A, add A2. |
| 3072 // b.dart is invalid, because it references A. | 3096 // b.dart is invalid, because it references A. |
| 3073 context.setContents( | 3097 context.setContents( |
| 3074 a, | 3098 a, |
| 3075 r''' | 3099 r''' |
| 3076 class A2 {} | 3100 class A2 {} |
| 3077 '''); | 3101 '''); |
| 3102 _assertValidForChangedLibrary(a); |
| 3078 _assertInvalid(a, LIBRARY_ERRORS_READY); | 3103 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 3104 _assertValidForDependentLibrary(b); |
| 3079 _assertInvalid(b, LIBRARY_ERRORS_READY); | 3105 _assertInvalid(b, LIBRARY_ERRORS_READY); |
| 3080 _assertInvalidUnits(b, RESOLVED_UNIT2); | 3106 _assertInvalidUnits(b, RESOLVED_UNIT4); |
| 3081 _assertInvalidLibraryElements(b, LIBRARY_ELEMENT2); | |
| 3082 } | 3107 } |
| 3083 | 3108 |
| 3084 void test_usedName_class_name_asTypeBound() { | 3109 void test_usedName_class_name_asTypeBound() { |
| 3085 Source a = addSource( | 3110 Source a = addSource( |
| 3086 '/a.dart', | 3111 '/a.dart', |
| 3087 r''' | 3112 r''' |
| 3088 class A {} | 3113 class A {} |
| 3089 '''); | 3114 '''); |
| 3090 Source b = addSource( | 3115 Source b = addSource( |
| 3091 '/b.dart', | 3116 '/b.dart', |
| 3092 r''' | 3117 r''' |
| 3093 import 'a.dart'; | 3118 import 'a.dart'; |
| 3094 class B<T extends A> { | 3119 class B<T extends A> { |
| 3095 T f; | 3120 T f; |
| 3096 } | 3121 } |
| 3097 '''); | 3122 '''); |
| 3098 _performPendingAnalysisTasks(); | 3123 _performPendingAnalysisTasks(); |
| 3099 // Update a.dart: remove A, add A2. | 3124 // Update a.dart: remove A, add A2. |
| 3100 // b.dart is invalid, because it references A. | 3125 // b.dart is invalid, because it references A. |
| 3101 context.setContents( | 3126 context.setContents( |
| 3102 a, | 3127 a, |
| 3103 r''' | 3128 r''' |
| 3104 class A2 {} | 3129 class A2 {} |
| 3105 '''); | 3130 '''); |
| 3131 _assertValidForChangedLibrary(a); |
| 3106 _assertInvalid(a, LIBRARY_ERRORS_READY); | 3132 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 3133 _assertValidForDependentLibrary(b); |
| 3107 _assertInvalid(b, LIBRARY_ERRORS_READY); | 3134 _assertInvalid(b, LIBRARY_ERRORS_READY); |
| 3108 _assertInvalidUnits(b, RESOLVED_UNIT2); | 3135 _assertInvalidUnits(b, RESOLVED_UNIT4); |
| 3109 _assertInvalidLibraryElements(b, LIBRARY_ELEMENT2); | |
| 3110 } | 3136 } |
| 3111 | 3137 |
| 3112 void test_usedName_class_name_inBody() { | 3138 void test_usedName_class_name_inBody() { |
| 3113 Source a = addSource( | 3139 Source a = addSource( |
| 3114 '/a.dart', | 3140 '/a.dart', |
| 3115 r''' | 3141 r''' |
| 3116 class A {} | 3142 class A {} |
| 3117 class B {} | 3143 class B {} |
| 3118 class C {} | 3144 class C {} |
| 3119 '''); | 3145 '''); |
| 3120 Source b = addSource( | 3146 Source b = addSource( |
| 3121 '/b.dart', | 3147 '/b.dart', |
| 3122 r''' | 3148 r''' |
| 3123 import 'a.dart'; | 3149 import 'a.dart'; |
| 3124 main() { | 3150 main() { |
| 3125 new A(); | 3151 new A(); |
| 3126 new C(); | 3152 new C(); |
| 3127 } | 3153 } |
| 3128 '''); | 3154 '''); |
| 3129 _performPendingAnalysisTasks(); | 3155 _performPendingAnalysisTasks(); |
| 3130 // Update a.dart: remove C, add C2. | 3156 // Update a.dart: remove C, add C2. |
| 3131 // b.dart is invalid, because it references C. | 3157 // b.dart is invalid, because it references C. |
| 3132 context.setContents( | 3158 context.setContents( |
| 3133 a, | 3159 a, |
| 3134 r''' | 3160 r''' |
| 3135 class A {} | 3161 class A {} |
| 3136 class B {} | 3162 class B {} |
| 3137 class C2 {} | 3163 class C2 {} |
| 3138 '''); | 3164 '''); |
| 3165 _assertValidForChangedLibrary(a); |
| 3166 _assertValidForDependentLibrary(b); |
| 3139 _assertInvalid(a, LIBRARY_ERRORS_READY); | 3167 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 3140 _assertInvalid(b, LIBRARY_ERRORS_READY); | 3168 _assertInvalid(b, LIBRARY_ERRORS_READY); |
| 3141 _assertInvalidUnits(b, RESOLVED_UNIT2); | 3169 _assertInvalidUnits(b, RESOLVED_UNIT4); |
| 3142 _assertInvalidLibraryElements(b, LIBRARY_ELEMENT2); | |
| 3143 } | 3170 } |
| 3144 | 3171 |
| 3145 void test_usedName_classMethod_name_inBody() { | 3172 void test_usedName_classMethod_name_inBody() { |
| 3146 Source a = addSource( | 3173 Source a = addSource( |
| 3147 '/a.dart', | 3174 '/a.dart', |
| 3148 r''' | 3175 r''' |
| 3149 class A { | 3176 class A { |
| 3150 m() {} | 3177 m() {} |
| 3151 } | 3178 } |
| 3152 '''); | 3179 '''); |
| 3153 Source b = addSource( | 3180 Source b = addSource( |
| 3154 '/b.dart', | 3181 '/b.dart', |
| 3155 r''' | 3182 r''' |
| 3156 import 'a.dart'; | 3183 import 'a.dart'; |
| 3157 main() { | 3184 main() { |
| 3158 A a = new A(); | 3185 A a = new A(); |
| 3159 a.m(); | 3186 a.m(); |
| 3160 } | 3187 } |
| 3161 '''); | 3188 '''); |
| 3162 _performPendingAnalysisTasks(); | 3189 _performPendingAnalysisTasks(); |
| 3163 // Update a.dart: remove C.m, add C.m2. | 3190 // Update a.dart: remove C.m, add C.m2. |
| 3164 // b.dart is invalid, because it references c.m. | 3191 // b.dart is invalid, because it references c.m. |
| 3165 context.setContents( | 3192 context.setContents( |
| 3166 a, | 3193 a, |
| 3167 r''' | 3194 r''' |
| 3168 class A { | 3195 class A { |
| 3169 m2() {} | 3196 m2() {} |
| 3170 } | 3197 } |
| 3171 '''); | 3198 '''); |
| 3199 _assertValidForChangedLibrary(a); |
| 3172 _assertInvalid(a, LIBRARY_ERRORS_READY); | 3200 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 3201 _assertValidForDependentLibrary(b); |
| 3202 _assertInvalidLibraryElements(b, LIBRARY_ELEMENT4); |
| 3203 _assertInvalidUnits(b, RESOLVED_UNIT4); |
| 3173 _assertInvalid(b, LIBRARY_ERRORS_READY); | 3204 _assertInvalid(b, LIBRARY_ERRORS_READY); |
| 3174 _assertInvalidUnits(b, RESOLVED_UNIT2); | |
| 3175 _assertInvalidLibraryElements(b, LIBRARY_ELEMENT2); | |
| 3176 } | 3205 } |
| 3177 | 3206 |
| 3178 void test_usedName_indirect_classMethod_name_inBody() { | 3207 void test_usedName_indirect_classMethod_name_inBody() { |
| 3179 Source a = addSource( | 3208 Source a = addSource( |
| 3180 '/a.dart', | 3209 '/a.dart', |
| 3181 r''' | 3210 r''' |
| 3182 class A { | 3211 class A { |
| 3183 m() {} | 3212 m() {} |
| 3184 } | 3213 } |
| 3185 '''); | 3214 '''); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3202 // Update a.dart: remove C.m, add C.m2. | 3231 // Update a.dart: remove C.m, add C.m2. |
| 3203 // b.dart is invalid, because B extends A. | 3232 // b.dart is invalid, because B extends A. |
| 3204 // c.dart is invalid, because 'main' references B. | 3233 // c.dart is invalid, because 'main' references B. |
| 3205 context.setContents( | 3234 context.setContents( |
| 3206 a, | 3235 a, |
| 3207 r''' | 3236 r''' |
| 3208 class A { | 3237 class A { |
| 3209 m2() {} | 3238 m2() {} |
| 3210 } | 3239 } |
| 3211 '''); | 3240 '''); |
| 3241 _assertValidForChangedLibrary(a); |
| 3212 _assertInvalid(a, LIBRARY_ERRORS_READY); | 3242 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 3243 |
| 3244 _assertValidForDependentLibrary(b); |
| 3245 _assertInvalidLibraryElements(b, LIBRARY_ELEMENT4); |
| 3246 _assertInvalidUnits(b, RESOLVED_UNIT4); |
| 3213 _assertInvalid(b, LIBRARY_ERRORS_READY); | 3247 _assertInvalid(b, LIBRARY_ERRORS_READY); |
| 3248 |
| 3249 _assertValidForDependentLibrary(c); |
| 3250 _assertInvalidLibraryElements(c, LIBRARY_ELEMENT5); |
| 3251 _assertInvalidUnits(c, RESOLVED_UNIT4); |
| 3214 _assertInvalid(c, LIBRARY_ERRORS_READY); | 3252 _assertInvalid(c, LIBRARY_ERRORS_READY); |
| 3215 _assertInvalidUnits(b, RESOLVED_UNIT2); | |
| 3216 _assertInvalidLibraryElements(b, LIBRARY_ELEMENT2); | |
| 3217 _assertInvalidUnits(c, RESOLVED_UNIT4); | |
| 3218 _assertInvalidLibraryElements(c, LIBRARY_ELEMENT5); | |
| 3219 } | 3253 } |
| 3220 | 3254 |
| 3221 void test_usedName_indirect_classMethod_returnType_inBody() { | 3255 void test_usedName_indirect_classMethod_returnType_inBody() { |
| 3222 Source a = addSource( | 3256 Source a = addSource( |
| 3223 '/a.dart', | 3257 '/a.dart', |
| 3224 r''' | 3258 r''' |
| 3225 class A { | 3259 class A { |
| 3226 int m() { | 3260 int m() { |
| 3227 return 1; | 3261 return 1; |
| 3228 } | 3262 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3250 context.setContents( | 3284 context.setContents( |
| 3251 a, | 3285 a, |
| 3252 r''' | 3286 r''' |
| 3253 class A { | 3287 class A { |
| 3254 double m() { | 3288 double m() { |
| 3255 return 1.2; | 3289 return 1.2; |
| 3256 } | 3290 } |
| 3257 } | 3291 } |
| 3258 '''); | 3292 '''); |
| 3259 _assertInvalid(a, LIBRARY_ERRORS_READY); | 3293 _assertInvalid(a, LIBRARY_ERRORS_READY); |
| 3260 _assertInvalid(b, LIBRARY_ERRORS_READY); | 3294 |
| 3261 _assertInvalid(c, LIBRARY_ERRORS_READY); | |
| 3262 // TODO(scheglov) In theory b.dart is not affected, because it does not | 3295 // TODO(scheglov) In theory b.dart is not affected, because it does not |
| 3263 // call A.m, does not override it, etc. | 3296 // call A.m, does not override it, etc. |
| 3264 _assertInvalidUnits(b, RESOLVED_UNIT2); | 3297 _assertValidForDependentLibrary(b); |
| 3265 _assertInvalidLibraryElements(b, LIBRARY_ELEMENT2); | 3298 _assertInvalidLibraryElements(b, LIBRARY_ELEMENT4); |
| 3299 _assertInvalidUnits(b, RESOLVED_UNIT4); |
| 3300 _assertInvalid(b, LIBRARY_ERRORS_READY); |
| 3301 |
| 3302 _assertValidForDependentLibrary(c); |
| 3303 _assertInvalidLibraryElements(c, LIBRARY_ELEMENT5); |
| 3266 _assertInvalidUnits(c, RESOLVED_UNIT4); | 3304 _assertInvalidUnits(c, RESOLVED_UNIT4); |
| 3267 _assertInvalidLibraryElements(c, LIBRARY_ELEMENT5); | 3305 _assertInvalid(c, LIBRARY_ERRORS_READY); |
| 3268 } | 3306 } |
| 3269 | 3307 |
| 3270 void _assertInvalid(AnalysisTarget target, ResultDescriptor descriptor) { | 3308 void _assertInvalid(AnalysisTarget target, ResultDescriptor descriptor) { |
| 3271 CacheState actual = analysisCache.getState(target, descriptor); | 3309 CacheState actual = analysisCache.getState(target, descriptor); |
| 3272 if (actual != CacheState.INVALID) { | 3310 if (actual != CacheState.INVALID) { |
| 3273 fail("cache state of $target $descriptor: wanted INVALID, got: $actual"); | 3311 fail("cache state of $target $descriptor: wanted INVALID, got: $actual"); |
| 3274 } | 3312 } |
| 3275 } | 3313 } |
| 3276 | 3314 |
| 3277 /** | 3315 /** |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3307 new LibrarySpecificUnit(librarySource, unitSource), descriptor); | 3345 new LibrarySpecificUnit(librarySource, unitSource), descriptor); |
| 3308 } | 3346 } |
| 3309 | 3347 |
| 3310 void _assertUnitValid(Source unitSource, ResultDescriptor descriptor, | 3348 void _assertUnitValid(Source unitSource, ResultDescriptor descriptor, |
| 3311 {Source librarySource}) { | 3349 {Source librarySource}) { |
| 3312 librarySource ??= unitSource; | 3350 librarySource ??= unitSource; |
| 3313 _assertValid( | 3351 _assertValid( |
| 3314 new LibrarySpecificUnit(librarySource, unitSource), descriptor); | 3352 new LibrarySpecificUnit(librarySource, unitSource), descriptor); |
| 3315 } | 3353 } |
| 3316 | 3354 |
| 3355 void _assertUnitValidTaskResults(Source unitSource, TaskDescriptor descriptor, |
| 3356 {Source librarySource}) { |
| 3357 librarySource ??= unitSource; |
| 3358 for (ResultDescriptor result in descriptor.results) { |
| 3359 _assertUnitValid(unitSource, result, librarySource: librarySource); |
| 3360 } |
| 3361 } |
| 3362 |
| 3317 void _assertValid(AnalysisTarget target, ResultDescriptor descriptor) { | 3363 void _assertValid(AnalysisTarget target, ResultDescriptor descriptor) { |
| 3318 CacheState state = analysisCache.getState(target, descriptor); | 3364 CacheState state = analysisCache.getState(target, descriptor); |
| 3319 expect(state, CacheState.VALID, reason: '$descriptor in $target'); | 3365 expect(state, isIn([CacheState.VALID, CacheState.FLUSHED]), |
| 3366 reason: '$descriptor in $target'); |
| 3367 } |
| 3368 |
| 3369 void _assertValidAllLibraryUnitResults(Source source, {Source library}) { |
| 3370 for (ResultDescriptor<LibraryElement> result in LIBRARY_ELEMENT_RESULTS) { |
| 3371 _assertValid(source, result); |
| 3372 } |
| 3373 library ??= source; |
| 3374 LibrarySpecificUnit target = new LibrarySpecificUnit(library, source); |
| 3375 for (ResultDescriptor<CompilationUnit> result in RESOLVED_UNIT_RESULTS) { |
| 3376 _assertValid(target, result); |
| 3377 } |
| 3378 } |
| 3379 |
| 3380 void _assertValidForAnyLibrary(Source source) { |
| 3381 // Source results. |
| 3382 _assertValidTaskResults(source, ScanDartTask.DESCRIPTOR); |
| 3383 // Library results. |
| 3384 _assertValidTaskResults(source, BuildLibraryElementTask.DESCRIPTOR); |
| 3385 _assertValidTaskResults(source, BuildDirectiveElementsTask.DESCRIPTOR); |
| 3386 _assertValidTaskResults(source, BuildSourceExportClosureTask.DESCRIPTOR); |
| 3387 _assertValidTaskResults(source, ReadyLibraryElement2Task.DESCRIPTOR); |
| 3388 // Unit results. |
| 3389 _assertUnitValidTaskResults( |
| 3390 source, BuildCompilationUnitElementTask.DESCRIPTOR); |
| 3391 _assertUnitValidTaskResults( |
| 3392 source, ResolveDirectiveElementsTask.DESCRIPTOR); |
| 3393 _assertUnitValidTaskResults(source, BuildEnumMemberElementsTask.DESCRIPTOR); |
| 3394 _assertUnitValidTaskResults(source, ComputeLibraryCycleTask.DESCRIPTOR); |
| 3395 } |
| 3396 |
| 3397 void _assertValidForChangedLibrary(Source source) { |
| 3398 _assertValidForAnyLibrary(source); |
| 3399 } |
| 3400 |
| 3401 void _assertValidForDependentLibrary(Source source) { |
| 3402 _assertValidForAnyLibrary(source); |
| 3403 // Library results. |
| 3404 _assertValidTaskResults(source, BuildPublicNamespaceTask.DESCRIPTOR); |
| 3405 } |
| 3406 |
| 3407 void _assertValidTaskResults(AnalysisTarget target, TaskDescriptor task) { |
| 3408 for (ResultDescriptor result in task.results) { |
| 3409 _assertValid(target, result); |
| 3410 } |
| 3320 } | 3411 } |
| 3321 | 3412 |
| 3322 void _performPendingAnalysisTasks([int maxTasks = 512]) { | 3413 void _performPendingAnalysisTasks([int maxTasks = 512]) { |
| 3323 for (int i = 0; context.performAnalysisTask().hasMoreWork; i++) { | 3414 for (int i = 0; context.performAnalysisTask().hasMoreWork; i++) { |
| 3324 if (i > maxTasks) { | 3415 if (i > maxTasks) { |
| 3325 fail('Analysis did not terminate.'); | 3416 fail('Analysis did not terminate.'); |
| 3326 } | 3417 } |
| 3327 } | 3418 } |
| 3328 } | 3419 } |
| 3329 } | 3420 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3428 * Initialize the visitor. | 3519 * Initialize the visitor. |
| 3429 */ | 3520 */ |
| 3430 _ElementGatherer(); | 3521 _ElementGatherer(); |
| 3431 | 3522 |
| 3432 @override | 3523 @override |
| 3433 void visitElement(Element element) { | 3524 void visitElement(Element element) { |
| 3434 elements[element] = element; | 3525 elements[element] = element; |
| 3435 super.visitElement(element); | 3526 super.visitElement(element); |
| 3436 } | 3527 } |
| 3437 } | 3528 } |
| OLD | NEW |