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

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

Issue 242363004: pkg/docgen: moved model classes into minilibs (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cl nits 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
(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.variable;
6
7 import '../exports/source_mirrors.dart';
8
9 import '../library_helpers.dart';
10
11 import 'class.dart';
12 import 'doc_gen_type.dart';
13 import 'dummy_mirror.dart';
14 import 'indexable.dart';
15 import 'owned_indexable.dart';
16
17
18 /// A class containing properties of a Dart variable.
19 class Variable extends OwnedIndexable {
20
21 bool isFinal;
22 bool isStatic;
23 bool isConst;
24 DocGenType type;
25 String _variableName;
26
27 factory Variable(String variableName, VariableMirror mirror,
28 Indexable owner) {
29 var variable = getDocgenObject(mirror);
30 if (variable is DummyMirror) {
31 return new Variable._(variableName, mirror, owner);
32 }
33 return variable;
34 }
35
36 Variable._(this._variableName, VariableMirror mirror, Indexable owner) :
37 super(mirror, owner) {
38 isFinal = mirror.isFinal;
39 isStatic = mirror.isStatic;
40 isConst = mirror.isConst;
41 type = new DocGenType(mirror.type, owner.owningLibrary);
42 }
43
44 String get name => _variableName;
45
46 /// Generates a map describing the [Variable] object.
47 Map toMap() => {
48 'name': name,
49 'qualifiedName': qualifiedName,
50 'comment': comment,
51 'final': isFinal,
52 'static': isStatic,
53 'constant': isConst,
54 'type': new List.filled(1, type.toMap()),
55 'annotations': annotations.map((a) => a.toMap()).toList()
56 };
57
58 String get typeName => 'property';
59
60 get comment {
61 if (commentField != null) return commentField;
62 if (owner is Class) {
63 (owner as Class).ensureComments();
64 }
65 return super.comment;
66 }
67
68 String findElementInScope(String name) {
69 var lookupFunc = determineLookupFunc(name);
70 var result = lookupFunc(mirror, name);
71 if (result != null) {
72 result = getDocgenObject(result);
73 if (result is DummyMirror) return packagePrefix + result.docName;
74 return result.packagePrefix + result.docName;
75 }
76
77 if (owner != null) {
78 var result = owner.findElementInScope(name);
79 if (result != null) {
80 return result;
81 }
82 }
83 return super.findElementInScope(name);
84 }
85
86 bool isValidMirror(DeclarationMirror mirror) => mirror is VariableMirror;
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698