| 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 | 7 import 'common/tasks.dart' show |
| 8 CompilerTask; | 8 CompilerTask; |
| 9 import 'compile_time_constants.dart' show | 9 import 'compile_time_constants.dart' show |
| 10 ConstantCompiler; | 10 ConstantCompiler; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 /// Find @MirrorsUsed annotations on the given import [tag] in [library]. The | 254 /// Find @MirrorsUsed annotations on the given import [tag] in [library]. The |
| 255 /// annotations are represented as [MirrorUsage]. | 255 /// annotations are represented as [MirrorUsage]. |
| 256 List<MirrorUsage> mirrorsUsedOnLibraryTag(LibraryElement library, | 256 List<MirrorUsage> mirrorsUsedOnLibraryTag(LibraryElement library, |
| 257 ImportElement import) { | 257 ImportElement import) { |
| 258 LibraryElement importedLibrary = import.importedLibrary; | 258 LibraryElement importedLibrary = import.importedLibrary; |
| 259 if (importedLibrary != compiler.mirrorsLibrary) { | 259 if (importedLibrary != compiler.mirrorsLibrary) { |
| 260 return null; | 260 return null; |
| 261 } | 261 } |
| 262 List<MirrorUsage> result = <MirrorUsage>[]; | 262 List<MirrorUsage> result = <MirrorUsage>[]; |
| 263 for (MetadataAnnotation metadata in import.metadata) { | 263 for (MetadataAnnotation metadata in import.metadata) { |
| 264 metadata.ensureResolved(compiler); | 264 metadata.ensureResolved(compiler.resolution); |
| 265 ConstantValue value = | 265 ConstantValue value = |
| 266 compiler.constants.getConstantValue(metadata.constant); | 266 compiler.constants.getConstantValue(metadata.constant); |
| 267 Element element = value.getType(compiler.coreTypes).element; | 267 Element element = value.getType(compiler.coreTypes).element; |
| 268 if (element == compiler.mirrorsUsedClass) { | 268 if (element == compiler.mirrorsUsedClass) { |
| 269 result.add(buildUsage(value)); | 269 result.add(buildUsage(value)); |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 return result; | 272 return result; |
| 273 } | 273 } |
| 274 | 274 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 } | 433 } |
| 434 } | 434 } |
| 435 | 435 |
| 436 /// Find the first non-implementation interface of constant. | 436 /// Find the first non-implementation interface of constant. |
| 437 DartType apiTypeOf(ConstantValue constant) { | 437 DartType apiTypeOf(ConstantValue constant) { |
| 438 DartType type = constant.getType(compiler.coreTypes); | 438 DartType type = constant.getType(compiler.coreTypes); |
| 439 LibraryElement library = type.element.library; | 439 LibraryElement library = type.element.library; |
| 440 if (type.isInterfaceType && library.isInternalLibrary) { | 440 if (type.isInterfaceType && library.isInternalLibrary) { |
| 441 InterfaceType interface = type; | 441 InterfaceType interface = type; |
| 442 ClassElement cls = type.element; | 442 ClassElement cls = type.element; |
| 443 cls.ensureResolved(compiler); | 443 cls.ensureResolved(compiler.resolution); |
| 444 for (DartType supertype in cls.allSupertypes) { | 444 for (DartType supertype in cls.allSupertypes) { |
| 445 if (supertype.isInterfaceType | 445 if (supertype.isInterfaceType |
| 446 && !supertype.element.library.isInternalLibrary) { | 446 && !supertype.element.library.isInternalLibrary) { |
| 447 return interface.asInstanceOf(supertype.element); | 447 return interface.asInstanceOf(supertype.element); |
| 448 } | 448 } |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 return type; | 451 return type; |
| 452 } | 452 } |
| 453 | 453 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 return current; | 546 return current; |
| 547 } | 547 } |
| 548 | 548 |
| 549 /// Helper method to lookup members in a [ScopeContainerElement]. If | 549 /// Helper method to lookup members in a [ScopeContainerElement]. If |
| 550 /// [element] is not a ScopeContainerElement, return null. | 550 /// [element] is not a ScopeContainerElement, return null. |
| 551 Element findLocalMemberIn(Element element, String name) { | 551 Element findLocalMemberIn(Element element, String name) { |
| 552 if (element is ScopeContainerElement) { | 552 if (element is ScopeContainerElement) { |
| 553 ScopeContainerElement scope = element; | 553 ScopeContainerElement scope = element; |
| 554 if (element.isClass) { | 554 if (element.isClass) { |
| 555 ClassElement cls = element; | 555 ClassElement cls = element; |
| 556 cls.ensureResolved(compiler); | 556 cls.ensureResolved(compiler.resolution); |
| 557 } | 557 } |
| 558 return scope.localLookup(name); | 558 return scope.localLookup(name); |
| 559 } | 559 } |
| 560 return null; | 560 return null; |
| 561 } | 561 } |
| 562 | 562 |
| 563 /// Attempt to find a [Spannable] corresponding to constant. | 563 /// Attempt to find a [Spannable] corresponding to constant. |
| 564 Spannable positionOf(ConstantValue constant) { | 564 Spannable positionOf(ConstantValue constant) { |
| 565 Node node; | 565 Node node; |
| 566 elements.forEachConstantNode((Node n, ConstantExpression c) { | 566 elements.forEachConstantNode((Node n, ConstantExpression c) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 584 // @MirrorsUsed(targets: fisk) | 584 // @MirrorsUsed(targets: fisk) |
| 585 // ^^^^ | 585 // ^^^^ |
| 586 // | 586 // |
| 587 // Instead of saying 'fisk' should pretty print the problematic constant | 587 // Instead of saying 'fisk' should pretty print the problematic constant |
| 588 // value. | 588 // value. |
| 589 return spannable; | 589 return spannable; |
| 590 } | 590 } |
| 591 return node; | 591 return node; |
| 592 } | 592 } |
| 593 } | 593 } |
| OLD | NEW |