| 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 'constants/expressions.dart'; | 7 import 'constants/expressions.dart'; |
| 8 import 'constants/values.dart' show | 8 import 'constants/values.dart' show |
| 9 ConstantValue, | 9 ConstantValue, |
| 10 ConstructedConstantValue, | 10 ConstructedConstantValue, |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 /// annotations are represented as [MirrorUsage]. | 258 /// annotations are represented as [MirrorUsage]. |
| 259 List<MirrorUsage> mirrorsUsedOnLibraryTag(LibraryElement library, | 259 List<MirrorUsage> mirrorsUsedOnLibraryTag(LibraryElement library, |
| 260 Import tag) { | 260 Import tag) { |
| 261 LibraryElement importedLibrary = library.getLibraryFromTag(tag); | 261 LibraryElement importedLibrary = library.getLibraryFromTag(tag); |
| 262 if (importedLibrary != compiler.mirrorsLibrary) { | 262 if (importedLibrary != compiler.mirrorsLibrary) { |
| 263 return null; | 263 return null; |
| 264 } | 264 } |
| 265 List<MirrorUsage> result = <MirrorUsage>[]; | 265 List<MirrorUsage> result = <MirrorUsage>[]; |
| 266 for (MetadataAnnotation metadata in tag.metadata) { | 266 for (MetadataAnnotation metadata in tag.metadata) { |
| 267 metadata.ensureResolved(compiler); | 267 metadata.ensureResolved(compiler); |
| 268 Element element = metadata.constant.value.computeType(compiler).element; | 268 Element element = |
| 269 metadata.constant.value.getType(compiler.coreTypes).element; |
| 269 if (element == compiler.mirrorsUsedClass) { | 270 if (element == compiler.mirrorsUsedClass) { |
| 270 result.add(buildUsage(metadata.constant.value)); | 271 result.add(buildUsage(metadata.constant.value)); |
| 271 } | 272 } |
| 272 } | 273 } |
| 273 return result; | 274 return result; |
| 274 } | 275 } |
| 275 | 276 |
| 276 /// Merge all [MirrorUsage] instances accross all libraries. | 277 /// Merge all [MirrorUsage] instances accross all libraries. |
| 277 MirrorUsage mergeUsages(Map<LibraryElement, List<MirrorUsage>> usageMap) { | 278 MirrorUsage mergeUsages(Map<LibraryElement, List<MirrorUsage>> usageMap) { |
| 278 Set<MirrorUsage> usagesToMerge = new Set<MirrorUsage>(); | 279 Set<MirrorUsage> usagesToMerge = new Set<MirrorUsage>(); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 : MessageKind.MIRRORS_EXPECTED_STRING_TYPE_OR_LIST; | 432 : MessageKind.MIRRORS_EXPECTED_STRING_TYPE_OR_LIST; |
| 432 compiler.reportHint( | 433 compiler.reportHint( |
| 433 node, | 434 node, |
| 434 kind, {'name': node, 'type': apiTypeOf(constant)}); | 435 kind, {'name': node, 'type': apiTypeOf(constant)}); |
| 435 return null; | 436 return null; |
| 436 } | 437 } |
| 437 } | 438 } |
| 438 | 439 |
| 439 /// Find the first non-implementation interface of constant. | 440 /// Find the first non-implementation interface of constant. |
| 440 DartType apiTypeOf(ConstantValue constant) { | 441 DartType apiTypeOf(ConstantValue constant) { |
| 441 DartType type = constant.computeType(compiler); | 442 DartType type = constant.getType(compiler.coreTypes); |
| 442 LibraryElement library = type.element.library; | 443 LibraryElement library = type.element.library; |
| 443 if (type.isInterfaceType && library.isInternalLibrary) { | 444 if (type.isInterfaceType && library.isInternalLibrary) { |
| 444 InterfaceType interface = type; | 445 InterfaceType interface = type; |
| 445 ClassElement cls = type.element; | 446 ClassElement cls = type.element; |
| 446 cls.ensureResolved(compiler); | 447 cls.ensureResolved(compiler); |
| 447 for (DartType supertype in cls.allSupertypes) { | 448 for (DartType supertype in cls.allSupertypes) { |
| 448 if (supertype.isInterfaceType | 449 if (supertype.isInterfaceType |
| 449 && !supertype.element.library.isInternalLibrary) { | 450 && !supertype.element.library.isInternalLibrary) { |
| 450 return interface.asInstanceOf(supertype.element); | 451 return interface.asInstanceOf(supertype.element); |
| 451 } | 452 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 // @MirrorsUsed(targets: fisk) | 587 // @MirrorsUsed(targets: fisk) |
| 587 // ^^^^ | 588 // ^^^^ |
| 588 // | 589 // |
| 589 // Instead of saying 'fisk' should pretty print the problematic constant | 590 // Instead of saying 'fisk' should pretty print the problematic constant |
| 590 // value. | 591 // value. |
| 591 return spannable; | 592 return spannable; |
| 592 } | 593 } |
| 593 return node; | 594 return node; |
| 594 } | 595 } |
| 595 } | 596 } |
| OLD | NEW |