OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
8 import 'package:compiler/src/compiler.dart'; | 8 import 'package:compiler/src/compiler.dart'; |
9 import 'package:compiler/src/diagnostics/messages.dart' show | 9 import 'package:compiler/src/diagnostics/messages.dart' show |
10 MessageKind; | 10 MessageKind; |
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 } | 1016 } |
1017 ''', | 1017 ''', |
1018 MessageKind.NOT_ASSIGNABLE); | 1018 MessageKind.NOT_ASSIGNABLE); |
1019 } | 1019 } |
1020 | 1020 |
1021 Future testEffectiveTarget() async { | 1021 Future testEffectiveTarget() async { |
1022 String origin = """ | 1022 String origin = """ |
1023 class A { | 1023 class A { |
1024 A() : super(); | 1024 A() : super(); |
1025 factory A.forward() = B.patchTarget; | 1025 factory A.forward() = B.patchTarget; |
| 1026 factory A.forwardOne() = B.patchFactory; |
1026 factory A.forwardTwo() = B.reflectBack; | 1027 factory A.forwardTwo() = B.reflectBack; |
| 1028 factory A.forwardThree() = B.patchInjected; |
1027 } | 1029 } |
1028 class B extends A { | 1030 class B extends A { |
1029 B() : super(); | 1031 B() : super(); |
1030 external B.patchTarget(); | 1032 external B.patchTarget(); |
| 1033 external factory B.patchFactory(); |
1031 external factory B.reflectBack(); | 1034 external factory B.reflectBack(); |
1032 B.originTarget() : super(); | 1035 B.originTarget() : super(); |
| 1036 external factory B.patchInjected(); |
1033 } | 1037 } |
1034 """; | 1038 """; |
1035 String patch = """ | 1039 String patch = """ |
1036 @patch class B { | 1040 @patch class B { |
1037 @patch | 1041 @patch |
1038 B.patchTarget() : super(); | 1042 B.patchTarget() : super(); |
1039 @patch | 1043 @patch |
| 1044 factory B.patchFactory() => new B.patchTarget(); |
| 1045 @patch |
1040 factory B.reflectBack() = B.originTarget; | 1046 factory B.reflectBack() = B.originTarget; |
| 1047 @patch |
| 1048 factory B.patchInjected() = _C.injected; |
| 1049 } |
| 1050 class _C extends B { |
| 1051 _C.injected() : super.patchTarget(); |
1041 } | 1052 } |
1042 """; | 1053 """; |
1043 | 1054 |
1044 var compiler = await applyPatch(origin, patch, analyzeAll: true, | 1055 var compiler = await applyPatch(origin, patch, analyzeAll: true, |
1045 analyzeOnly: true, runCompiler: true); | 1056 analyzeOnly: true, runCompiler: true); |
1046 ClassElement clsA = compiler.coreLibrary.find("A"); | 1057 ClassElement clsA = compiler.coreLibrary.find("A"); |
1047 ClassElement clsB = compiler.coreLibrary.find("B"); | 1058 ClassElement clsB = compiler.coreLibrary.find("B"); |
1048 | 1059 |
1049 ConstructorElement forward = clsA.lookupConstructor("forward"); | 1060 ConstructorElement forward = clsA.lookupConstructor("forward"); |
1050 ConstructorElement target = forward.effectiveTarget; | 1061 ConstructorElement target = forward.effectiveTarget; |
1051 Expect.isTrue(target.isPatch); | 1062 Expect.isTrue(target.isPatched, "Unexpected target $target for $forward"); |
| 1063 Expect.isFalse(target.isPatch, "Unexpected target $target for $forward"); |
1052 Expect.equals("patchTarget", target.name); | 1064 Expect.equals("patchTarget", target.name); |
1053 | 1065 |
| 1066 ConstructorElement forwardOne = clsA.lookupConstructor("forwardOne"); |
| 1067 target = forwardOne.effectiveTarget; |
| 1068 Expect.isFalse(forwardOne.isMalformed); |
| 1069 Expect.isFalse(target.isPatch, "Unexpected target $target for $forwardOne"); |
| 1070 Expect.equals("patchFactory", target.name); |
| 1071 |
1054 ConstructorElement forwardTwo = clsA.lookupConstructor("forwardTwo"); | 1072 ConstructorElement forwardTwo = clsA.lookupConstructor("forwardTwo"); |
1055 target = forwardTwo.effectiveTarget; | 1073 target = forwardTwo.effectiveTarget; |
1056 Expect.isFalse(forwardTwo.isMalformed); | 1074 Expect.isFalse(forwardTwo.isMalformed); |
1057 Expect.isFalse(target.isPatch); | 1075 Expect.isFalse(target.isPatch, "Unexpected target $target for $forwardTwo"); |
1058 Expect.equals("originTarget", target.name); | 1076 Expect.equals("originTarget", target.name); |
| 1077 |
| 1078 ConstructorElement forwardThree = clsA.lookupConstructor("forwardThree"); |
| 1079 target = forwardThree.effectiveTarget; |
| 1080 Expect.isFalse(forwardThree.isMalformed); |
| 1081 Expect.isTrue(target.isInjected, |
| 1082 "Unexpected target $target for $forwardThree"); |
| 1083 Expect.equals("injected", target.name); |
1059 } | 1084 } |
1060 | 1085 |
1061 Future testTypecheckPatchedMembers() async { | 1086 Future testTypecheckPatchedMembers() async { |
1062 String originText = "external void method();"; | 1087 String originText = "external void method();"; |
1063 String patchText = """ | 1088 String patchText = """ |
1064 @patch void method() { | 1089 @patch void method() { |
1065 String s = 0; | 1090 String s = 0; |
1066 } | 1091 } |
1067 """; | 1092 """; |
1068 var compiler = await applyPatch(originText, patchText, | 1093 var compiler = await applyPatch(originText, patchText, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 await testPatchNonFunction(); | 1135 await testPatchNonFunction(); |
1111 | 1136 |
1112 await testPatchAndSelector(); | 1137 await testPatchAndSelector(); |
1113 | 1138 |
1114 await testEffectiveTarget(); | 1139 await testEffectiveTarget(); |
1115 | 1140 |
1116 await testAnalyzeAllInjectedMembers(); | 1141 await testAnalyzeAllInjectedMembers(); |
1117 await testTypecheckPatchedMembers(); | 1142 await testTypecheckPatchedMembers(); |
1118 }); | 1143 }); |
1119 } | 1144 } |
OLD | NEW |