| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 dart2js.mirrors_used; | 5 library dart2js.mirrors_used; |
| 6 | 6 |
| 7 import 'common/tasks.dart' show CompilerTask; | 7 import 'common/tasks.dart' show CompilerTask; |
| 8 import 'common.dart'; | 8 import 'common.dart'; |
| 9 import 'compile_time_constants.dart' show ConstantCompiler; | 9 import 'compile_time_constants.dart' show ConstantCompiler; |
| 10 import 'compiler.dart' show Compiler; | 10 import 'compiler.dart' show Compiler; |
| 11 import 'constants/expressions.dart'; | 11 import 'constants/expressions.dart'; |
| 12 import 'constants/values.dart' | 12 import 'constants/values.dart' |
| 13 show | 13 show |
| 14 ConstantValue, | 14 ConstantValue, |
| 15 ConstructedConstantValue, | 15 ConstructedConstantValue, |
| 16 ListConstantValue, | 16 ListConstantValue, |
| 17 StringConstantValue, | 17 StringConstantValue, |
| 18 TypeConstantValue; | 18 TypeConstantValue; |
| 19 import 'elements/resolution_types.dart' show DartType, InterfaceType; | 19 import 'elements/resolution_types.dart' |
| 20 show ResolutionDartType, ResolutionInterfaceType; |
| 20 import 'elements/elements.dart' | 21 import 'elements/elements.dart' |
| 21 show | 22 show |
| 22 ClassElement, | 23 ClassElement, |
| 23 Element, | 24 Element, |
| 24 FieldElement, | 25 FieldElement, |
| 25 ImportElement, | 26 ImportElement, |
| 26 LibraryElement, | 27 LibraryElement, |
| 27 MetadataAnnotation, | 28 MetadataAnnotation, |
| 28 ScopeContainerElement; | 29 ScopeContainerElement; |
| 29 import 'resolution/tree_elements.dart' show TreeElements; | 30 import 'resolution/tree_elements.dart' show TreeElements; |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 MessageKind kind = onlyStrings | 408 MessageKind kind = onlyStrings |
| 408 ? MessageKind.MIRRORS_EXPECTED_STRING_OR_LIST | 409 ? MessageKind.MIRRORS_EXPECTED_STRING_OR_LIST |
| 409 : MessageKind.MIRRORS_EXPECTED_STRING_TYPE_OR_LIST; | 410 : MessageKind.MIRRORS_EXPECTED_STRING_TYPE_OR_LIST; |
| 410 reporter.reportHintMessage( | 411 reporter.reportHintMessage( |
| 411 node, kind, {'name': node, 'type': apiTypeOf(constant)}); | 412 node, kind, {'name': node, 'type': apiTypeOf(constant)}); |
| 412 return null; | 413 return null; |
| 413 } | 414 } |
| 414 } | 415 } |
| 415 | 416 |
| 416 /// Find the first non-implementation interface of constant. | 417 /// Find the first non-implementation interface of constant. |
| 417 DartType apiTypeOf(ConstantValue constant) { | 418 ResolutionDartType apiTypeOf(ConstantValue constant) { |
| 418 DartType type = constant.getType(compiler.commonElements); | 419 ResolutionDartType type = constant.getType(compiler.commonElements); |
| 419 LibraryElement library = type.element.library; | 420 LibraryElement library = type.element.library; |
| 420 if (type.isInterfaceType && library.isInternalLibrary) { | 421 if (type.isInterfaceType && library.isInternalLibrary) { |
| 421 InterfaceType interface = type; | 422 ResolutionInterfaceType interface = type; |
| 422 ClassElement cls = type.element; | 423 ClassElement cls = type.element; |
| 423 cls.ensureResolved(compiler.resolution); | 424 cls.ensureResolved(compiler.resolution); |
| 424 for (DartType supertype in cls.allSupertypes) { | 425 for (ResolutionDartType supertype in cls.allSupertypes) { |
| 425 if (supertype.isInterfaceType && | 426 if (supertype.isInterfaceType && |
| 426 !supertype.element.library.isInternalLibrary) { | 427 !supertype.element.library.isInternalLibrary) { |
| 427 return interface.asInstanceOf(supertype.element); | 428 return interface.asInstanceOf(supertype.element); |
| 428 } | 429 } |
| 429 } | 430 } |
| 430 } | 431 } |
| 431 return type; | 432 return type; |
| 432 } | 433 } |
| 433 | 434 |
| 434 /// Convert a list of strings and types to a list of elements. Types are | 435 /// Convert a list of strings and types to a list of elements. Types are |
| 435 /// converted to their corresponding element, and strings are resolved as | 436 /// converted to their corresponding element, and strings are resolved as |
| 436 /// follows: | 437 /// follows: |
| 437 /// | 438 /// |
| 438 /// First find the longest library name that is a prefix of the string, if | 439 /// First find the longest library name that is a prefix of the string, if |
| 439 /// there are none, resolve using [resolveExpression]. Otherwise, resolve the | 440 /// there are none, resolve using [resolveExpression]. Otherwise, resolve the |
| 440 /// rest of the string using [resolveLocalExpression]. | 441 /// rest of the string using [resolveLocalExpression]. |
| 441 List<Element> resolveUsageList(List list) { | 442 List<Element> resolveUsageList(List list) { |
| 442 if (list == null) return null; | 443 if (list == null) return null; |
| 443 if (list.length == 1 && list[0] == '*') { | 444 if (list.length == 1 && list[0] == '*') { |
| 444 return analyzer.wildcard; | 445 return analyzer.wildcard; |
| 445 } | 446 } |
| 446 List<Element> result = <Element>[]; | 447 List<Element> result = <Element>[]; |
| 447 for (var entry in list) { | 448 for (var entry in list) { |
| 448 if (entry is DartType) { | 449 if (entry is ResolutionDartType) { |
| 449 DartType type = entry; | 450 ResolutionDartType type = entry; |
| 450 result.add(type.element); | 451 result.add(type.element); |
| 451 } else { | 452 } else { |
| 452 String string = entry; | 453 String string = entry; |
| 453 LibraryElement libraryCandiate; | 454 LibraryElement libraryCandiate; |
| 454 String libraryNameCandiate; | 455 String libraryNameCandiate; |
| 455 for (LibraryElement l in compiler.libraryLoader.libraries) { | 456 for (LibraryElement l in compiler.libraryLoader.libraries) { |
| 456 if (l.hasLibraryName) { | 457 if (l.hasLibraryName) { |
| 457 String libraryName = l.libraryOrScriptName; | 458 String libraryName = l.libraryOrScriptName; |
| 458 if (string == libraryName) { | 459 if (string == libraryName) { |
| 459 // Found an exact match. | 460 // Found an exact match. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 // @MirrorsUsed(targets: fisk) | 565 // @MirrorsUsed(targets: fisk) |
| 565 // ^^^^ | 566 // ^^^^ |
| 566 // | 567 // |
| 567 // Instead of saying 'fisk' should pretty print the problematic constant | 568 // Instead of saying 'fisk' should pretty print the problematic constant |
| 568 // value. | 569 // value. |
| 569 return spannable; | 570 return spannable; |
| 570 } | 571 } |
| 571 return node; | 572 return node; |
| 572 } | 573 } |
| 573 } | 574 } |
| OLD | NEW |