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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: pkg/docgen/lib/src/models/variable.dart
diff --git a/pkg/docgen/lib/src/models/variable.dart b/pkg/docgen/lib/src/models/variable.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f89bef156048a00bdc084c9b4a24a81401e67668
--- /dev/null
+++ b/pkg/docgen/lib/src/models/variable.dart
@@ -0,0 +1,87 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library docgen.models.variable;
+
+import '../exports/source_mirrors.dart';
+
+import '../library_helpers.dart';
+
+import 'class.dart';
+import 'doc_gen_type.dart';
+import 'dummy_mirror.dart';
+import 'indexable.dart';
+import 'owned_indexable.dart';
+
+
+/// A class containing properties of a Dart variable.
+class Variable extends OwnedIndexable {
+
+ bool isFinal;
+ bool isStatic;
+ bool isConst;
+ DocGenType type;
+ String _variableName;
+
+ factory Variable(String variableName, VariableMirror mirror,
+ Indexable owner) {
+ var variable = getDocgenObject(mirror);
+ if (variable is DummyMirror) {
+ return new Variable._(variableName, mirror, owner);
+ }
+ return variable;
+ }
+
+ Variable._(this._variableName, VariableMirror mirror, Indexable owner) :
+ super(mirror, owner) {
+ isFinal = mirror.isFinal;
+ isStatic = mirror.isStatic;
+ isConst = mirror.isConst;
+ type = new DocGenType(mirror.type, owner.owningLibrary);
+ }
+
+ String get name => _variableName;
+
+ /// Generates a map describing the [Variable] object.
+ Map toMap() => {
+ 'name': name,
+ 'qualifiedName': qualifiedName,
+ 'comment': comment,
+ 'final': isFinal,
+ 'static': isStatic,
+ 'constant': isConst,
+ 'type': new List.filled(1, type.toMap()),
+ 'annotations': annotations.map((a) => a.toMap()).toList()
+ };
+
+ String get typeName => 'property';
+
+ get comment {
+ if (commentField != null) return commentField;
+ if (owner is Class) {
+ (owner as Class).ensureComments();
+ }
+ return super.comment;
+ }
+
+ String findElementInScope(String name) {
+ var lookupFunc = determineLookupFunc(name);
+ var result = lookupFunc(mirror, name);
+ if (result != null) {
+ result = getDocgenObject(result);
+ if (result is DummyMirror) return packagePrefix + result.docName;
+ return result.packagePrefix + result.docName;
+ }
+
+ if (owner != null) {
+ var result = owner.findElementInScope(name);
+ if (result != null) {
+ return result;
+ }
+ }
+ return super.findElementInScope(name);
+ }
+
+ bool isValidMirror(DeclarationMirror mirror) => mirror is VariableMirror;
+}

Powered by Google App Engine
This is Rietveld 408576698