| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 'package:analyzer/dart/ast/ast.dart' as analyzer; | 5 import 'package:analyzer/dart/ast/ast.dart' as analyzer; |
| 6 import 'package:analyzer/dart/element/element.dart' as analyzer; | 6 import 'package:analyzer/dart/element/element.dart' as analyzer; |
| 7 import 'package:analyzer/dart/element/type.dart' as analyzer; | 7 import 'package:analyzer/dart/element/type.dart' as analyzer; |
| 8 import 'package:analyzer/error/error.dart' as analyzer; | 8 import 'package:analyzer/error/error.dart' as analyzer; |
| 9 import 'package:analyzer/exception/exception.dart' as analyzer; | 9 import 'package:analyzer/exception/exception.dart' as analyzer; |
| 10 import 'package:analyzer/source/error_processor.dart' as analyzer; | 10 import 'package:analyzer/source/error_processor.dart' as analyzer; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 ]; | 174 ]; |
| 175 | 175 |
| 176 List<plugin.AnalysisError> pluginErrors = | 176 List<plugin.AnalysisError> pluginErrors = |
| 177 converter.convertAnalysisErrors(analyzerErrors, options: options); | 177 converter.convertAnalysisErrors(analyzerErrors, options: options); |
| 178 expect(pluginErrors, hasLength(analyzerErrors.length)); | 178 expect(pluginErrors, hasLength(analyzerErrors.length)); |
| 179 assertError(pluginErrors[0], analyzerErrors[0], severity: severity); | 179 assertError(pluginErrors[0], analyzerErrors[0], severity: severity); |
| 180 assertError(pluginErrors[1], analyzerErrors[1], severity: severity); | 180 assertError(pluginErrors[1], analyzerErrors[1], severity: severity); |
| 181 } | 181 } |
| 182 | 182 |
| 183 test_convertElement_class() async { | 183 test_convertElement_class() async { |
| 184 analyzer.Source source = addSource( | 184 analyzer.Source source = addSource(testFile, ''' |
| 185 testFile, | |
| 186 ''' | |
| 187 @deprecated | 185 @deprecated |
| 188 abstract class _A {} | 186 abstract class _A {} |
| 189 class B<K, V> {}'''); | 187 class B<K, V> {}'''); |
| 190 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); | 188 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 191 { | 189 { |
| 192 analyzer.ClassElement engineElement = findElementInUnit(unit, '_A'); | 190 analyzer.ClassElement engineElement = findElementInUnit(unit, '_A'); |
| 193 // create notification Element | 191 // create notification Element |
| 194 plugin.Element element = converter.convertElement(engineElement); | 192 plugin.Element element = converter.convertElement(engineElement); |
| 195 expect(element.kind, plugin.ElementKind.CLASS); | 193 expect(element.kind, plugin.ElementKind.CLASS); |
| 196 expect(element.name, '_A'); | 194 expect(element.name, '_A'); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 215 // create notification Element | 213 // create notification Element |
| 216 plugin.Element element = converter.convertElement(engineElement); | 214 plugin.Element element = converter.convertElement(engineElement); |
| 217 expect(element.kind, plugin.ElementKind.CLASS); | 215 expect(element.kind, plugin.ElementKind.CLASS); |
| 218 expect(element.name, 'B'); | 216 expect(element.name, 'B'); |
| 219 expect(element.typeParameters, '<K, V>'); | 217 expect(element.typeParameters, '<K, V>'); |
| 220 expect(element.flags, 0); | 218 expect(element.flags, 0); |
| 221 } | 219 } |
| 222 } | 220 } |
| 223 | 221 |
| 224 test_convertElement_constructor() async { | 222 test_convertElement_constructor() async { |
| 225 analyzer.Source source = addSource( | 223 analyzer.Source source = addSource(testFile, ''' |
| 226 testFile, | |
| 227 ''' | |
| 228 class A { | 224 class A { |
| 229 const A.myConstructor(int a, [String b]); | 225 const A.myConstructor(int a, [String b]); |
| 230 }'''); | 226 }'''); |
| 231 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); | 227 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 232 analyzer.ConstructorElement engineElement = | 228 analyzer.ConstructorElement engineElement = |
| 233 findElementInUnit(unit, 'myConstructor'); | 229 findElementInUnit(unit, 'myConstructor'); |
| 234 // create notification Element | 230 // create notification Element |
| 235 plugin.Element element = converter.convertElement(engineElement); | 231 plugin.Element element = converter.convertElement(engineElement); |
| 236 expect(element.kind, plugin.ElementKind.CONSTRUCTOR); | 232 expect(element.kind, plugin.ElementKind.CONSTRUCTOR); |
| 237 expect(element.name, 'myConstructor'); | 233 expect(element.name, 'myConstructor'); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 255 plugin.Element element = converter.convertElement(engineElement); | 251 plugin.Element element = converter.convertElement(engineElement); |
| 256 expect(element.kind, plugin.ElementKind.UNKNOWN); | 252 expect(element.kind, plugin.ElementKind.UNKNOWN); |
| 257 expect(element.name, 'dynamic'); | 253 expect(element.name, 'dynamic'); |
| 258 expect(element.location, isNull); | 254 expect(element.location, isNull); |
| 259 expect(element.parameters, isNull); | 255 expect(element.parameters, isNull); |
| 260 expect(element.returnType, isNull); | 256 expect(element.returnType, isNull); |
| 261 expect(element.flags, 0); | 257 expect(element.flags, 0); |
| 262 } | 258 } |
| 263 | 259 |
| 264 test_convertElement_enum() async { | 260 test_convertElement_enum() async { |
| 265 analyzer.Source source = addSource( | 261 analyzer.Source source = addSource(testFile, ''' |
| 266 testFile, | |
| 267 ''' | |
| 268 @deprecated | 262 @deprecated |
| 269 enum _E1 { one, two } | 263 enum _E1 { one, two } |
| 270 enum E2 { three, four }'''); | 264 enum E2 { three, four }'''); |
| 271 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); | 265 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 272 { | 266 { |
| 273 analyzer.ClassElement engineElement = findElementInUnit(unit, '_E1'); | 267 analyzer.ClassElement engineElement = findElementInUnit(unit, '_E1'); |
| 274 expect(engineElement.isDeprecated, isTrue); | 268 expect(engineElement.isDeprecated, isTrue); |
| 275 // create notification Element | 269 // create notification Element |
| 276 plugin.Element element = converter.convertElement(engineElement); | 270 plugin.Element element = converter.convertElement(engineElement); |
| 277 expect(element.kind, plugin.ElementKind.ENUM); | 271 expect(element.kind, plugin.ElementKind.ENUM); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 296 // create notification Element | 290 // create notification Element |
| 297 plugin.Element element = converter.convertElement(engineElement); | 291 plugin.Element element = converter.convertElement(engineElement); |
| 298 expect(element.kind, plugin.ElementKind.ENUM); | 292 expect(element.kind, plugin.ElementKind.ENUM); |
| 299 expect(element.name, 'E2'); | 293 expect(element.name, 'E2'); |
| 300 expect(element.typeParameters, isNull); | 294 expect(element.typeParameters, isNull); |
| 301 expect(element.flags, 0); | 295 expect(element.flags, 0); |
| 302 } | 296 } |
| 303 } | 297 } |
| 304 | 298 |
| 305 test_convertElement_enumConstant() async { | 299 test_convertElement_enumConstant() async { |
| 306 analyzer.Source source = addSource( | 300 analyzer.Source source = addSource(testFile, ''' |
| 307 testFile, | |
| 308 ''' | |
| 309 @deprecated | 301 @deprecated |
| 310 enum _E1 { one, two } | 302 enum _E1 { one, two } |
| 311 enum E2 { three, four }'''); | 303 enum E2 { three, four }'''); |
| 312 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); | 304 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 313 { | 305 { |
| 314 analyzer.FieldElement engineElement = findElementInUnit(unit, 'one'); | 306 analyzer.FieldElement engineElement = findElementInUnit(unit, 'one'); |
| 315 // create notification Element | 307 // create notification Element |
| 316 plugin.Element element = converter.convertElement(engineElement); | 308 plugin.Element element = converter.convertElement(engineElement); |
| 317 expect(element.kind, plugin.ElementKind.ENUM_CONSTANT); | 309 expect(element.kind, plugin.ElementKind.ENUM_CONSTANT); |
| 318 expect(element.name, 'one'); | 310 expect(element.name, 'one'); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 expect(location.startColumn, 0); | 381 expect(location.startColumn, 0); |
| 390 } | 382 } |
| 391 expect(element.parameters, isNull); | 383 expect(element.parameters, isNull); |
| 392 expect(element.returnType, 'List<E2>'); | 384 expect(element.returnType, 'List<E2>'); |
| 393 expect(element.flags, | 385 expect(element.flags, |
| 394 plugin.Element.FLAG_CONST | plugin.Element.FLAG_STATIC); | 386 plugin.Element.FLAG_CONST | plugin.Element.FLAG_STATIC); |
| 395 } | 387 } |
| 396 } | 388 } |
| 397 | 389 |
| 398 test_convertElement_field() async { | 390 test_convertElement_field() async { |
| 399 analyzer.Source source = addSource( | 391 analyzer.Source source = addSource(testFile, ''' |
| 400 testFile, | |
| 401 ''' | |
| 402 class A { | 392 class A { |
| 403 static const myField = 42; | 393 static const myField = 42; |
| 404 }'''); | 394 }'''); |
| 405 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); | 395 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 406 analyzer.FieldElement engineElement = findElementInUnit(unit, 'myField'); | 396 analyzer.FieldElement engineElement = findElementInUnit(unit, 'myField'); |
| 407 // create notification Element | 397 // create notification Element |
| 408 plugin.Element element = converter.convertElement(engineElement); | 398 plugin.Element element = converter.convertElement(engineElement); |
| 409 expect(element.kind, plugin.ElementKind.FIELD); | 399 expect(element.kind, plugin.ElementKind.FIELD); |
| 410 expect(element.name, 'myField'); | 400 expect(element.name, 'myField'); |
| 411 { | 401 { |
| 412 plugin.Location location = element.location; | 402 plugin.Location location = element.location; |
| 413 expect(location.file, testFile); | 403 expect(location.file, testFile); |
| 414 expect(location.offset, 25); | 404 expect(location.offset, 25); |
| 415 expect(location.length, 'myField'.length); | 405 expect(location.length, 'myField'.length); |
| 416 expect(location.startLine, 2); | 406 expect(location.startLine, 2); |
| 417 expect(location.startColumn, 16); | 407 expect(location.startColumn, 16); |
| 418 } | 408 } |
| 419 expect(element.parameters, isNull); | 409 expect(element.parameters, isNull); |
| 420 expect(element.returnType, 'dynamic'); | 410 expect(element.returnType, 'dynamic'); |
| 421 expect( | 411 expect( |
| 422 element.flags, plugin.Element.FLAG_CONST | plugin.Element.FLAG_STATIC); | 412 element.flags, plugin.Element.FLAG_CONST | plugin.Element.FLAG_STATIC); |
| 423 } | 413 } |
| 424 | 414 |
| 425 test_convertElement_functionTypeAlias() async { | 415 test_convertElement_functionTypeAlias() async { |
| 426 analyzer.Source source = addSource( | 416 analyzer.Source source = addSource(testFile, ''' |
| 427 testFile, | |
| 428 ''' | |
| 429 typedef int F<T>(String x); | 417 typedef int F<T>(String x); |
| 430 '''); | 418 '''); |
| 431 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); | 419 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 432 analyzer.FunctionTypeAliasElement engineElement = | 420 analyzer.FunctionTypeAliasElement engineElement = |
| 433 findElementInUnit(unit, 'F'); | 421 findElementInUnit(unit, 'F'); |
| 434 // create notification Element | 422 // create notification Element |
| 435 plugin.Element element = converter.convertElement(engineElement); | 423 plugin.Element element = converter.convertElement(engineElement); |
| 436 expect(element.kind, plugin.ElementKind.FUNCTION_TYPE_ALIAS); | 424 expect(element.kind, plugin.ElementKind.FUNCTION_TYPE_ALIAS); |
| 437 expect(element.name, 'F'); | 425 expect(element.name, 'F'); |
| 438 expect(element.typeParameters, '<T>'); | 426 expect(element.typeParameters, '<T>'); |
| 439 { | 427 { |
| 440 plugin.Location location = element.location; | 428 plugin.Location location = element.location; |
| 441 expect(location.file, testFile); | 429 expect(location.file, testFile); |
| 442 expect(location.offset, 12); | 430 expect(location.offset, 12); |
| 443 expect(location.length, 'F'.length); | 431 expect(location.length, 'F'.length); |
| 444 expect(location.startLine, 1); | 432 expect(location.startLine, 1); |
| 445 expect(location.startColumn, 13); | 433 expect(location.startColumn, 13); |
| 446 } | 434 } |
| 447 expect(element.parameters, '(String x)'); | 435 expect(element.parameters, '(String x)'); |
| 448 expect(element.returnType, 'int'); | 436 expect(element.returnType, 'int'); |
| 449 expect(element.flags, 0); | 437 expect(element.flags, 0); |
| 450 } | 438 } |
| 451 | 439 |
| 452 test_convertElement_getter() async { | 440 test_convertElement_getter() async { |
| 453 analyzer.Source source = addSource( | 441 analyzer.Source source = addSource(testFile, ''' |
| 454 testFile, | |
| 455 ''' | |
| 456 class A { | 442 class A { |
| 457 String get myGetter => 42; | 443 String get myGetter => 42; |
| 458 }'''); | 444 }'''); |
| 459 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); | 445 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 460 analyzer.PropertyAccessorElement engineElement = | 446 analyzer.PropertyAccessorElement engineElement = |
| 461 findElementInUnit(unit, 'myGetter', analyzer.ElementKind.GETTER); | 447 findElementInUnit(unit, 'myGetter', analyzer.ElementKind.GETTER); |
| 462 // create notification Element | 448 // create notification Element |
| 463 plugin.Element element = converter.convertElement(engineElement); | 449 plugin.Element element = converter.convertElement(engineElement); |
| 464 expect(element.kind, plugin.ElementKind.GETTER); | 450 expect(element.kind, plugin.ElementKind.GETTER); |
| 465 expect(element.name, 'myGetter'); | 451 expect(element.name, 'myGetter'); |
| 466 { | 452 { |
| 467 plugin.Location location = element.location; | 453 plugin.Location location = element.location; |
| 468 expect(location.file, testFile); | 454 expect(location.file, testFile); |
| 469 expect(location.offset, 23); | 455 expect(location.offset, 23); |
| 470 expect(location.length, 'myGetter'.length); | 456 expect(location.length, 'myGetter'.length); |
| 471 expect(location.startLine, 2); | 457 expect(location.startLine, 2); |
| 472 expect(location.startColumn, 14); | 458 expect(location.startColumn, 14); |
| 473 } | 459 } |
| 474 expect(element.parameters, isNull); | 460 expect(element.parameters, isNull); |
| 475 expect(element.returnType, 'String'); | 461 expect(element.returnType, 'String'); |
| 476 expect(element.flags, 0); | 462 expect(element.flags, 0); |
| 477 } | 463 } |
| 478 | 464 |
| 479 test_convertElement_method() async { | 465 test_convertElement_method() async { |
| 480 analyzer.Source source = addSource( | 466 analyzer.Source source = addSource(testFile, ''' |
| 481 testFile, | |
| 482 ''' | |
| 483 class A { | 467 class A { |
| 484 static List<String> myMethod(int a, {String b, int c}) { | 468 static List<String> myMethod(int a, {String b, int c}) { |
| 485 return null; | 469 return null; |
| 486 } | 470 } |
| 487 }'''); | 471 }'''); |
| 488 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); | 472 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 489 analyzer.MethodElement engineElement = findElementInUnit(unit, 'myMethod'); | 473 analyzer.MethodElement engineElement = findElementInUnit(unit, 'myMethod'); |
| 490 // create notification Element | 474 // create notification Element |
| 491 plugin.Element element = converter.convertElement(engineElement); | 475 plugin.Element element = converter.convertElement(engineElement); |
| 492 expect(element.kind, plugin.ElementKind.METHOD); | 476 expect(element.kind, plugin.ElementKind.METHOD); |
| 493 expect(element.name, 'myMethod'); | 477 expect(element.name, 'myMethod'); |
| 494 { | 478 { |
| 495 plugin.Location location = element.location; | 479 plugin.Location location = element.location; |
| 496 expect(location.file, testFile); | 480 expect(location.file, testFile); |
| 497 expect(location.offset, 32); | 481 expect(location.offset, 32); |
| 498 expect(location.length, 'myGetter'.length); | 482 expect(location.length, 'myGetter'.length); |
| 499 expect(location.startLine, 2); | 483 expect(location.startLine, 2); |
| 500 expect(location.startColumn, 23); | 484 expect(location.startColumn, 23); |
| 501 } | 485 } |
| 502 expect(element.parameters, '(int a, {String b, int c})'); | 486 expect(element.parameters, '(int a, {String b, int c})'); |
| 503 expect(element.returnType, 'List<String>'); | 487 expect(element.returnType, 'List<String>'); |
| 504 expect(element.flags, plugin.Element.FLAG_STATIC); | 488 expect(element.flags, plugin.Element.FLAG_STATIC); |
| 505 } | 489 } |
| 506 | 490 |
| 507 test_convertElement_setter() async { | 491 test_convertElement_setter() async { |
| 508 analyzer.Source source = addSource( | 492 analyzer.Source source = addSource(testFile, ''' |
| 509 testFile, | |
| 510 ''' | |
| 511 class A { | 493 class A { |
| 512 set mySetter(String x) {} | 494 set mySetter(String x) {} |
| 513 }'''); | 495 }'''); |
| 514 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); | 496 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 515 analyzer.PropertyAccessorElement engineElement = | 497 analyzer.PropertyAccessorElement engineElement = |
| 516 findElementInUnit(unit, 'mySetter', analyzer.ElementKind.SETTER); | 498 findElementInUnit(unit, 'mySetter', analyzer.ElementKind.SETTER); |
| 517 // create notification Element | 499 // create notification Element |
| 518 plugin.Element element = converter.convertElement(engineElement); | 500 plugin.Element element = converter.convertElement(engineElement); |
| 519 expect(element.kind, plugin.ElementKind.SETTER); | 501 expect(element.kind, plugin.ElementKind.SETTER); |
| 520 expect(element.name, 'mySetter'); | 502 expect(element.name, 'mySetter'); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 } | 557 } |
| 576 } | 558 } |
| 577 | 559 |
| 578 test_convertErrorType() { | 560 test_convertErrorType() { |
| 579 for (analyzer.ErrorType type in analyzer.ErrorType.values) { | 561 for (analyzer.ErrorType type in analyzer.ErrorType.values) { |
| 580 expect(converter.convertErrorType(type), isNotNull, reason: type.name); | 562 expect(converter.convertErrorType(type), isNotNull, reason: type.name); |
| 581 } | 563 } |
| 582 } | 564 } |
| 583 | 565 |
| 584 test_fromElement_LABEL() async { | 566 test_fromElement_LABEL() async { |
| 585 analyzer.Source source = addSource( | 567 analyzer.Source source = addSource(testFile, ''' |
| 586 testFile, | |
| 587 ''' | |
| 588 main() { | 568 main() { |
| 589 myLabel: | 569 myLabel: |
| 590 while (true) { | 570 while (true) { |
| 591 break myLabel; | 571 break myLabel; |
| 592 } | 572 } |
| 593 }'''); | 573 }'''); |
| 594 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); | 574 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 595 analyzer.LabelElement engineElement = findElementInUnit(unit, 'myLabel'); | 575 analyzer.LabelElement engineElement = findElementInUnit(unit, 'myLabel'); |
| 596 // create notification Element | 576 // create notification Element |
| 597 plugin.Element element = converter.convertElement(engineElement); | 577 plugin.Element element = converter.convertElement(engineElement); |
| 598 expect(element.kind, plugin.ElementKind.LABEL); | 578 expect(element.kind, plugin.ElementKind.LABEL); |
| 599 expect(element.name, 'myLabel'); | 579 expect(element.name, 'myLabel'); |
| 600 { | 580 { |
| 601 plugin.Location location = element.location; | 581 plugin.Location location = element.location; |
| 602 expect(location.file, testFile); | 582 expect(location.file, testFile); |
| 603 expect(location.offset, 9); | 583 expect(location.offset, 9); |
| 604 expect(location.length, 'myLabel'.length); | 584 expect(location.length, 'myLabel'.length); |
| 605 expect(location.startLine, 2); | 585 expect(location.startLine, 2); |
| 606 expect(location.startColumn, 1); | 586 expect(location.startColumn, 1); |
| 607 } | 587 } |
| 608 expect(element.parameters, isNull); | 588 expect(element.parameters, isNull); |
| 609 expect(element.returnType, isNull); | 589 expect(element.returnType, isNull); |
| 610 expect(element.flags, 0); | 590 expect(element.flags, 0); |
| 611 } | 591 } |
| 612 } | 592 } |
| OLD | NEW |