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; |
| 6 import 'package:analyzer/dart/element/element.dart' as analyzer; |
| 7 import 'package:analyzer/dart/element/type.dart' as analyzer; |
5 import 'package:analyzer/error/error.dart' as analyzer; | 8 import 'package:analyzer/error/error.dart' as analyzer; |
6 import 'package:analyzer/file_system/memory_file_system.dart'; | 9 import 'package:analyzer/exception/exception.dart' as analyzer; |
7 import 'package:analyzer/source/error_processor.dart' as analyzer; | 10 import 'package:analyzer/source/error_processor.dart' as analyzer; |
| 11 import 'package:analyzer/src/dart/element/element.dart' as analyzer; |
8 import 'package:analyzer/src/error/codes.dart' as analyzer; | 12 import 'package:analyzer/src/error/codes.dart' as analyzer; |
9 import 'package:analyzer/src/generated/engine.dart' as analyzer; | 13 import 'package:analyzer/src/generated/engine.dart' as analyzer; |
10 import 'package:analyzer/src/generated/source.dart' as analyzer; | 14 import 'package:analyzer/src/generated/source.dart' as analyzer; |
| 15 import 'package:analyzer/src/generated/utilities_dart.dart' as analyzer; |
11 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin; | 16 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin; |
12 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; | 17 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; |
13 import 'package:analyzer_plugin/utilities/analyzer_converter.dart'; | 18 import 'package:analyzer_plugin/utilities/analyzer_converter.dart'; |
14 import 'package:test/test.dart'; | 19 import 'package:test/test.dart'; |
15 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 20 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
16 | 21 |
| 22 import '../support/abstract_context.dart'; |
| 23 |
17 void main() { | 24 void main() { |
18 defineReflectiveTests(AnalyzerConverterTest); | 25 defineReflectiveTests(AnalyzerConverterTest); |
19 } | 26 } |
20 | 27 |
21 @reflectiveTest | 28 @reflectiveTest |
22 class AnalyzerConverterTest { | 29 class AnalyzerConverterTest extends AbstractContextTest { |
23 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); | |
24 AnalyzerConverter converter = new AnalyzerConverter(); | 30 AnalyzerConverter converter = new AnalyzerConverter(); |
25 analyzer.Source source; | 31 analyzer.Source source; |
| 32 String testFile; |
26 | 33 |
27 /** | 34 /** |
28 * Assert that the given [pluginError] matches the given [analyzerError]. | 35 * Assert that the given [pluginError] matches the given [analyzerError]. |
29 */ | 36 */ |
30 void assertError( | 37 void assertError( |
31 plugin.AnalysisError pluginError, analyzer.AnalysisError analyzerError, | 38 plugin.AnalysisError pluginError, analyzer.AnalysisError analyzerError, |
32 {analyzer.ErrorSeverity severity, | 39 {analyzer.ErrorSeverity severity, |
33 int startColumn: -1, | 40 int startColumn: -1, |
34 int startLine: -1}) { | 41 int startLine: -1}) { |
35 analyzer.ErrorCode errorCode = analyzerError.errorCode; | 42 analyzer.ErrorCode errorCode = analyzerError.errorCode; |
36 expect(pluginError, isNotNull); | 43 expect(pluginError, isNotNull); |
37 plugin.Location location = pluginError.location; | 44 plugin.Location location = pluginError.location; |
38 expect(pluginError.code, errorCode.name.toLowerCase()); | 45 expect(pluginError.code, errorCode.name.toLowerCase()); |
39 expect(pluginError.correction, errorCode.correction); | 46 expect(pluginError.correction, errorCode.correction); |
40 expect(location, isNotNull); | 47 expect(location, isNotNull); |
41 expect(location.file, analyzerError.source.fullName); | 48 expect(location.file, analyzerError.source.fullName); |
42 expect(location.length, analyzerError.length); | 49 expect(location.length, analyzerError.length); |
43 expect(location.offset, analyzerError.offset); | 50 expect(location.offset, analyzerError.offset); |
44 expect(location.startColumn, startColumn); | 51 expect(location.startColumn, startColumn); |
45 expect(location.startLine, startLine); | 52 expect(location.startLine, startLine); |
46 expect(pluginError.message, errorCode.message); | 53 expect(pluginError.message, errorCode.message); |
47 expect(pluginError.severity, | 54 expect(pluginError.severity, |
48 converter.convertErrorSeverity(severity ?? errorCode.errorSeverity)); | 55 converter.convertErrorSeverity(severity ?? errorCode.errorSeverity)); |
49 expect(pluginError.type, converter.convertErrorType(errorCode.type)); | 56 expect(pluginError.type, converter.convertErrorType(errorCode.type)); |
50 } | 57 } |
51 | 58 |
52 analyzer.AnalysisError createError(int offset) => new analyzer.AnalysisError( | 59 analyzer.AnalysisError createError(int offset) => new analyzer.AnalysisError( |
53 source, offset, 5, analyzer.CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT); | 60 source, offset, 5, analyzer.CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT); |
54 | 61 |
| 62 @override |
55 void setUp() { | 63 void setUp() { |
56 source = resourceProvider | 64 super.setUp(); |
57 .newFile(resourceProvider.convertPath('/foo/bar.dart'), '') | 65 source = provider |
| 66 .newFile(provider.convertPath('/foo/bar.dart'), '') |
58 .createSource(); | 67 .createSource(); |
| 68 testFile = provider.convertPath('/test.dart'); |
59 } | 69 } |
60 | 70 |
61 test_convertAnalysisError_lineInfo_noSeverity() { | 71 test_convertAnalysisError_lineInfo_noSeverity() { |
62 analyzer.AnalysisError analyzerError = createError(13); | 72 analyzer.AnalysisError analyzerError = createError(13); |
63 analyzer.LineInfo lineInfo = new analyzer.LineInfo([0, 10, 20]); | 73 analyzer.LineInfo lineInfo = new analyzer.LineInfo([0, 10, 20]); |
64 | 74 |
65 assertError( | 75 assertError( |
66 converter.convertAnalysisError(analyzerError, lineInfo: lineInfo), | 76 converter.convertAnalysisError(analyzerError, lineInfo: lineInfo), |
67 analyzerError, | 77 analyzerError, |
68 startColumn: 4, | 78 startColumn: 4, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 new analyzer.ErrorProcessor(analyzerErrors[0].errorCode.name, severity) | 172 new analyzer.ErrorProcessor(analyzerErrors[0].errorCode.name, severity) |
163 ]; | 173 ]; |
164 | 174 |
165 List<plugin.AnalysisError> pluginErrors = | 175 List<plugin.AnalysisError> pluginErrors = |
166 converter.convertAnalysisErrors(analyzerErrors, options: options); | 176 converter.convertAnalysisErrors(analyzerErrors, options: options); |
167 expect(pluginErrors, hasLength(analyzerErrors.length)); | 177 expect(pluginErrors, hasLength(analyzerErrors.length)); |
168 assertError(pluginErrors[0], analyzerErrors[0], severity: severity); | 178 assertError(pluginErrors[0], analyzerErrors[0], severity: severity); |
169 assertError(pluginErrors[1], analyzerErrors[1], severity: severity); | 179 assertError(pluginErrors[1], analyzerErrors[1], severity: severity); |
170 } | 180 } |
171 | 181 |
| 182 test_convertElement_class() async { |
| 183 analyzer.Source source = addSource( |
| 184 testFile, |
| 185 ''' |
| 186 @deprecated |
| 187 abstract class _A {} |
| 188 class B<K, V> {}'''); |
| 189 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 190 { |
| 191 analyzer.ClassElement engineElement = findElementInUnit(unit, '_A'); |
| 192 // create notification Element |
| 193 plugin.Element element = converter.convertElement(engineElement); |
| 194 expect(element.kind, plugin.ElementKind.CLASS); |
| 195 expect(element.name, '_A'); |
| 196 expect(element.typeParameters, isNull); |
| 197 { |
| 198 plugin.Location location = element.location; |
| 199 expect(location.file, '/test.dart'); |
| 200 expect(location.offset, 27); |
| 201 expect(location.length, '_A'.length); |
| 202 expect(location.startLine, 2); |
| 203 expect(location.startColumn, 16); |
| 204 } |
| 205 expect(element.parameters, isNull); |
| 206 expect( |
| 207 element.flags, |
| 208 plugin.Element.FLAG_ABSTRACT | |
| 209 plugin.Element.FLAG_DEPRECATED | |
| 210 plugin.Element.FLAG_PRIVATE); |
| 211 } |
| 212 { |
| 213 analyzer.ClassElement engineElement = findElementInUnit(unit, 'B'); |
| 214 // create notification Element |
| 215 plugin.Element element = converter.convertElement(engineElement); |
| 216 expect(element.kind, plugin.ElementKind.CLASS); |
| 217 expect(element.name, 'B'); |
| 218 expect(element.typeParameters, '<K, V>'); |
| 219 expect(element.flags, 0); |
| 220 } |
| 221 } |
| 222 |
| 223 test_convertElement_constructor() async { |
| 224 analyzer.Source source = addSource( |
| 225 testFile, |
| 226 ''' |
| 227 class A { |
| 228 const A.myConstructor(int a, [String b]); |
| 229 }'''); |
| 230 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 231 analyzer.ConstructorElement engineElement = |
| 232 findElementInUnit(unit, 'myConstructor'); |
| 233 // create notification Element |
| 234 plugin.Element element = converter.convertElement(engineElement); |
| 235 expect(element.kind, plugin.ElementKind.CONSTRUCTOR); |
| 236 expect(element.name, 'myConstructor'); |
| 237 expect(element.typeParameters, isNull); |
| 238 { |
| 239 plugin.Location location = element.location; |
| 240 expect(location.file, '/test.dart'); |
| 241 expect(location.offset, 20); |
| 242 expect(location.length, 'myConstructor'.length); |
| 243 expect(location.startLine, 2); |
| 244 expect(location.startColumn, 11); |
| 245 } |
| 246 expect(element.parameters, '(int a, [String b])'); |
| 247 expect(element.returnType, 'A'); |
| 248 expect(element.flags, plugin.Element.FLAG_CONST); |
| 249 } |
| 250 |
| 251 void test_convertElement_dynamic() { |
| 252 var engineElement = analyzer.DynamicElementImpl.instance; |
| 253 // create notification Element |
| 254 plugin.Element element = converter.convertElement(engineElement); |
| 255 expect(element.kind, plugin.ElementKind.UNKNOWN); |
| 256 expect(element.name, 'dynamic'); |
| 257 expect(element.location, isNull); |
| 258 expect(element.parameters, isNull); |
| 259 expect(element.returnType, isNull); |
| 260 expect(element.flags, 0); |
| 261 } |
| 262 |
| 263 test_convertElement_enum() async { |
| 264 analyzer.Source source = addSource( |
| 265 testFile, |
| 266 ''' |
| 267 @deprecated |
| 268 enum _E1 { one, two } |
| 269 enum E2 { three, four }'''); |
| 270 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 271 { |
| 272 analyzer.ClassElement engineElement = findElementInUnit(unit, '_E1'); |
| 273 expect(engineElement.isDeprecated, isTrue); |
| 274 // create notification Element |
| 275 plugin.Element element = converter.convertElement(engineElement); |
| 276 expect(element.kind, plugin.ElementKind.ENUM); |
| 277 expect(element.name, '_E1'); |
| 278 expect(element.typeParameters, isNull); |
| 279 { |
| 280 plugin.Location location = element.location; |
| 281 expect(location.file, '/test.dart'); |
| 282 expect(location.offset, 17); |
| 283 expect(location.length, '_E1'.length); |
| 284 expect(location.startLine, 2); |
| 285 expect(location.startColumn, 6); |
| 286 } |
| 287 expect(element.parameters, isNull); |
| 288 expect( |
| 289 element.flags, |
| 290 (engineElement.isDeprecated ? plugin.Element.FLAG_DEPRECATED : 0) | |
| 291 plugin.Element.FLAG_PRIVATE); |
| 292 } |
| 293 { |
| 294 analyzer.ClassElement engineElement = findElementInUnit(unit, 'E2'); |
| 295 // create notification Element |
| 296 plugin.Element element = converter.convertElement(engineElement); |
| 297 expect(element.kind, plugin.ElementKind.ENUM); |
| 298 expect(element.name, 'E2'); |
| 299 expect(element.typeParameters, isNull); |
| 300 expect(element.flags, 0); |
| 301 } |
| 302 } |
| 303 |
| 304 test_convertElement_enumConstant() async { |
| 305 analyzer.Source source = addSource( |
| 306 testFile, |
| 307 ''' |
| 308 @deprecated |
| 309 enum _E1 { one, two } |
| 310 enum E2 { three, four }'''); |
| 311 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 312 { |
| 313 analyzer.FieldElement engineElement = findElementInUnit(unit, 'one'); |
| 314 // create notification Element |
| 315 plugin.Element element = converter.convertElement(engineElement); |
| 316 expect(element.kind, plugin.ElementKind.ENUM_CONSTANT); |
| 317 expect(element.name, 'one'); |
| 318 { |
| 319 plugin.Location location = element.location; |
| 320 expect(location.file, '/test.dart'); |
| 321 expect(location.offset, 23); |
| 322 expect(location.length, 'one'.length); |
| 323 expect(location.startLine, 2); |
| 324 expect(location.startColumn, 12); |
| 325 } |
| 326 expect(element.parameters, isNull); |
| 327 expect(element.returnType, '_E1'); |
| 328 // TODO(danrubel) determine why enum constant is not marked as deprecated |
| 329 //analyzer.ClassElement classElement = engineElement.enclosingElement; |
| 330 //expect(classElement.isDeprecated, isTrue); |
| 331 expect( |
| 332 element.flags, |
| 333 // Element.FLAG_DEPRECATED | |
| 334 plugin.Element.FLAG_CONST | plugin.Element.FLAG_STATIC); |
| 335 } |
| 336 { |
| 337 analyzer.FieldElement engineElement = findElementInUnit(unit, 'three'); |
| 338 // create notification Element |
| 339 plugin.Element element = converter.convertElement(engineElement); |
| 340 expect(element.kind, plugin.ElementKind.ENUM_CONSTANT); |
| 341 expect(element.name, 'three'); |
| 342 { |
| 343 plugin.Location location = element.location; |
| 344 expect(location.file, '/test.dart'); |
| 345 expect(location.offset, 44); |
| 346 expect(location.length, 'three'.length); |
| 347 expect(location.startLine, 3); |
| 348 expect(location.startColumn, 11); |
| 349 } |
| 350 expect(element.parameters, isNull); |
| 351 expect(element.returnType, 'E2'); |
| 352 expect(element.flags, |
| 353 plugin.Element.FLAG_CONST | plugin.Element.FLAG_STATIC); |
| 354 } |
| 355 { |
| 356 analyzer.FieldElement engineElement = findElementInUnit(unit, 'index'); |
| 357 // create notification Element |
| 358 plugin.Element element = converter.convertElement(engineElement); |
| 359 expect(element.kind, plugin.ElementKind.FIELD); |
| 360 expect(element.name, 'index'); |
| 361 { |
| 362 plugin.Location location = element.location; |
| 363 expect(location.file, '/test.dart'); |
| 364 expect(location.offset, -1); |
| 365 expect(location.length, 'index'.length); |
| 366 expect(location.startLine, 1); |
| 367 expect(location.startColumn, 0); |
| 368 } |
| 369 expect(element.parameters, isNull); |
| 370 expect(element.returnType, 'int'); |
| 371 expect(element.flags, plugin.Element.FLAG_FINAL); |
| 372 } |
| 373 { |
| 374 analyzer.FieldElement engineElement = findElementInUnit(unit, 'values'); |
| 375 // create notification Element |
| 376 plugin.Element element = converter.convertElement(engineElement); |
| 377 expect(element.kind, plugin.ElementKind.FIELD); |
| 378 expect(element.name, 'values'); |
| 379 { |
| 380 plugin.Location location = element.location; |
| 381 expect(location.file, '/test.dart'); |
| 382 expect(location.offset, -1); |
| 383 expect(location.length, 'values'.length); |
| 384 expect(location.startLine, 1); |
| 385 expect(location.startColumn, 0); |
| 386 } |
| 387 expect(element.parameters, isNull); |
| 388 expect(element.returnType, 'List<E2>'); |
| 389 expect(element.flags, |
| 390 plugin.Element.FLAG_CONST | plugin.Element.FLAG_STATIC); |
| 391 } |
| 392 } |
| 393 |
| 394 test_convertElement_field() async { |
| 395 analyzer.Source source = addSource( |
| 396 testFile, |
| 397 ''' |
| 398 class A { |
| 399 static const myField = 42; |
| 400 }'''); |
| 401 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 402 analyzer.FieldElement engineElement = findElementInUnit(unit, 'myField'); |
| 403 // create notification Element |
| 404 plugin.Element element = converter.convertElement(engineElement); |
| 405 expect(element.kind, plugin.ElementKind.FIELD); |
| 406 expect(element.name, 'myField'); |
| 407 { |
| 408 plugin.Location location = element.location; |
| 409 expect(location.file, '/test.dart'); |
| 410 expect(location.offset, 25); |
| 411 expect(location.length, 'myField'.length); |
| 412 expect(location.startLine, 2); |
| 413 expect(location.startColumn, 16); |
| 414 } |
| 415 expect(element.parameters, isNull); |
| 416 expect(element.returnType, 'dynamic'); |
| 417 expect( |
| 418 element.flags, plugin.Element.FLAG_CONST | plugin.Element.FLAG_STATIC); |
| 419 } |
| 420 |
| 421 test_convertElement_functionTypeAlias() async { |
| 422 analyzer.Source source = addSource( |
| 423 testFile, |
| 424 ''' |
| 425 typedef int F<T>(String x); |
| 426 '''); |
| 427 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 428 analyzer.FunctionTypeAliasElement engineElement = |
| 429 findElementInUnit(unit, 'F'); |
| 430 // create notification Element |
| 431 plugin.Element element = converter.convertElement(engineElement); |
| 432 expect(element.kind, plugin.ElementKind.FUNCTION_TYPE_ALIAS); |
| 433 expect(element.name, 'F'); |
| 434 expect(element.typeParameters, '<T>'); |
| 435 { |
| 436 plugin.Location location = element.location; |
| 437 expect(location.file, '/test.dart'); |
| 438 expect(location.offset, 12); |
| 439 expect(location.length, 'F'.length); |
| 440 expect(location.startLine, 1); |
| 441 expect(location.startColumn, 13); |
| 442 } |
| 443 expect(element.parameters, '(String x)'); |
| 444 expect(element.returnType, 'int'); |
| 445 expect(element.flags, 0); |
| 446 } |
| 447 |
| 448 test_convertElement_getter() async { |
| 449 analyzer.Source source = addSource( |
| 450 testFile, |
| 451 ''' |
| 452 class A { |
| 453 String get myGetter => 42; |
| 454 }'''); |
| 455 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 456 analyzer.PropertyAccessorElement engineElement = |
| 457 findElementInUnit(unit, 'myGetter', analyzer.ElementKind.GETTER); |
| 458 // create notification Element |
| 459 plugin.Element element = converter.convertElement(engineElement); |
| 460 expect(element.kind, plugin.ElementKind.GETTER); |
| 461 expect(element.name, 'myGetter'); |
| 462 { |
| 463 plugin.Location location = element.location; |
| 464 expect(location.file, '/test.dart'); |
| 465 expect(location.offset, 23); |
| 466 expect(location.length, 'myGetter'.length); |
| 467 expect(location.startLine, 2); |
| 468 expect(location.startColumn, 14); |
| 469 } |
| 470 expect(element.parameters, isNull); |
| 471 expect(element.returnType, 'String'); |
| 472 expect(element.flags, 0); |
| 473 } |
| 474 |
| 475 test_convertElement_method() async { |
| 476 analyzer.Source source = addSource( |
| 477 testFile, |
| 478 ''' |
| 479 class A { |
| 480 static List<String> myMethod(int a, {String b, int c}) { |
| 481 return null; |
| 482 } |
| 483 }'''); |
| 484 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 485 analyzer.MethodElement engineElement = findElementInUnit(unit, 'myMethod'); |
| 486 // create notification Element |
| 487 plugin.Element element = converter.convertElement(engineElement); |
| 488 expect(element.kind, plugin.ElementKind.METHOD); |
| 489 expect(element.name, 'myMethod'); |
| 490 { |
| 491 plugin.Location location = element.location; |
| 492 expect(location.file, '/test.dart'); |
| 493 expect(location.offset, 32); |
| 494 expect(location.length, 'myGetter'.length); |
| 495 expect(location.startLine, 2); |
| 496 expect(location.startColumn, 23); |
| 497 } |
| 498 expect(element.parameters, '(int a, {String b, int c})'); |
| 499 expect(element.returnType, 'List<String>'); |
| 500 expect(element.flags, plugin.Element.FLAG_STATIC); |
| 501 } |
| 502 |
| 503 test_convertElement_setter() async { |
| 504 analyzer.Source source = addSource( |
| 505 testFile, |
| 506 ''' |
| 507 class A { |
| 508 set mySetter(String x) {} |
| 509 }'''); |
| 510 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 511 analyzer.FieldElement engineFieldElement = |
| 512 findElementInUnit(unit, 'mySetter', analyzer.ElementKind.FIELD); |
| 513 analyzer.PropertyAccessorElement engineElement = engineFieldElement.setter; |
| 514 // create notification Element |
| 515 plugin.Element element = converter.convertElement(engineElement); |
| 516 expect(element.kind, plugin.ElementKind.SETTER); |
| 517 expect(element.name, 'mySetter'); |
| 518 { |
| 519 plugin.Location location = element.location; |
| 520 expect(location.file, '/test.dart'); |
| 521 expect(location.offset, 16); |
| 522 expect(location.length, 'mySetter'.length); |
| 523 expect(location.startLine, 2); |
| 524 expect(location.startColumn, 7); |
| 525 } |
| 526 expect(element.parameters, '(String x)'); |
| 527 expect(element.returnType, isNull); |
| 528 expect(element.flags, 0); |
| 529 } |
| 530 |
| 531 void test_convertElementKind() { |
| 532 expect(converter.convertElementKind(analyzer.ElementKind.CLASS), |
| 533 plugin.ElementKind.CLASS); |
| 534 expect(converter.convertElementKind(analyzer.ElementKind.COMPILATION_UNIT), |
| 535 plugin.ElementKind.COMPILATION_UNIT); |
| 536 expect(converter.convertElementKind(analyzer.ElementKind.CONSTRUCTOR), |
| 537 plugin.ElementKind.CONSTRUCTOR); |
| 538 expect(converter.convertElementKind(analyzer.ElementKind.FIELD), |
| 539 plugin.ElementKind.FIELD); |
| 540 expect(converter.convertElementKind(analyzer.ElementKind.FUNCTION), |
| 541 plugin.ElementKind.FUNCTION); |
| 542 expect( |
| 543 converter.convertElementKind(analyzer.ElementKind.FUNCTION_TYPE_ALIAS), |
| 544 plugin.ElementKind.FUNCTION_TYPE_ALIAS); |
| 545 expect(converter.convertElementKind(analyzer.ElementKind.GETTER), |
| 546 plugin.ElementKind.GETTER); |
| 547 expect(converter.convertElementKind(analyzer.ElementKind.LABEL), |
| 548 plugin.ElementKind.LABEL); |
| 549 expect(converter.convertElementKind(analyzer.ElementKind.LIBRARY), |
| 550 plugin.ElementKind.LIBRARY); |
| 551 expect(converter.convertElementKind(analyzer.ElementKind.LOCAL_VARIABLE), |
| 552 plugin.ElementKind.LOCAL_VARIABLE); |
| 553 expect(converter.convertElementKind(analyzer.ElementKind.METHOD), |
| 554 plugin.ElementKind.METHOD); |
| 555 expect(converter.convertElementKind(analyzer.ElementKind.PARAMETER), |
| 556 plugin.ElementKind.PARAMETER); |
| 557 expect(converter.convertElementKind(analyzer.ElementKind.SETTER), |
| 558 plugin.ElementKind.SETTER); |
| 559 expect( |
| 560 converter.convertElementKind(analyzer.ElementKind.TOP_LEVEL_VARIABLE), |
| 561 plugin.ElementKind.TOP_LEVEL_VARIABLE); |
| 562 expect(converter.convertElementKind(analyzer.ElementKind.TYPE_PARAMETER), |
| 563 plugin.ElementKind.TYPE_PARAMETER); |
| 564 } |
| 565 |
172 test_convertErrorSeverity() { | 566 test_convertErrorSeverity() { |
173 for (analyzer.ErrorSeverity severity in analyzer.ErrorSeverity.values) { | 567 for (analyzer.ErrorSeverity severity in analyzer.ErrorSeverity.values) { |
174 if (severity != analyzer.ErrorSeverity.NONE) { | 568 if (severity != analyzer.ErrorSeverity.NONE) { |
175 expect(converter.convertErrorSeverity(severity), isNotNull, | 569 expect(converter.convertErrorSeverity(severity), isNotNull, |
176 reason: severity.name); | 570 reason: severity.name); |
177 } | 571 } |
178 } | 572 } |
179 } | 573 } |
180 | 574 |
181 test_convertErrorType() { | 575 test_convertErrorType() { |
182 for (analyzer.ErrorType type in analyzer.ErrorType.values) { | 576 for (analyzer.ErrorType type in analyzer.ErrorType.values) { |
183 expect(converter.convertErrorType(type), isNotNull, reason: type.name); | 577 expect(converter.convertErrorType(type), isNotNull, reason: type.name); |
184 } | 578 } |
185 } | 579 } |
| 580 |
| 581 test_fromElement_LABEL() async { |
| 582 analyzer.Source source = addSource( |
| 583 testFile, |
| 584 ''' |
| 585 main() { |
| 586 myLabel: |
| 587 while (true) { |
| 588 break myLabel; |
| 589 } |
| 590 }'''); |
| 591 analyzer.CompilationUnit unit = await resolveLibraryUnit(source); |
| 592 analyzer.LabelElement engineElement = findElementInUnit(unit, 'myLabel'); |
| 593 // create notification Element |
| 594 plugin.Element element = converter.convertElement(engineElement); |
| 595 expect(element.kind, plugin.ElementKind.LABEL); |
| 596 expect(element.name, 'myLabel'); |
| 597 { |
| 598 plugin.Location location = element.location; |
| 599 expect(location.file, '/test.dart'); |
| 600 expect(location.offset, 9); |
| 601 expect(location.length, 'myLabel'.length); |
| 602 expect(location.startLine, 2); |
| 603 expect(location.startColumn, 1); |
| 604 } |
| 605 expect(element.parameters, isNull); |
| 606 expect(element.returnType, isNull); |
| 607 expect(element.flags, 0); |
| 608 } |
186 } | 609 } |
OLD | NEW |