Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1003)

Side by Side Diff: pkg/docgen/lib/src/models/dummy_mirror.dart

Issue 245673002: pkg/docgen: a bunch of cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 docgen.models.dummy_mirror; 5 library docgen.models.dummy_mirror;
6 6
7 import '../exports/mirrors_util.dart' as dart2js_util; 7 import '../exports/mirrors_util.dart' as dart2js_util;
8 import '../exports/source_mirrors.dart'; 8 import '../exports/source_mirrors.dart';
9 9
10 import '../library_helpers.dart'; 10 import '../library_helpers.dart';
11 11
12 import 'indexable.dart'; 12 import 'indexable.dart';
13 import 'model_helpers.dart'; 13 import 'model_helpers.dart';
14 14
15 /// For types that we do not explicitly create or have not yet created in our 15 /// For types that we do not explicitly create or have not yet created in our
16 /// entity map (like core types). 16 /// entity map (like core types).
17 class DummyMirror implements Indexable { 17 class DummyMirror implements Indexable {
18 final DeclarationMirror mirror; 18 final DeclarationMirror mirror;
19 /// The library that contains this element, if any. Used as a hint to help 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 20 /// determine which object we're referring to when looking up this mirror in
21 /// our map. 21 /// our map.
22 final Indexable owner; 22 final Indexable owner;
23 23
24 DummyMirror(this.mirror, [this.owner]); 24 DummyMirror(this.mirror, [this.owner]);
25 25
26 String get docName { 26 String get docName {
27 if (mirror == null) return '';
kevmoo 2014/04/21 19:22:19 With the change to Library have it's own "fake" In
28 if (mirror is LibraryMirror) { 27 if (mirror is LibraryMirror) {
29 return dart2js_util.qualifiedNameOf(mirror).replaceAll('.', '-'); 28 return getLibraryDocName(mirror);
kevmoo 2014/04/21 19:22:19 Moved to shared method since this logic also exist
30 } 29 }
31 var mirrorOwner = mirror.owner; 30 var mirrorOwner = mirror.owner;
32 if (mirrorOwner == null) return dart2js_util.qualifiedNameOf(mirror); 31 if (mirrorOwner == null) return dart2js_util.qualifiedNameOf(mirror);
33 var simpleName = dart2js_util.nameOf(mirror); 32 var simpleName = dart2js_util.nameOf(mirror);
34 if (mirror is MethodMirror && (mirror as MethodMirror).isConstructor) { 33 if (mirror is MethodMirror && (mirror as MethodMirror).isConstructor) {
35 // We name constructors specially -- repeating the class name and a 34 // We name constructors specially -- repeating the class name and a
36 // "-" to separate the constructor from its name (if any). 35 // "-" to separate the constructor from its name (if any).
37 simpleName = '${dart2js_util.nameOf(mirrorOwner)}-$simpleName'; 36 simpleName = '${dart2js_util.nameOf(mirrorOwner)}-$simpleName';
38 } 37 }
39 return getDocgenObject(mirrorOwner, owner).docName + '.' + 38 return getDocgenObject(mirrorOwner, owner).docName + '.' +
40 simpleName; 39 simpleName;
41 } 40 }
42 41
43 bool get isPrivate => mirror == null ? false : mirror.isPrivate; 42 bool get isPrivate => mirror.isPrivate;
44 43
45 String get packageName { 44 String get packageName {
46 var libMirror = _getOwningLibraryFromMirror(mirror); 45 var libMirror = _getOwningLibraryFromMirror(mirror);
47 if (libMirror != null) { 46 if (libMirror != null) {
48 return getPackageName(libMirror); 47 return getPackageName(libMirror);
49 } 48 }
50 return ''; 49 return '';
51 } 50 }
52 51
53 String get packagePrefix => packageName == null || packageName.isEmpty ? 52 String get packagePrefix => packageName == null || packageName.isEmpty ?
54 '' : '$packageName/'; 53 '' : '$packageName/';
55 54
56 LibraryMirror _getOwningLibraryFromMirror(DeclarationMirror mirror) { 55 // This is a known incomplete implementation of Indexable
57 if (mirror is LibraryMirror) return mirror; 56 // overriding noSuchMethod to remove static warnings
58 if (mirror == null) return null;
59 return _getOwningLibraryFromMirror(mirror.owner);
60 }
61
62 noSuchMethod(Invocation invocation) { 57 noSuchMethod(Invocation invocation) {
63 throw new UnimplementedError(invocation.memberName.toString()); 58 throw new UnimplementedError(invocation.memberName.toString());
64 } 59 }
65 } 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698