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 test.computer.element; | 5 library test.computer.element; |
6 | 6 |
7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
8 | 8 |
9 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
10 import 'package:analysis_server/src/protocol_server.dart'; | 10 import 'package:analysis_server/src/protocol_server.dart'; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 // create notification Element | 260 // create notification Element |
261 Element element = newElement_fromEngine(engineElement); | 261 Element element = newElement_fromEngine(engineElement); |
262 expect(element.kind, ElementKind.UNKNOWN); | 262 expect(element.kind, ElementKind.UNKNOWN); |
263 expect(element.name, 'dynamic'); | 263 expect(element.name, 'dynamic'); |
264 expect(element.location, isNull); | 264 expect(element.location, isNull); |
265 expect(element.parameters, isNull); | 265 expect(element.parameters, isNull); |
266 expect(element.returnType, isNull); | 266 expect(element.returnType, isNull); |
267 expect(element.flags, 0); | 267 expect(element.flags, 0); |
268 } | 268 } |
269 | 269 |
| 270 void test_fromElement_ENUM() { |
| 271 engine.Source source = addSource('/test.dart', ''' |
| 272 @deprecated |
| 273 enum _E1 { one, two } |
| 274 enum E2 { three, four }'''); |
| 275 engine.CompilationUnit unit = resolveLibraryUnit(source); |
| 276 { |
| 277 engine.ClassElement engineElement = findElementInUnit(unit, '_E1'); |
| 278 // TODO (danrubel) determine why enum is not deprecated |
| 279 expect(engineElement.isDeprecated, isFalse); |
| 280 // create notification Element |
| 281 Element element = newElement_fromEngine(engineElement); |
| 282 expect(element.kind, ElementKind.ENUM); |
| 283 expect(element.name, '_E1'); |
| 284 expect(element.typeParameters, isNull); |
| 285 { |
| 286 Location location = element.location; |
| 287 expect(location.file, '/test.dart'); |
| 288 expect(location.offset, 17); |
| 289 expect(location.length, '_E1'.length); |
| 290 expect(location.startLine, 2); |
| 291 expect(location.startColumn, 6); |
| 292 } |
| 293 expect(element.parameters, isNull); |
| 294 expect(element.flags, |
| 295 (engineElement.isDeprecated ? Element.FLAG_DEPRECATED : 0) | |
| 296 Element.FLAG_PRIVATE); |
| 297 } |
| 298 { |
| 299 engine.ClassElement engineElement = findElementInUnit(unit, 'E2'); |
| 300 // create notification Element |
| 301 Element element = newElement_fromEngine(engineElement); |
| 302 expect(element.kind, ElementKind.ENUM); |
| 303 expect(element.name, 'E2'); |
| 304 expect(element.typeParameters, isNull); |
| 305 expect(element.flags, 0); |
| 306 } |
| 307 } |
| 308 |
| 309 void test_fromElement_ENUM_CONSTANT() { |
| 310 engine.Source source = addSource('/test.dart', ''' |
| 311 @deprecated |
| 312 enum _E1 { one, two } |
| 313 enum E2 { three, four }'''); |
| 314 engine.CompilationUnit unit = resolveLibraryUnit(source); |
| 315 { |
| 316 engine.FieldElement engineElement = findElementInUnit(unit, 'one'); |
| 317 // create notification Element |
| 318 Element element = newElement_fromEngine(engineElement); |
| 319 expect(element.kind, ElementKind.ENUM_CONSTANT); |
| 320 expect(element.name, 'one'); |
| 321 { |
| 322 Location location = element.location; |
| 323 expect(location.file, '/test.dart'); |
| 324 expect(location.offset, 23); |
| 325 expect(location.length, 'one'.length); |
| 326 expect(location.startLine, 2); |
| 327 expect(location.startColumn, 12); |
| 328 } |
| 329 expect(element.parameters, isNull); |
| 330 expect(element.returnType, '_E1'); |
| 331 // TODO(danrubel) determine why enum constant is not marked as deprecated |
| 332 engine.ClassElement classElement = engineElement.enclosingElement; |
| 333 expect(element.flags, |
| 334 (classElement.isDeprecated ? Element.FLAG_DEPRECATED : 0) | |
| 335 Element.FLAG_CONST | |
| 336 Element.FLAG_STATIC); |
| 337 } |
| 338 { |
| 339 engine.FieldElement engineElement = findElementInUnit(unit, 'three'); |
| 340 // create notification Element |
| 341 Element element = newElement_fromEngine(engineElement); |
| 342 expect(element.kind, ElementKind.ENUM_CONSTANT); |
| 343 expect(element.name, 'three'); |
| 344 { |
| 345 Location location = element.location; |
| 346 expect(location.file, '/test.dart'); |
| 347 expect(location.offset, 44); |
| 348 expect(location.length, 'three'.length); |
| 349 expect(location.startLine, 3); |
| 350 expect(location.startColumn, 11); |
| 351 } |
| 352 expect(element.parameters, isNull); |
| 353 expect(element.returnType, 'E2'); |
| 354 expect(element.flags, Element.FLAG_CONST | Element.FLAG_STATIC); |
| 355 } |
| 356 { |
| 357 engine.FieldElement engineElement = findElementInUnit(unit, 'index'); |
| 358 // create notification Element |
| 359 Element element = newElement_fromEngine(engineElement); |
| 360 expect(element.kind, ElementKind.FIELD); |
| 361 expect(element.name, 'index'); |
| 362 { |
| 363 Location location = element.location; |
| 364 expect(location.file, '/test.dart'); |
| 365 expect(location.offset, -1); |
| 366 expect(location.length, 'index'.length); |
| 367 expect(location.startLine, 1); |
| 368 expect(location.startColumn, 0); |
| 369 } |
| 370 expect(element.parameters, isNull); |
| 371 expect(element.returnType, 'int'); |
| 372 expect(element.flags, Element.FLAG_FINAL); |
| 373 } |
| 374 { |
| 375 engine.FieldElement engineElement = findElementInUnit(unit, 'values'); |
| 376 // create notification Element |
| 377 Element element = newElement_fromEngine(engineElement); |
| 378 expect(element.kind, ElementKind.FIELD); |
| 379 expect(element.name, 'values'); |
| 380 { |
| 381 Location location = element.location; |
| 382 expect(location.file, '/test.dart'); |
| 383 expect(location.offset, -1); |
| 384 expect(location.length, 'values'.length); |
| 385 expect(location.startLine, 1); |
| 386 expect(location.startColumn, 0); |
| 387 } |
| 388 expect(element.parameters, isNull); |
| 389 expect(element.returnType, 'List<E2>'); |
| 390 expect(element.flags, Element.FLAG_CONST | Element.FLAG_STATIC); |
| 391 } |
| 392 } |
| 393 |
270 void test_fromElement_FIELD() { | 394 void test_fromElement_FIELD() { |
271 engine.Source source = addSource('/test.dart', ''' | 395 engine.Source source = addSource('/test.dart', ''' |
272 class A { | 396 class A { |
273 static const myField = 42; | 397 static const myField = 42; |
274 }'''); | 398 }'''); |
275 engine.CompilationUnit unit = resolveLibraryUnit(source); | 399 engine.CompilationUnit unit = resolveLibraryUnit(source); |
276 engine.FieldElement engineElement = findElementInUnit(unit, 'myField'); | 400 engine.FieldElement engineElement = findElementInUnit(unit, 'myField'); |
277 // create notification Element | 401 // create notification Element |
278 Element element = newElement_fromEngine(engineElement); | 402 Element element = newElement_fromEngine(engineElement); |
279 expect(element.kind, ElementKind.FIELD); | 403 expect(element.kind, ElementKind.FIELD); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 ApiEnum apiValue = convert(engineValue); | 620 ApiEnum apiValue = convert(engineValue); |
497 expect(apiValue, equals(expectedResult)); | 621 expect(apiValue, equals(expectedResult)); |
498 } | 622 } |
499 } else { | 623 } else { |
500 ApiEnum apiValue = convert(engineValue); | 624 ApiEnum apiValue = convert(engineValue); |
501 expect(apiValue.name, equals(enumName)); | 625 expect(apiValue.name, equals(enumName)); |
502 } | 626 } |
503 }); | 627 }); |
504 } | 628 } |
505 } | 629 } |
OLD | NEW |