| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
| 8 | 8 |
| 9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:analyzer/file_system/memory_file_system.dart'; | 10 import 'package:analyzer/file_system/memory_file_system.dart'; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 new ResourceUriResolver(provider) | 58 new ResourceUriResolver(provider) |
| 59 ], null, provider); | 59 ], null, provider); |
| 60 AnalysisOptions analysisOptions = new AnalysisOptionsImpl() | 60 AnalysisOptions analysisOptions = new AnalysisOptionsImpl() |
| 61 ..strongMode = true; | 61 ..strongMode = true; |
| 62 fileSystemState = new FileSystemState(logger, byteStore, contentOverlay, | 62 fileSystemState = new FileSystemState(logger, byteStore, contentOverlay, |
| 63 provider, sourceFactory, analysisOptions, new Uint32List(0)); | 63 provider, sourceFactory, analysisOptions, new Uint32List(0)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 test_definedClassMemberNames() { | 66 test_definedClassMemberNames() { |
| 67 String path = _p('/aaa/lib/a.dart'); | 67 String path = _p('/aaa/lib/a.dart'); |
| 68 provider.newFile( | 68 provider.newFile(path, r''' |
| 69 path, | |
| 70 r''' | |
| 71 class A { | 69 class A { |
| 72 int a, b; | 70 int a, b; |
| 73 A(); | 71 A(); |
| 74 A.c(); | 72 A.c(); |
| 75 d() {} | 73 d() {} |
| 76 get e => null; | 74 get e => null; |
| 77 set f(_) {} | 75 set f(_) {} |
| 78 } | 76 } |
| 79 class B { | 77 class B { |
| 80 g() {} | 78 g() {} |
| 81 } | 79 } |
| 82 '''); | 80 '''); |
| 83 FileState file = fileSystemState.getFileForPath(path); | 81 FileState file = fileSystemState.getFileForPath(path); |
| 84 expect(file.definedClassMemberNames, | 82 expect(file.definedClassMemberNames, |
| 85 unorderedEquals(['a', 'b', 'd', 'e', 'f', 'g'])); | 83 unorderedEquals(['a', 'b', 'd', 'e', 'f', 'g'])); |
| 86 } | 84 } |
| 87 | 85 |
| 88 test_definedTopLevelNames() { | 86 test_definedTopLevelNames() { |
| 89 String path = _p('/aaa/lib/a.dart'); | 87 String path = _p('/aaa/lib/a.dart'); |
| 90 provider.newFile( | 88 provider.newFile(path, r''' |
| 91 path, | |
| 92 r''' | |
| 93 class A {} | 89 class A {} |
| 94 class B = Object with A; | 90 class B = Object with A; |
| 95 typedef C(); | 91 typedef C(); |
| 96 D() {} | 92 D() {} |
| 97 get E => null; | 93 get E => null; |
| 98 set F(_) {} | 94 set F(_) {} |
| 99 var G, H; | 95 var G, H; |
| 100 '''); | 96 '''); |
| 101 FileState file = fileSystemState.getFileForPath(path); | 97 FileState file = fileSystemState.getFileForPath(path); |
| 102 expect(file.definedTopLevelNames, | 98 expect(file.definedTopLevelNames, |
| 103 unorderedEquals(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'])); | 99 unorderedEquals(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'])); |
| 104 } | 100 } |
| 105 | 101 |
| 106 test_exportedTopLevelDeclarations_export() { | 102 test_exportedTopLevelDeclarations_export() { |
| 107 String a = _p('/aaa/lib/a.dart'); | 103 String a = _p('/aaa/lib/a.dart'); |
| 108 String b = _p('/aaa/lib/b.dart'); | 104 String b = _p('/aaa/lib/b.dart'); |
| 109 provider.newFile( | 105 provider.newFile(a, r''' |
| 110 a, | |
| 111 r''' | |
| 112 class A {} | 106 class A {} |
| 113 '''); | 107 '''); |
| 114 provider.newFile( | 108 provider.newFile(b, r''' |
| 115 b, | |
| 116 r''' | |
| 117 export 'a.dart'; | 109 export 'a.dart'; |
| 118 class B {} | 110 class B {} |
| 119 '''); | 111 '''); |
| 120 FileState file = fileSystemState.getFileForPath(b); | 112 FileState file = fileSystemState.getFileForPath(b); |
| 121 Map<String, TopLevelDeclaration> declarations = | 113 Map<String, TopLevelDeclaration> declarations = |
| 122 file.exportedTopLevelDeclarations; | 114 file.exportedTopLevelDeclarations; |
| 123 expect(declarations.keys, unorderedEquals(['A', 'B'])); | 115 expect(declarations.keys, unorderedEquals(['A', 'B'])); |
| 124 } | 116 } |
| 125 | 117 |
| 126 test_exportedTopLevelDeclarations_export2_show() { | 118 test_exportedTopLevelDeclarations_export2_show() { |
| 127 String a = _p('/aaa/lib/a.dart'); | 119 String a = _p('/aaa/lib/a.dart'); |
| 128 String b = _p('/aaa/lib/b.dart'); | 120 String b = _p('/aaa/lib/b.dart'); |
| 129 String c = _p('/aaa/lib/c.dart'); | 121 String c = _p('/aaa/lib/c.dart'); |
| 130 provider.newFile( | 122 provider.newFile(a, r''' |
| 131 a, | |
| 132 r''' | |
| 133 class A1 {} | 123 class A1 {} |
| 134 class A2 {} | 124 class A2 {} |
| 135 class A3 {} | 125 class A3 {} |
| 136 '''); | 126 '''); |
| 137 provider.newFile( | 127 provider.newFile(b, r''' |
| 138 b, | |
| 139 r''' | |
| 140 export 'a.dart' show A1, A2; | 128 export 'a.dart' show A1, A2; |
| 141 class B1 {} | 129 class B1 {} |
| 142 class B2 {} | 130 class B2 {} |
| 143 '''); | 131 '''); |
| 144 provider.newFile( | 132 provider.newFile(c, r''' |
| 145 c, | |
| 146 r''' | |
| 147 export 'b.dart' show A2, A3, B1; | 133 export 'b.dart' show A2, A3, B1; |
| 148 class C {} | 134 class C {} |
| 149 '''); | 135 '''); |
| 150 _assertExportedTopLevelDeclarations(c, ['A2', 'B1', 'C']); | 136 _assertExportedTopLevelDeclarations(c, ['A2', 'B1', 'C']); |
| 151 } | 137 } |
| 152 | 138 |
| 153 test_exportedTopLevelDeclarations_export_flushOnChange() { | 139 test_exportedTopLevelDeclarations_export_flushOnChange() { |
| 154 String a = _p('/aaa/lib/a.dart'); | 140 String a = _p('/aaa/lib/a.dart'); |
| 155 String b = _p('/aaa/lib/b.dart'); | 141 String b = _p('/aaa/lib/b.dart'); |
| 156 provider.newFile( | 142 provider.newFile(a, r''' |
| 157 a, | |
| 158 r''' | |
| 159 class A {} | 143 class A {} |
| 160 '''); | 144 '''); |
| 161 provider.newFile( | 145 provider.newFile(b, r''' |
| 162 b, | |
| 163 r''' | |
| 164 export 'a.dart'; | 146 export 'a.dart'; |
| 165 class B {} | 147 class B {} |
| 166 '''); | 148 '''); |
| 167 | 149 |
| 168 // Initial exported declarations. | 150 // Initial exported declarations. |
| 169 _assertExportedTopLevelDeclarations(b, ['A', 'B']); | 151 _assertExportedTopLevelDeclarations(b, ['A', 'B']); |
| 170 | 152 |
| 171 // Update a.dart, so a.dart and b.dart exported declarations are flushed. | 153 // Update a.dart, so a.dart and b.dart exported declarations are flushed. |
| 172 provider.newFile(a, 'class A {} class A2 {}'); | 154 provider.newFile(a, 'class A {} class A2 {}'); |
| 173 fileSystemState.getFileForPath(a).refresh(); | 155 fileSystemState.getFileForPath(a).refresh(); |
| 174 _assertExportedTopLevelDeclarations(b, ['A', 'A2', 'B']); | 156 _assertExportedTopLevelDeclarations(b, ['A', 'A2', 'B']); |
| 175 } | 157 } |
| 176 | 158 |
| 177 test_exportedTopLevelDeclarations_export_hide() { | 159 test_exportedTopLevelDeclarations_export_hide() { |
| 178 String a = _p('/aaa/lib/a.dart'); | 160 String a = _p('/aaa/lib/a.dart'); |
| 179 String b = _p('/aaa/lib/b.dart'); | 161 String b = _p('/aaa/lib/b.dart'); |
| 180 provider.newFile( | 162 provider.newFile(a, r''' |
| 181 a, | |
| 182 r''' | |
| 183 class A1 {} | 163 class A1 {} |
| 184 class A2 {} | 164 class A2 {} |
| 185 class A3 {} | 165 class A3 {} |
| 186 '''); | 166 '''); |
| 187 provider.newFile( | 167 provider.newFile(b, r''' |
| 188 b, | |
| 189 r''' | |
| 190 export 'a.dart' hide A2; | 168 export 'a.dart' hide A2; |
| 191 class B {} | 169 class B {} |
| 192 '''); | 170 '''); |
| 193 _assertExportedTopLevelDeclarations(b, ['A1', 'A3', 'B']); | 171 _assertExportedTopLevelDeclarations(b, ['A1', 'A3', 'B']); |
| 194 } | 172 } |
| 195 | 173 |
| 196 test_exportedTopLevelDeclarations_export_preferLocal() { | 174 test_exportedTopLevelDeclarations_export_preferLocal() { |
| 197 String a = _p('/aaa/lib/a.dart'); | 175 String a = _p('/aaa/lib/a.dart'); |
| 198 String b = _p('/aaa/lib/b.dart'); | 176 String b = _p('/aaa/lib/b.dart'); |
| 199 provider.newFile( | 177 provider.newFile(a, r''' |
| 200 a, | |
| 201 r''' | |
| 202 class V {} | 178 class V {} |
| 203 '''); | 179 '''); |
| 204 provider.newFile( | 180 provider.newFile(b, r''' |
| 205 b, | |
| 206 r''' | |
| 207 export 'a.dart'; | 181 export 'a.dart'; |
| 208 int V; | 182 int V; |
| 209 '''); | 183 '''); |
| 210 FileState file = fileSystemState.getFileForPath(b); | 184 FileState file = fileSystemState.getFileForPath(b); |
| 211 Map<String, TopLevelDeclaration> declarations = | 185 Map<String, TopLevelDeclaration> declarations = |
| 212 file.exportedTopLevelDeclarations; | 186 file.exportedTopLevelDeclarations; |
| 213 expect(declarations.keys, unorderedEquals(['V'])); | 187 expect(declarations.keys, unorderedEquals(['V'])); |
| 214 expect(declarations['V'].kind, TopLevelDeclarationKind.variable); | 188 expect(declarations['V'].kind, TopLevelDeclarationKind.variable); |
| 215 } | 189 } |
| 216 | 190 |
| 217 test_exportedTopLevelDeclarations_export_show() { | 191 test_exportedTopLevelDeclarations_export_show() { |
| 218 String a = _p('/aaa/lib/a.dart'); | 192 String a = _p('/aaa/lib/a.dart'); |
| 219 String b = _p('/aaa/lib/b.dart'); | 193 String b = _p('/aaa/lib/b.dart'); |
| 220 provider.newFile( | 194 provider.newFile(a, r''' |
| 221 a, | |
| 222 r''' | |
| 223 class A1 {} | 195 class A1 {} |
| 224 class A2 {} | 196 class A2 {} |
| 225 '''); | 197 '''); |
| 226 provider.newFile( | 198 provider.newFile(b, r''' |
| 227 b, | |
| 228 r''' | |
| 229 export 'a.dart' show A2; | 199 export 'a.dart' show A2; |
| 230 class B {} | 200 class B {} |
| 231 '''); | 201 '''); |
| 232 _assertExportedTopLevelDeclarations(b, ['A2', 'B']); | 202 _assertExportedTopLevelDeclarations(b, ['A2', 'B']); |
| 233 } | 203 } |
| 234 | 204 |
| 235 test_exportedTopLevelDeclarations_export_show2() { | 205 test_exportedTopLevelDeclarations_export_show2() { |
| 236 String a = _p('/aaa/lib/a.dart'); | 206 String a = _p('/aaa/lib/a.dart'); |
| 237 String b = _p('/aaa/lib/b.dart'); | 207 String b = _p('/aaa/lib/b.dart'); |
| 238 String c = _p('/aaa/lib/c.dart'); | 208 String c = _p('/aaa/lib/c.dart'); |
| 239 String d = _p('/aaa/lib/d.dart'); | 209 String d = _p('/aaa/lib/d.dart'); |
| 240 provider.newFile( | 210 provider.newFile(a, r''' |
| 241 a, | |
| 242 r''' | |
| 243 export 'b.dart' show Foo; | 211 export 'b.dart' show Foo; |
| 244 export 'c.dart' show Bar; | 212 export 'c.dart' show Bar; |
| 245 '''); | 213 '''); |
| 246 provider.newFile( | 214 provider.newFile(b, r''' |
| 247 b, | |
| 248 r''' | |
| 249 export 'd.dart'; | 215 export 'd.dart'; |
| 250 '''); | 216 '''); |
| 251 provider.newFile( | 217 provider.newFile(c, r''' |
| 252 c, | |
| 253 r''' | |
| 254 export 'd.dart'; | 218 export 'd.dart'; |
| 255 '''); | 219 '''); |
| 256 provider.newFile( | 220 provider.newFile(d, r''' |
| 257 d, | |
| 258 r''' | |
| 259 class Foo {} | 221 class Foo {} |
| 260 class Bar {} | 222 class Bar {} |
| 261 '''); | 223 '''); |
| 262 _assertExportedTopLevelDeclarations(a, ['Foo', 'Bar']); | 224 _assertExportedTopLevelDeclarations(a, ['Foo', 'Bar']); |
| 263 } | 225 } |
| 264 | 226 |
| 265 test_exportedTopLevelDeclarations_import() { | 227 test_exportedTopLevelDeclarations_import() { |
| 266 String a = _p('/aaa/lib/a.dart'); | 228 String a = _p('/aaa/lib/a.dart'); |
| 267 String b = _p('/aaa/lib/b.dart'); | 229 String b = _p('/aaa/lib/b.dart'); |
| 268 provider.newFile( | 230 provider.newFile(a, r''' |
| 269 a, | |
| 270 r''' | |
| 271 class A {} | 231 class A {} |
| 272 '''); | 232 '''); |
| 273 provider.newFile( | 233 provider.newFile(b, r''' |
| 274 b, | |
| 275 r''' | |
| 276 import 'a.dart'; | 234 import 'a.dart'; |
| 277 class B {} | 235 class B {} |
| 278 '''); | 236 '''); |
| 279 _assertExportedTopLevelDeclarations(b, ['B']); | 237 _assertExportedTopLevelDeclarations(b, ['B']); |
| 280 } | 238 } |
| 281 | 239 |
| 282 test_exportedTopLevelDeclarations_parts() { | 240 test_exportedTopLevelDeclarations_parts() { |
| 283 String a = _p('/aaa/lib/a.dart'); | 241 String a = _p('/aaa/lib/a.dart'); |
| 284 String a2 = _p('/aaa/lib/a2.dart'); | 242 String a2 = _p('/aaa/lib/a2.dart'); |
| 285 provider.newFile( | 243 provider.newFile(a, r''' |
| 286 a, | |
| 287 r''' | |
| 288 library lib; | 244 library lib; |
| 289 part 'a2.dart'; | 245 part 'a2.dart'; |
| 290 class A1 {} | 246 class A1 {} |
| 291 '''); | 247 '''); |
| 292 provider.newFile( | 248 provider.newFile(a2, r''' |
| 293 a2, | |
| 294 r''' | |
| 295 part of lib; | 249 part of lib; |
| 296 class A2 {} | 250 class A2 {} |
| 297 '''); | 251 '''); |
| 298 _assertExportedTopLevelDeclarations(a, ['A1', 'A2']); | 252 _assertExportedTopLevelDeclarations(a, ['A1', 'A2']); |
| 299 } | 253 } |
| 300 | 254 |
| 301 test_getFileForPath_doesNotExist() { | 255 test_getFileForPath_doesNotExist() { |
| 302 String path = _p('/aaa/lib/a.dart'); | 256 String path = _p('/aaa/lib/a.dart'); |
| 303 FileState file = fileSystemState.getFileForPath(path); | 257 FileState file = fileSystemState.getFileForPath(path); |
| 304 expect(file.path, path); | 258 expect(file.path, path); |
| 305 expect(file.uri, Uri.parse('package:aaa/a.dart')); | 259 expect(file.uri, Uri.parse('package:aaa/a.dart')); |
| 306 expect(file.content, ''); | 260 expect(file.content, ''); |
| 307 expect(file.contentHash, _md5('')); | 261 expect(file.contentHash, _md5('')); |
| 308 expect(_excludeSdk(file.importedFiles), isEmpty); | 262 expect(_excludeSdk(file.importedFiles), isEmpty); |
| 309 expect(file.exportedFiles, isEmpty); | 263 expect(file.exportedFiles, isEmpty); |
| 310 expect(file.partedFiles, isEmpty); | 264 expect(file.partedFiles, isEmpty); |
| 311 expect(_excludeSdk(file.directReferencedFiles), isEmpty); | 265 expect(_excludeSdk(file.directReferencedFiles), isEmpty); |
| 312 expect(file.isPart, isFalse); | 266 expect(file.isPart, isFalse); |
| 313 expect(file.library, isNull); | 267 expect(file.library, isNull); |
| 314 expect(file.unlinked, isNotNull); | 268 expect(file.unlinked, isNotNull); |
| 315 expect(file.unlinked.classes, isEmpty); | 269 expect(file.unlinked.classes, isEmpty); |
| 316 } | 270 } |
| 317 | 271 |
| 318 test_getFileForPath_emptyUri() { | 272 test_getFileForPath_emptyUri() { |
| 319 String path = _p('/test.dart'); | 273 String path = _p('/test.dart'); |
| 320 provider.newFile( | 274 provider.newFile(path, r''' |
| 321 path, | |
| 322 r''' | |
| 323 import ''; | 275 import ''; |
| 324 export ''; | 276 export ''; |
| 325 part ''; | 277 part ''; |
| 326 '''); | 278 '''); |
| 327 | 279 |
| 328 FileState file = fileSystemState.getFileForPath(path); | 280 FileState file = fileSystemState.getFileForPath(path); |
| 329 _assertIsUnresolvedFile(file.importedFiles[0]); | 281 _assertIsUnresolvedFile(file.importedFiles[0]); |
| 330 _assertIsUnresolvedFile(file.exportedFiles[0]); | 282 _assertIsUnresolvedFile(file.exportedFiles[0]); |
| 331 _assertIsUnresolvedFile(file.partedFiles[0]); | 283 _assertIsUnresolvedFile(file.partedFiles[0]); |
| 332 } | 284 } |
| 333 | 285 |
| 334 test_getFileForPath_hasLibraryDirective_hasPartOfDirective() { | 286 test_getFileForPath_hasLibraryDirective_hasPartOfDirective() { |
| 335 String a = _p('/test/lib/a.dart'); | 287 String a = _p('/test/lib/a.dart'); |
| 336 provider.newFile( | 288 provider.newFile(a, r''' |
| 337 a, | |
| 338 r''' | |
| 339 library L; | 289 library L; |
| 340 part of L; | 290 part of L; |
| 341 '''); | 291 '''); |
| 342 FileState file = fileSystemState.getFileForPath(a); | 292 FileState file = fileSystemState.getFileForPath(a); |
| 343 expect(file.isPart, isFalse); | 293 expect(file.isPart, isFalse); |
| 344 } | 294 } |
| 345 | 295 |
| 346 test_getFileForPath_invalidUri() { | 296 test_getFileForPath_invalidUri() { |
| 347 String a = _p('/aaa/lib/a.dart'); | 297 String a = _p('/aaa/lib/a.dart'); |
| 348 String a1 = _p('/aaa/lib/a1.dart'); | 298 String a1 = _p('/aaa/lib/a1.dart'); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 384 |
| 435 expect(fileSystemState.getFilesForPath(a1), [file]); | 385 expect(fileSystemState.getFilesForPath(a1), [file]); |
| 436 } | 386 } |
| 437 | 387 |
| 438 test_getFileForPath_onlyDartFiles() { | 388 test_getFileForPath_onlyDartFiles() { |
| 439 String not_dart = _p('/test/lib/not_dart.txt'); | 389 String not_dart = _p('/test/lib/not_dart.txt'); |
| 440 String a = _p('/test/lib/a.dart'); | 390 String a = _p('/test/lib/a.dart'); |
| 441 String b = _p('/test/lib/b.dart'); | 391 String b = _p('/test/lib/b.dart'); |
| 442 String c = _p('/test/lib/c.dart'); | 392 String c = _p('/test/lib/c.dart'); |
| 443 String d = _p('/test/lib/d.dart'); | 393 String d = _p('/test/lib/d.dart'); |
| 444 provider.newFile( | 394 provider.newFile(a, r''' |
| 445 a, | |
| 446 r''' | |
| 447 library lib; | 395 library lib; |
| 448 import 'dart:math'; | 396 import 'dart:math'; |
| 449 import 'b.dart'; | 397 import 'b.dart'; |
| 450 import 'not_dart.txt'; | 398 import 'not_dart.txt'; |
| 451 export 'c.dart'; | 399 export 'c.dart'; |
| 452 export 'not_dart.txt'; | 400 export 'not_dart.txt'; |
| 453 part 'd.dart'; | 401 part 'd.dart'; |
| 454 part 'not_dart.txt'; | 402 part 'not_dart.txt'; |
| 455 '''); | 403 '''); |
| 456 FileState file = fileSystemState.getFileForPath(a); | 404 FileState file = fileSystemState.getFileForPath(a); |
| 457 expect(_excludeSdk(file.importedFiles).map((f) => f.path), | 405 expect(_excludeSdk(file.importedFiles).map((f) => f.path), |
| 458 unorderedEquals([b, not_dart])); | 406 unorderedEquals([b, not_dart])); |
| 459 expect( | 407 expect( |
| 460 file.exportedFiles.map((f) => f.path), unorderedEquals([c, not_dart])); | 408 file.exportedFiles.map((f) => f.path), unorderedEquals([c, not_dart])); |
| 461 expect(file.partedFiles.map((f) => f.path), unorderedEquals([d, not_dart])); | 409 expect(file.partedFiles.map((f) => f.path), unorderedEquals([d, not_dart])); |
| 462 expect(_excludeSdk(fileSystemState.knownFilePaths), | 410 expect(_excludeSdk(fileSystemState.knownFilePaths), |
| 463 unorderedEquals([a, b, c, d, not_dart])); | 411 unorderedEquals([a, b, c, d, not_dart])); |
| 464 } | 412 } |
| 465 | 413 |
| 466 test_getFileForPath_part() { | 414 test_getFileForPath_part() { |
| 467 String a1 = _p('/aaa/lib/a1.dart'); | 415 String a1 = _p('/aaa/lib/a1.dart'); |
| 468 String a2 = _p('/aaa/lib/a2.dart'); | 416 String a2 = _p('/aaa/lib/a2.dart'); |
| 469 provider.newFile( | 417 provider.newFile(a1, r''' |
| 470 a1, | |
| 471 r''' | |
| 472 library a1; | 418 library a1; |
| 473 part 'a2.dart'; | 419 part 'a2.dart'; |
| 474 '''); | 420 '''); |
| 475 provider.newFile( | 421 provider.newFile(a2, r''' |
| 476 a2, | |
| 477 r''' | |
| 478 part of a1; | 422 part of a1; |
| 479 class A2 {} | 423 class A2 {} |
| 480 '''); | 424 '''); |
| 481 | 425 |
| 482 FileState file_a2 = fileSystemState.getFileForPath(a2); | 426 FileState file_a2 = fileSystemState.getFileForPath(a2); |
| 483 expect(file_a2.path, a2); | 427 expect(file_a2.path, a2); |
| 484 expect(file_a2.uri, Uri.parse('package:aaa/a2.dart')); | 428 expect(file_a2.uri, Uri.parse('package:aaa/a2.dart')); |
| 485 | 429 |
| 486 expect(file_a2.unlinked, isNotNull); | 430 expect(file_a2.unlinked, isNotNull); |
| 487 expect(file_a2.unlinked.classes, hasLength(1)); | 431 expect(file_a2.unlinked.classes, hasLength(1)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 502 expect(file_a1.partedFiles[0], same(file_a2)); | 446 expect(file_a1.partedFiles[0], same(file_a2)); |
| 503 expect( | 447 expect( |
| 504 _excludeSdk(file_a1.directReferencedFiles), unorderedEquals([file_a2])); | 448 _excludeSdk(file_a1.directReferencedFiles), unorderedEquals([file_a2])); |
| 505 | 449 |
| 506 // Now the part knows its library. | 450 // Now the part knows its library. |
| 507 expect(file_a2.library, same(file_a1)); | 451 expect(file_a2.library, same(file_a1)); |
| 508 | 452 |
| 509 // Now update the library, and refresh its file. | 453 // Now update the library, and refresh its file. |
| 510 // The 'a2.dart' is not referenced anymore. | 454 // The 'a2.dart' is not referenced anymore. |
| 511 // So the part file does not have the library anymore. | 455 // So the part file does not have the library anymore. |
| 512 provider.newFile( | 456 provider.newFile(a1, r''' |
| 513 a1, | |
| 514 r''' | |
| 515 library a1; | 457 library a1; |
| 516 part 'not-a2.dart'; | 458 part 'not-a2.dart'; |
| 517 '''); | 459 '''); |
| 518 file_a1.refresh(); | 460 file_a1.refresh(); |
| 519 expect(file_a2.library, isNull); | 461 expect(file_a2.library, isNull); |
| 520 } | 462 } |
| 521 | 463 |
| 522 test_getFileForPath_samePath() { | 464 test_getFileForPath_samePath() { |
| 523 String path = _p('/aaa/lib/a.dart'); | 465 String path = _p('/aaa/lib/a.dart'); |
| 524 FileState file1 = fileSystemState.getFileForPath(path); | 466 FileState file1 = fileSystemState.getFileForPath(path); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 expect(fileSystemState.hasUri(templatePath), isFalse); | 504 expect(fileSystemState.hasUri(templatePath), isFalse); |
| 563 expect(fileSystemState.hasUri(generatedPath), isTrue); | 505 expect(fileSystemState.hasUri(generatedPath), isTrue); |
| 564 } | 506 } |
| 565 | 507 |
| 566 test_knownFilesSetChanges() async { | 508 test_knownFilesSetChanges() async { |
| 567 fileSystemState.test.knownFilesDelay = new Duration(milliseconds: 5); | 509 fileSystemState.test.knownFilesDelay = new Duration(milliseconds: 5); |
| 568 | 510 |
| 569 String a = _p('/test/lib/a.dart'); | 511 String a = _p('/test/lib/a.dart'); |
| 570 String b = _p('/test/lib/b.dart'); | 512 String b = _p('/test/lib/b.dart'); |
| 571 String c = _p('/test/lib/c.dart'); | 513 String c = _p('/test/lib/c.dart'); |
| 572 provider.newFile( | 514 provider.newFile(a, r''' |
| 573 a, | |
| 574 r''' | |
| 575 import 'b.dart'; | 515 import 'b.dart'; |
| 576 '''); | 516 '''); |
| 577 provider.newFile(b, ''); | 517 provider.newFile(b, ''); |
| 578 provider.newFile(c, ''); | 518 provider.newFile(c, ''); |
| 579 | 519 |
| 580 Stream<KnownFilesSetChange> broadcastEvents = | 520 Stream<KnownFilesSetChange> broadcastEvents = |
| 581 fileSystemState.knownFilesSetChanges.asBroadcastStream(); | 521 fileSystemState.knownFilesSetChanges.asBroadcastStream(); |
| 582 | 522 |
| 583 FileState file = fileSystemState.getFileForPath(a); | 523 FileState file = fileSystemState.getFileForPath(a); |
| 584 { | 524 { |
| 585 KnownFilesSetChange event = await broadcastEvents.first; | 525 KnownFilesSetChange event = await broadcastEvents.first; |
| 586 expect(event.added, contains(a)); | 526 expect(event.added, contains(a)); |
| 587 expect(event.added, contains(b)); | 527 expect(event.added, contains(b)); |
| 588 expect(event.removed, isEmpty); | 528 expect(event.removed, isEmpty); |
| 589 } | 529 } |
| 590 | 530 |
| 591 // Update a.dart to import c.dart and refresh. | 531 // Update a.dart to import c.dart and refresh. |
| 592 // So, c.dart should be reported as added in the next change event. | 532 // So, c.dart should be reported as added in the next change event. |
| 593 provider.newFile( | 533 provider.newFile(a, r''' |
| 594 a, | |
| 595 r''' | |
| 596 import 'b.dart'; | 534 import 'b.dart'; |
| 597 import 'c.dart'; | 535 import 'c.dart'; |
| 598 '''); | 536 '''); |
| 599 file.refresh(); | 537 file.refresh(); |
| 600 { | 538 { |
| 601 KnownFilesSetChange event = await broadcastEvents.first; | 539 KnownFilesSetChange event = await broadcastEvents.first; |
| 602 expect(event.added, contains(c)); | 540 expect(event.added, contains(c)); |
| 603 expect(event.removed, isEmpty); | 541 expect(event.removed, isEmpty); |
| 604 } | 542 } |
| 605 } | 543 } |
| 606 | 544 |
| 607 test_referencedNames() { | 545 test_referencedNames() { |
| 608 String path = _p('/aaa/lib/a.dart'); | 546 String path = _p('/aaa/lib/a.dart'); |
| 609 provider.newFile( | 547 provider.newFile(path, r''' |
| 610 path, | |
| 611 r''' | |
| 612 A foo(B p) { | 548 A foo(B p) { |
| 613 foo(null); | 549 foo(null); |
| 614 C c = new C(p); | 550 C c = new C(p); |
| 615 return c; | 551 return c; |
| 616 } | 552 } |
| 617 '''); | 553 '''); |
| 618 FileState file = fileSystemState.getFileForPath(path); | 554 FileState file = fileSystemState.getFileForPath(path); |
| 619 expect(file.referencedNames, unorderedEquals(['A', 'B', 'C'])); | 555 expect(file.referencedNames, unorderedEquals(['A', 'B', 'C'])); |
| 620 } | 556 } |
| 621 | 557 |
| 622 test_refresh_differentApiSignature() { | 558 test_refresh_differentApiSignature() { |
| 623 String path = _p('/aaa/lib/a.dart'); | 559 String path = _p('/aaa/lib/a.dart'); |
| 624 provider.newFile( | 560 provider.newFile(path, r''' |
| 625 path, | |
| 626 r''' | |
| 627 class A {} | 561 class A {} |
| 628 '''); | 562 '''); |
| 629 FileState file = fileSystemState.getFileForPath(path); | 563 FileState file = fileSystemState.getFileForPath(path); |
| 630 expect(file.unlinked.classes[0].name, 'A'); | 564 expect(file.unlinked.classes[0].name, 'A'); |
| 631 List<int> signature = file.apiSignature; | 565 List<int> signature = file.apiSignature; |
| 632 | 566 |
| 633 // Update the resource and refresh the file state. | 567 // Update the resource and refresh the file state. |
| 634 provider.newFile( | 568 provider.newFile(path, r''' |
| 635 path, | |
| 636 r''' | |
| 637 class B {} | 569 class B {} |
| 638 '''); | 570 '''); |
| 639 bool apiSignatureChanged = file.refresh(); | 571 bool apiSignatureChanged = file.refresh(); |
| 640 expect(apiSignatureChanged, isTrue); | 572 expect(apiSignatureChanged, isTrue); |
| 641 | 573 |
| 642 expect(file.unlinked.classes[0].name, 'B'); | 574 expect(file.unlinked.classes[0].name, 'B'); |
| 643 expect(file.apiSignature, isNot(signature)); | 575 expect(file.apiSignature, isNot(signature)); |
| 644 } | 576 } |
| 645 | 577 |
| 646 test_refresh_sameApiSignature() { | 578 test_refresh_sameApiSignature() { |
| 647 String path = _p('/aaa/lib/a.dart'); | 579 String path = _p('/aaa/lib/a.dart'); |
| 648 provider.newFile( | 580 provider.newFile(path, r''' |
| 649 path, | |
| 650 r''' | |
| 651 class C { | 581 class C { |
| 652 foo() { | 582 foo() { |
| 653 print(111); | 583 print(111); |
| 654 } | 584 } |
| 655 } | 585 } |
| 656 '''); | 586 '''); |
| 657 FileState file = fileSystemState.getFileForPath(path); | 587 FileState file = fileSystemState.getFileForPath(path); |
| 658 List<int> signature = file.apiSignature; | 588 List<int> signature = file.apiSignature; |
| 659 | 589 |
| 660 // Update the resource and refresh the file state. | 590 // Update the resource and refresh the file state. |
| 661 provider.newFile( | 591 provider.newFile(path, r''' |
| 662 path, | |
| 663 r''' | |
| 664 class C { | 592 class C { |
| 665 foo() { | 593 foo() { |
| 666 print(222); | 594 print(222); |
| 667 } | 595 } |
| 668 } | 596 } |
| 669 '''); | 597 '''); |
| 670 bool apiSignatureChanged = file.refresh(); | 598 bool apiSignatureChanged = file.refresh(); |
| 671 expect(apiSignatureChanged, isFalse); | 599 expect(apiSignatureChanged, isFalse); |
| 672 | 600 |
| 673 expect(file.apiSignature, signature); | 601 expect(file.apiSignature, signature); |
| 674 } | 602 } |
| 675 | 603 |
| 676 test_subtypedNames() { | 604 test_subtypedNames() { |
| 677 String path = _p('/test.dart'); | 605 String path = _p('/test.dart'); |
| 678 provider.newFile( | 606 provider.newFile(path, r''' |
| 679 path, | |
| 680 r''' | |
| 681 class X extends A {} | 607 class X extends A {} |
| 682 class Y extends A with B {} | 608 class Y extends A with B {} |
| 683 class Z implements C, D {} | 609 class Z implements C, D {} |
| 684 '''); | 610 '''); |
| 685 FileState file = fileSystemState.getFileForPath(path); | 611 FileState file = fileSystemState.getFileForPath(path); |
| 686 expect(file.referencedNames, unorderedEquals(['A', 'B', 'C', 'D'])); | 612 expect(file.referencedNames, unorderedEquals(['A', 'B', 'C', 'D'])); |
| 687 } | 613 } |
| 688 | 614 |
| 689 test_topLevelDeclarations() { | 615 test_topLevelDeclarations() { |
| 690 String path = _p('/aaa/lib/a.dart'); | 616 String path = _p('/aaa/lib/a.dart'); |
| 691 provider.newFile( | 617 provider.newFile(path, r''' |
| 692 path, | |
| 693 r''' | |
| 694 class C {} | 618 class C {} |
| 695 typedef F(); | 619 typedef F(); |
| 696 enum E {E1, E2} | 620 enum E {E1, E2} |
| 697 void f() {} | 621 void f() {} |
| 698 var V1; | 622 var V1; |
| 699 get V2 => null; | 623 get V2 => null; |
| 700 set V3(_) {} | 624 set V3(_) {} |
| 701 get V4 => null; | 625 get V4 => null; |
| 702 set V4(_) {} | 626 set V4(_) {} |
| 703 | 627 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 String _p(String path) => provider.convertPath(path); | 810 String _p(String path) => provider.convertPath(path); |
| 887 | 811 |
| 888 static String _md5(String content) { | 812 static String _md5(String content) { |
| 889 return hex.encode(md5.convert(UTF8.encode(content)).bytes); | 813 return hex.encode(md5.convert(UTF8.encode(content)).bytes); |
| 890 } | 814 } |
| 891 } | 815 } |
| 892 | 816 |
| 893 class _GeneratedUriResolverMock extends TypedMock implements UriResolver {} | 817 class _GeneratedUriResolverMock extends TypedMock implements UriResolver {} |
| 894 | 818 |
| 895 class _SourceMock extends TypedMock implements Source {} | 819 class _SourceMock extends TypedMock implements Source {} |
| OLD | NEW |