| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.summary.summary_common; | 5 library analyzer.test.src.summary.summary_common; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 void checkAnnotationA(List<UnlinkedConst> annotations) { | 204 void checkAnnotationA(List<UnlinkedConst> annotations) { |
| 205 expect(annotations, hasLength(1)); | 205 expect(annotations, hasLength(1)); |
| 206 _assertUnlinkedConst(annotations[0], operators: [ | 206 _assertUnlinkedConst(annotations[0], operators: [ |
| 207 UnlinkedConstOperation.pushReference | 207 UnlinkedConstOperation.pushReference |
| 208 ], referenceValidators: [ | 208 ], referenceValidators: [ |
| 209 (EntityRef r) => checkTypeRef(r, null, null, 'a', | 209 (EntityRef r) => checkTypeRef(r, null, null, 'a', |
| 210 expectedKind: ReferenceKind.topLevelPropertyAccessor) | 210 expectedKind: ReferenceKind.topLevelPropertyAccessor) |
| 211 ]); | 211 ]); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void checkConstCycle(String className, |
| 215 {String name: '', bool hasCycle: true}) { |
| 216 UnlinkedClass cls = findClass(className); |
| 217 int constCycleSlot = |
| 218 findExecutable(name, executables: cls.executables).constCycleSlot; |
| 219 expect(constCycleSlot, isNot(0)); |
| 220 if (!skipFullyLinkedData) { |
| 221 expect( |
| 222 definingUnit.constCycles, |
| 223 hasCycle |
| 224 ? contains(constCycleSlot) |
| 225 : isNot(contains(constCycleSlot))); |
| 226 } |
| 227 } |
| 228 |
| 214 /** | 229 /** |
| 215 * Verify that the [dependency]th element of the dependency table represents | 230 * Verify that the [dependency]th element of the dependency table represents |
| 216 * a file reachable via the given [absoluteUri] and [relativeUri]. | 231 * a file reachable via the given [absoluteUri] and [relativeUri]. |
| 217 */ | 232 */ |
| 218 void checkDependency(int dependency, String absoluteUri, String relativeUri) { | 233 void checkDependency(int dependency, String absoluteUri, String relativeUri) { |
| 219 if (expectAbsoluteUrisInDependencies) { | 234 if (expectAbsoluteUrisInDependencies) { |
| 220 // The element model doesn't (yet) store enough information to recover | 235 // The element model doesn't (yet) store enough information to recover |
| 221 // relative URIs, so we have to use the absolute URI. | 236 // relative URIs, so we have to use the absolute URI. |
| 222 // TODO(paulberry): fix this. | 237 // TODO(paulberry): fix this. |
| 223 relativeUri = absoluteUri; | 238 relativeUri = absoluteUri; |
| (...skipping 3679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3903 } | 3918 } |
| 3904 class D { | 3919 class D { |
| 3905 final x; | 3920 final x; |
| 3906 const D() : x = const C(); | 3921 const D() : x = const C(); |
| 3907 } | 3922 } |
| 3908 class E { | 3923 class E { |
| 3909 final x; | 3924 final x; |
| 3910 const E() : x = null; | 3925 const E() : x = null; |
| 3911 } | 3926 } |
| 3912 '''); | 3927 '''); |
| 3913 int classCConstCycleSlot = findClass('C').executables[0].constCycleSlot; | 3928 checkConstCycle('C'); |
| 3914 expect(classCConstCycleSlot, isNot(0)); | 3929 checkConstCycle('D'); |
| 3915 int classDConstCycleSlot = findClass('D').executables[0].constCycleSlot; | 3930 checkConstCycle('E', hasCycle: false); |
| 3916 expect(classDConstCycleSlot, isNot(0)); | |
| 3917 int classEConstCycleSlot = findClass('E').executables[0].constCycleSlot; | |
| 3918 expect(classEConstCycleSlot, isNot(0)); | |
| 3919 if (!skipFullyLinkedData) { | |
| 3920 expect(definingUnit.constCycles, contains(classCConstCycleSlot)); | |
| 3921 expect(definingUnit.constCycles, contains(classDConstCycleSlot)); | |
| 3922 expect(definingUnit.constCycles, isNot(contains(classEConstCycleSlot))); | |
| 3923 } | |
| 3924 } | 3931 } |
| 3925 | 3932 |
| 3926 test_constructor_withCycles_nonConst() { | 3933 test_constructor_withCycles_nonConst() { |
| 3927 serializeLibraryText(''' | 3934 serializeLibraryText(''' |
| 3928 class C { | 3935 class C { |
| 3929 final x; | 3936 final x; |
| 3930 C() : x = new D(); | 3937 C() : x = new D(); |
| 3931 } | 3938 } |
| 3932 class D { | 3939 class D { |
| 3933 final x; | 3940 final x; |
| 3934 D() : x = new C(); | 3941 D() : x = new C(); |
| 3935 } | 3942 } |
| 3936 '''); | 3943 '''); |
| 3937 expect(findClass('C').executables[0].constCycleSlot, 0); | 3944 expect(findClass('C').executables[0].constCycleSlot, 0); |
| 3938 expect(findClass('D').executables[0].constCycleSlot, 0); | 3945 expect(findClass('D').executables[0].constCycleSlot, 0); |
| 3939 } | 3946 } |
| 3940 | 3947 |
| 3948 test_constructorCycle_referenceToEnumValue() { |
| 3949 serializeLibraryText(''' |
| 3950 enum E { v } |
| 3951 class C { |
| 3952 final x; |
| 3953 const C() : x = E.v; |
| 3954 } |
| 3955 '''); |
| 3956 checkConstCycle('C', hasCycle: false); |
| 3957 } |
| 3958 |
| 3959 test_constructorCycle_referenceToEnumValues() { |
| 3960 serializeLibraryText(''' |
| 3961 enum E { v } |
| 3962 class C { |
| 3963 final x; |
| 3964 const C() : x = E.values; |
| 3965 } |
| 3966 '''); |
| 3967 checkConstCycle('C', hasCycle: false); |
| 3968 } |
| 3969 |
| 3970 test_constructorCycle_viaFinalField() { |
| 3971 serializeLibraryText( |
| 3972 ''' |
| 3973 class C { |
| 3974 final x = const C(); |
| 3975 const C(); |
| 3976 } |
| 3977 ''', |
| 3978 allowErrors: true); |
| 3979 checkConstCycle('C'); |
| 3980 } |
| 3981 |
| 3982 test_constructorCycle_viaNamedConstructor() { |
| 3983 serializeLibraryText(''' |
| 3984 class C { |
| 3985 final x; |
| 3986 const C() : x = const D.named(); |
| 3987 } |
| 3988 class D { |
| 3989 final x; |
| 3990 const D.named() : x = const C(); |
| 3991 } |
| 3992 '''); |
| 3993 checkConstCycle('C'); |
| 3994 checkConstCycle('D', name: 'named'); |
| 3995 } |
| 3996 |
| 3997 test_constructorCycle_viaStaticField_inOtherClass() { |
| 3998 serializeLibraryText( |
| 3999 ''' |
| 4000 class C { |
| 4001 final x; |
| 4002 const C() : x = D.y; |
| 4003 } |
| 4004 class D { |
| 4005 static const y = const C(); |
| 4006 } |
| 4007 ''', |
| 4008 allowErrors: true); |
| 4009 checkConstCycle('C'); |
| 4010 } |
| 4011 |
| 4012 test_constructorCycle_viaStaticField_inSameClass() { |
| 4013 serializeLibraryText( |
| 4014 ''' |
| 4015 class C { |
| 4016 final x; |
| 4017 static const y = const C(); |
| 4018 const C() : x = y; |
| 4019 } |
| 4020 ''', |
| 4021 allowErrors: true); |
| 4022 checkConstCycle('C'); |
| 4023 } |
| 4024 |
| 4025 test_constructorCycle_viaSupertype() { |
| 4026 serializeLibraryText(''' |
| 4027 class C { |
| 4028 final x; |
| 4029 const C() : x = const D(); |
| 4030 } |
| 4031 class D extends C { |
| 4032 const D(); |
| 4033 } |
| 4034 '''); |
| 4035 checkConstCycle('C'); |
| 4036 checkConstCycle('D'); |
| 4037 } |
| 4038 |
| 4039 test_constructorCycle_viaSupertype_Enum() { |
| 4040 // It's not valid Dart but we need to make sure it doesn't crash |
| 4041 // summary generation. |
| 4042 serializeLibraryText( |
| 4043 ''' |
| 4044 enum E { v } |
| 4045 class C extends E { |
| 4046 const C(); |
| 4047 } |
| 4048 ''', |
| 4049 allowErrors: true); |
| 4050 checkConstCycle('C', hasCycle: false); |
| 4051 } |
| 4052 |
| 4053 test_constructorCycle_viaSupertype_withDefaultTypeArgument() { |
| 4054 serializeLibraryText(''' |
| 4055 class C<T> { |
| 4056 final x; |
| 4057 const C() : x = const D(); |
| 4058 } |
| 4059 class D extends C { |
| 4060 const D(); |
| 4061 } |
| 4062 '''); |
| 4063 checkConstCycle('C'); |
| 4064 checkConstCycle('D'); |
| 4065 } |
| 4066 |
| 4067 test_constructorCycle_viaSupertype_withTypeArgument() { |
| 4068 serializeLibraryText(''' |
| 4069 class C<T> { |
| 4070 final x; |
| 4071 const C() : x = const D(); |
| 4072 } |
| 4073 class D extends C<int> { |
| 4074 const D(); |
| 4075 } |
| 4076 '''); |
| 4077 checkConstCycle('C'); |
| 4078 checkConstCycle('D'); |
| 4079 } |
| 4080 |
| 4081 test_constructorCycle_viaTopLevelVariable() { |
| 4082 serializeLibraryText( |
| 4083 ''' |
| 4084 class C { |
| 4085 final x; |
| 4086 const C() : x = y; |
| 4087 } |
| 4088 const y = const C(); |
| 4089 ''', |
| 4090 allowErrors: true); |
| 4091 checkConstCycle('C'); |
| 4092 } |
| 4093 |
| 3941 test_dependencies_export_to_export_unused() { | 4094 test_dependencies_export_to_export_unused() { |
| 3942 addNamedSource('/a.dart', 'export "b.dart";'); | 4095 addNamedSource('/a.dart', 'export "b.dart";'); |
| 3943 addNamedSource('/b.dart', ''); | 4096 addNamedSource('/b.dart', ''); |
| 3944 serializeLibraryText('export "a.dart";'); | 4097 serializeLibraryText('export "a.dart";'); |
| 3945 // The main test library depends on b.dart, even though it doesn't | 4098 // The main test library depends on b.dart, even though it doesn't |
| 3946 // re-export any names defined in b.dart, because a change to b.dart might | 4099 // re-export any names defined in b.dart, because a change to b.dart might |
| 3947 // cause it to start exporting a name that the main test library *does* | 4100 // cause it to start exporting a name that the main test library *does* |
| 3948 // use. | 4101 // use. |
| 3949 checkHasDependency(absUri('/b.dart'), 'b.dart'); | 4102 checkHasDependency(absUri('/b.dart'), 'b.dart'); |
| 3950 } | 4103 } |
| (...skipping 3697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7648 class _PrefixExpectation { | 7801 class _PrefixExpectation { |
| 7649 final ReferenceKind kind; | 7802 final ReferenceKind kind; |
| 7650 final String name; | 7803 final String name; |
| 7651 final String absoluteUri; | 7804 final String absoluteUri; |
| 7652 final String relativeUri; | 7805 final String relativeUri; |
| 7653 final int numTypeParameters; | 7806 final int numTypeParameters; |
| 7654 | 7807 |
| 7655 _PrefixExpectation(this.kind, this.name, | 7808 _PrefixExpectation(this.kind, this.name, |
| 7656 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); | 7809 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); |
| 7657 } | 7810 } |
| OLD | NEW |