| 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 engine.incremental_resolver_test; | 5 library engine.incremental_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 void fail_test_constructor_fieldInitializer_add() { | 1093 void fail_test_constructor_fieldInitializer_add() { |
| 1094 // TODO(scheglov) resolver uses "enclosingClass", which we don't set yet | 1094 // TODO(scheglov) resolver uses "enclosingClass", which we don't set yet |
| 1095 _resolveUnit(r''' | 1095 _resolveUnit(r''' |
| 1096 class A { | 1096 class A { |
| 1097 int f; | 1097 int f; |
| 1098 A(int a, int b); | 1098 A(int a, int b); |
| 1099 }'''); | 1099 }'''); |
| 1100 _resolve(_editString(');', ') : f = a + b;'), _isClassMember); | 1100 _resolve(_editString(');', ') : f = a + b;'), _isClassMember); |
| 1101 } | 1101 } |
| 1102 | 1102 |
| 1103 void fail_test_functionBody_addLocalVariable() { | 1103 void fail_test_constructor_fieldInitializer_edit() { |
| 1104 // TODO(scheglov) this test fails, because we don't create element models | 1104 // TODO(scheglov) resolver uses "enclosingClass", which we don't set yet |
| 1105 // for new local variables | |
| 1106 _resolveUnit(r''' | 1105 _resolveUnit(r''' |
| 1107 main(int a, int b) { | 1106 class A { |
| 1107 int f; |
| 1108 A(int a, int b) : f = a + b { |
| 1109 int a = 42; |
| 1110 } |
| 1111 }'''); |
| 1112 _resolve(_editString('+', '*'), _isExpression); |
| 1113 } |
| 1114 |
| 1115 void fail_test_topLevelFunction_parameter_rename() { |
| 1116 // TODO(scheglov) Decide if incremental parser keeps the element |
| 1117 // of the function. If so, we can resolve parameter renames. |
| 1118 _resolveUnit(r''' |
| 1119 int main(int a, int b) { |
| 1108 return a + b; | 1120 return a + b; |
| 1109 } | 1121 } |
| 1110 '''); | 1122 '''); |
| 1111 _resolve(_editString(' return a + b;', r''' | 1123 _resolve(_editString(r'''(int a, int b) { |
| 1112 int res = a + b; | 1124 return a + b;''', r'''(int first, int b) { |
| 1113 return res; | 1125 return first + b;'''), _isDeclaration); |
| 1114 '''), _isBlock); | |
| 1115 } | 1126 } |
| 1116 | 1127 |
| 1117 void test_constructor_body() { | 1128 void test_constructor_body() { |
| 1118 _resolveUnit(r''' | 1129 _resolveUnit(r''' |
| 1119 class A { | 1130 class A { |
| 1120 int f; | 1131 int f; |
| 1121 A(int a, int b) { | 1132 A(int a, int b) { |
| 1122 f = a + b; | 1133 f = a + b; |
| 1123 } | 1134 } |
| 1124 }'''); | 1135 }'''); |
| 1125 _resolve(_editString('+', '*'), _isFunctionBody); | 1136 _resolve(_editString('+', '*'), _isFunctionBody); |
| 1126 } | 1137 } |
| 1127 | 1138 |
| 1128 void test_constructor_fieldInitializer_edit() { | |
| 1129 _resolveUnit(r''' | |
| 1130 class A { | |
| 1131 int f; | |
| 1132 A(int a, int b) : f = a + b { | |
| 1133 int a = 42; | |
| 1134 } | |
| 1135 }'''); | |
| 1136 _resolve(_editString('+', '*'), _isExpression); | |
| 1137 } | |
| 1138 | |
| 1139 void test_constructor_superConstructorInvocation() { | 1139 void test_constructor_superConstructorInvocation() { |
| 1140 _resolveUnit(r''' | 1140 _resolveUnit(r''' |
| 1141 class A { | 1141 class A { |
| 1142 A(int p); | 1142 A(int p); |
| 1143 } | 1143 } |
| 1144 class A { | 1144 class A { |
| 1145 A(int a, int b) : super(a + b); | 1145 A(int a, int b) : super(a + b); |
| 1146 } | 1146 } |
| 1147 '''); | 1147 '''); |
| 1148 _resolve(_editString('+', '*'), _isExpression); | 1148 _resolve(_editString('+', '*'), _isExpression); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1174 void test_method_body() { | 1174 void test_method_body() { |
| 1175 _resolveUnit(r''' | 1175 _resolveUnit(r''' |
| 1176 class A { | 1176 class A { |
| 1177 m(int a, int b) { | 1177 m(int a, int b) { |
| 1178 return a + b; | 1178 return a + b; |
| 1179 } | 1179 } |
| 1180 }'''); | 1180 }'''); |
| 1181 _resolve(_editString('+', '*'), _isFunctionBody); | 1181 _resolve(_editString('+', '*'), _isFunctionBody); |
| 1182 } | 1182 } |
| 1183 | 1183 |
| 1184 void test_method_label_add() { |
| 1185 _resolveUnit(r''' |
| 1186 class A { |
| 1187 int m(int a, int b) { |
| 1188 return a + b; |
| 1189 } |
| 1190 } |
| 1191 '''); |
| 1192 _resolve(_editString('return', 'label: return'), _isBlock); |
| 1193 } |
| 1194 |
| 1195 void test_method_localVariable_add() { |
| 1196 _resolveUnit(r''' |
| 1197 class A { |
| 1198 int m(int a, int b) { |
| 1199 return a + b; |
| 1200 } |
| 1201 } |
| 1202 '''); |
| 1203 _resolve(_editString(' return a + b;', r''' |
| 1204 int res = a + b; |
| 1205 return res; |
| 1206 '''), _isBlock); |
| 1207 } |
| 1208 |
| 1209 void test_topLevelFunction_label_add() { |
| 1210 _resolveUnit(r''' |
| 1211 int main(int a, int b) { |
| 1212 return a + b; |
| 1213 } |
| 1214 '''); |
| 1215 _resolve(_editString(' return', 'label: return a + b;'), _isBlock); |
| 1216 } |
| 1217 |
| 1218 void test_topLevelFunction_label_remove() { |
| 1219 _resolveUnit(r''' |
| 1220 int main(int a, int b) { |
| 1221 label: return a + b; |
| 1222 } |
| 1223 '''); |
| 1224 _resolve(_editString('label: ', ''), _isBlock); |
| 1225 } |
| 1226 |
| 1227 void test_topLevelFunction_localVariable_add() { |
| 1228 _resolveUnit(r''' |
| 1229 int main(int a, int b) { |
| 1230 return a + b; |
| 1231 } |
| 1232 '''); |
| 1233 _resolve(_editString(' return a + b;', r''' |
| 1234 int res = a + b; |
| 1235 return res; |
| 1236 '''), _isBlock); |
| 1237 } |
| 1238 |
| 1239 void test_topLevelFunction_localVariable_remove() { |
| 1240 _resolveUnit(r''' |
| 1241 int main(int a, int b) { |
| 1242 int res = a * b; |
| 1243 return a + b; |
| 1244 } |
| 1245 '''); |
| 1246 _resolve(_editString('int res = a * b;', ''), _isBlock); |
| 1247 } |
| 1248 |
| 1184 void test_topLevelVariable_initializer() { | 1249 void test_topLevelVariable_initializer() { |
| 1185 _resolveUnit(r''' | 1250 _resolveUnit(r''' |
| 1186 int C = 1 + 2; | 1251 int C = 1 + 2; |
| 1187 '''); | 1252 '''); |
| 1188 _resolve(_editString('+', '*'), _isExpression); | 1253 _resolve(_editString('+', '*'), _isExpression); |
| 1189 } | 1254 } |
| 1190 | 1255 |
| 1191 void test_updateElementOffset() { | 1256 void test_updateElementOffset() { |
| 1192 _resolveUnit(r''' | 1257 _resolveUnit(r''' |
| 1193 class A { | 1258 class A { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1271 Predicate<AstNode> predicate) { | 1336 Predicate<AstNode> predicate) { |
| 1272 NodeLocator locator = new NodeLocator.con1(offset); | 1337 NodeLocator locator = new NodeLocator.con1(offset); |
| 1273 AstNode node = locator.searchWithin(oldUnit); | 1338 AstNode node = locator.searchWithin(oldUnit); |
| 1274 return node.getAncestor(predicate); | 1339 return node.getAncestor(predicate); |
| 1275 } | 1340 } |
| 1276 | 1341 |
| 1277 static bool _isBlock(AstNode node) => node is Block; | 1342 static bool _isBlock(AstNode node) => node is Block; |
| 1278 | 1343 |
| 1279 static bool _isClassMember(AstNode node) => node is ClassMember; | 1344 static bool _isClassMember(AstNode node) => node is ClassMember; |
| 1280 | 1345 |
| 1346 static bool _isDeclaration(AstNode node) => node is Declaration; |
| 1347 |
| 1281 static bool _isExpression(AstNode node) => node is Expression; | 1348 static bool _isExpression(AstNode node) => node is Expression; |
| 1282 | 1349 |
| 1283 static bool _isFunctionBody(AstNode node) => node is FunctionBody; | 1350 static bool _isFunctionBody(AstNode node) => node is FunctionBody; |
| 1284 | 1351 |
| 1285 static bool _isStatement(AstNode node) => node is Statement; | 1352 static bool _isStatement(AstNode node) => node is Statement; |
| 1286 | 1353 |
| 1287 static CompilationUnit _parseUnit(String code) { | 1354 static CompilationUnit _parseUnit(String code) { |
| 1288 var errorListener = new BooleanErrorListener(); | 1355 var errorListener = new BooleanErrorListener(); |
| 1289 var reader = new CharSequenceReader(code); | 1356 var reader = new CharSequenceReader(code); |
| 1290 var scanner = new Scanner(null, reader, errorListener); | 1357 var scanner = new Scanner(null, reader, errorListener); |
| (...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2372 _visitList(node.metadata, other.metadata); | 2439 _visitList(node.metadata, other.metadata); |
| 2373 _visitNode(node.identifier, other.identifier); | 2440 _visitNode(node.identifier, other.identifier); |
| 2374 } | 2441 } |
| 2375 | 2442 |
| 2376 static void assertSameResolution(CompilationUnit actual, | 2443 static void assertSameResolution(CompilationUnit actual, |
| 2377 CompilationUnit expected) { | 2444 CompilationUnit expected) { |
| 2378 _SameResolutionValidator validator = new _SameResolutionValidator(expected); | 2445 _SameResolutionValidator validator = new _SameResolutionValidator(expected); |
| 2379 actual.accept(validator); | 2446 actual.accept(validator); |
| 2380 } | 2447 } |
| 2381 } | 2448 } |
| OLD | NEW |