[inspect][dart] Merge Node and Inspect into a single library.
As their usage is tightly coupled, it makes sense to bundle them in this way.
Hide implementation details of Node and StringProperty: the constructors are for internal use only, as it depends on knowledge of VMO indices. Client code should use the relevant public create* methods.
CF-602 #comment
Change-Id: Ibb4fd0f41bfd78751cd598bfbfe35e16507d57ce
diff --git a/public/dart/fuchsia_inspect/lib/inspect.dart b/public/dart/fuchsia_inspect/lib/inspect.dart
index 1062df6..fe3ebfd 100644
--- a/public/dart/fuchsia_inspect/lib/inspect.dart
+++ b/public/dart/fuchsia_inspect/lib/inspect.dart
@@ -4,4 +4,3 @@
/// The Inspect API for Dart.
export 'src/inspect.dart';
-export 'src/node.dart';
diff --git a/public/dart/fuchsia_inspect/lib/src/inspect.dart b/public/dart/fuchsia_inspect/lib/src/inspect.dart
index fda669b..c74b161 100644
--- a/public/dart/fuchsia_inspect/lib/src/inspect.dart
+++ b/public/dart/fuchsia_inspect/lib/src/inspect.dart
@@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+library topaz.public.dart.fuchsia_inspect.inspect;
+
import 'package:fuchsia_services/services.dart';
import 'package:meta/meta.dart';
-import 'node.dart';
import 'vmo_writer.dart';
+part 'node.dart';
+
const int _defaultVmoSizeBytes = 256 * 1024;
/// Inspect exposes a structured tree of internal component state in a VMO.
@@ -29,7 +32,7 @@
/// injection of fakes for testing.
@visibleForTesting
Inspect.internal(this._writer) {
- _root = Node(_writer.rootNode, _writer);
+ _root = Node._(_writer.rootNode, _writer);
}
/// The root [Node] of this Inspect tree.
diff --git a/public/dart/fuchsia_inspect/lib/src/node.dart b/public/dart/fuchsia_inspect/lib/src/node.dart
index 80d6619..83af153 100644
--- a/public/dart/fuchsia_inspect/lib/src/node.dart
+++ b/public/dart/fuchsia_inspect/lib/src/node.dart
@@ -2,15 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'package:meta/meta.dart';
-
-import 'vmo_writer.dart';
+part of 'inspect.dart';
/// A node in the [Inspect] tree that can have associated key-values (KVs).
class Node {
- // TODO(CF-602): Refactor this to hide implementation details like this index
- // and the public constructor below (since client code should only create
- // Nodes using [createChild].
/// The VMO index of this node.
@visibleForTesting
final int index;
@@ -19,14 +14,17 @@
final VmoWriter _writer;
/// Creates a [Node] with the VMO [index] and [writer].
- Node(this.index, this._writer);
+ ///
+ /// Private as an implementation detail to code that understands VMO indices.
+ /// Client code that wishes to create [Node]s should use [createChild].
+ Node._(this.index, this._writer);
/// Creates a child [Node] with [name].
///
/// This method is not idempotent: calling it multiple times with the same
/// [name] will create multiple children with the same name.
Node createChild(String name) =>
- Node(_writer.createNode(index, name), _writer);
+ Node._(_writer.createNode(index, name), _writer);
/// Creates a [StringProperty] with [name] on this node.
///
@@ -34,7 +32,7 @@
/// idempotent and calling it multiple times with the same [name] will
/// create multiple [StringProperty]s.
StringProperty createStringProperty(String name) =>
- StringProperty(name, index, _writer);
+ StringProperty._(name, index, _writer);
}
/// A VMO-backed key-value pair with a string key and string value.
@@ -52,7 +50,7 @@
bool _isRemoved = false;
/// Creates a [StringProperty] with [name] under the [parentIndex].
- StringProperty(String name, int parentIndex, this._writer)
+ StringProperty._(String name, int parentIndex, this._writer)
: index = _writer.createProperty(parentIndex, name);
/// Sets the value of this property in the VMO.
diff --git a/public/dart/fuchsia_inspect/test/inspect_test.dart b/public/dart/fuchsia_inspect/test/inspect_test.dart
index 6f911a9..80462ca 100644
--- a/public/dart/fuchsia_inspect/test/inspect_test.dart
+++ b/public/dart/fuchsia_inspect/test/inspect_test.dart
@@ -4,7 +4,7 @@
// ignore_for_file: implementation_imports
-import 'package:fuchsia_inspect/src/inspect.dart';
+import 'package:fuchsia_inspect/inspect.dart';
import 'package:fuchsia_inspect/src/vmo_writer.dart';
import 'package:test/test.dart';
diff --git a/public/dart/fuchsia_inspect/test/node_test.dart b/public/dart/fuchsia_inspect/test/node_test.dart
index 5a5e00f..dde53b4 100644
--- a/public/dart/fuchsia_inspect/test/node_test.dart
+++ b/public/dart/fuchsia_inspect/test/node_test.dart
@@ -4,7 +4,7 @@
// ignore_for_file: implementation_imports
-import 'package:fuchsia_inspect/src/node.dart';
+import 'package:fuchsia_inspect/inspect.dart';
import 'package:fuchsia_inspect/src/util.dart';
import 'package:fuchsia_inspect/src/vmo_holder.dart';
import 'package:fuchsia_inspect/src/vmo_writer.dart';
@@ -19,7 +19,8 @@
setUp(() {
vmo = FakeVmo(512);
var writer = VmoWriter(vmo);
- node = Node(writer.rootNode, writer);
+ var inspect = Inspect.internal(writer);
+ node = inspect.root;
});
test('Child nodes have unique indices from their parents', () {