| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library docgen.models.dummy_mirror; | |
| 6 | |
| 7 import '../exports/mirrors_util.dart' as dart2js_util; | |
| 8 import '../exports/source_mirrors.dart'; | |
| 9 | |
| 10 import '../library_helpers.dart'; | |
| 11 | |
| 12 import 'indexable.dart'; | |
| 13 import 'model_helpers.dart'; | |
| 14 | |
| 15 /// For types that we do not explicitly create or have not yet created in our | |
| 16 /// entity map (like core types). | |
| 17 class DummyMirror implements Indexable { | |
| 18 final DeclarationMirror mirror; | |
| 19 /// The library that contains this element, if any. Used as a hint to help | |
| 20 /// determine which object we're referring to when looking up this mirror in | |
| 21 /// our map. | |
| 22 final Indexable owner; | |
| 23 | |
| 24 DummyMirror(this.mirror, [this.owner]); | |
| 25 | |
| 26 String get docName { | |
| 27 if (mirror is LibraryMirror) { | |
| 28 return getLibraryDocName(mirror); | |
| 29 } | |
| 30 var mirrorOwner = mirror.owner; | |
| 31 if (mirrorOwner == null) return dart2js_util.qualifiedNameOf(mirror); | |
| 32 var simpleName = dart2js_util.nameOf(mirror); | |
| 33 if (mirror is MethodMirror && (mirror as MethodMirror).isConstructor) { | |
| 34 // We name constructors specially -- repeating the class name and a | |
| 35 // "-" to separate the constructor from its name (if any). | |
| 36 simpleName = '${dart2js_util.nameOf(mirrorOwner)}-$simpleName'; | |
| 37 } | |
| 38 return getDocgenObject(mirrorOwner, owner).docName + '.' + | |
| 39 simpleName; | |
| 40 } | |
| 41 | |
| 42 bool get isPrivate => mirror.isPrivate; | |
| 43 | |
| 44 String get packageName { | |
| 45 var libMirror = _getOwningLibraryFromMirror(mirror); | |
| 46 if (libMirror != null) { | |
| 47 return getPackageName(libMirror); | |
| 48 } | |
| 49 return ''; | |
| 50 } | |
| 51 | |
| 52 String get packagePrefix => packageName == null || packageName.isEmpty ? | |
| 53 '' : '$packageName/'; | |
| 54 | |
| 55 // This is a known incomplete implementation of Indexable | |
| 56 // overriding noSuchMethod to remove static warnings | |
| 57 noSuchMethod(Invocation invocation) { | |
| 58 throw new UnimplementedError(invocation.memberName.toString()); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 LibraryMirror _getOwningLibraryFromMirror(DeclarationMirror mirror) { | |
| 63 if (mirror == null) return null; | |
| 64 if (mirror is LibraryMirror) return mirror; | |
| 65 return _getOwningLibraryFromMirror(mirror.owner); | |
| 66 } | |
| OLD | NEW |