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

Unified Diff: pkg/docgen/lib/src/models/class.dart

Issue 258753004: Use UnmodifiableMapView in compiler (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 side-by-side diff with in-line comments
Download patch
Index: pkg/docgen/lib/src/models/class.dart
diff --git a/pkg/docgen/lib/src/models/class.dart b/pkg/docgen/lib/src/models/class.dart
index 555b1ddb9cd6f22284e6edd4712ded743dbb72fe..4bcbb65433c9a0f7a1881a2d0e99ad055e93024b 100644
--- a/pkg/docgen/lib/src/models/class.dart
+++ b/pkg/docgen/lib/src/models/class.dart
@@ -4,6 +4,8 @@
library docgen.models.clazz;
+import 'dart:collection';
+
import '../exports/dart2js_mirrors.dart' as dart2js_mirrors;
import '../exports/mirrors_util.dart' as dart2js_util;
import '../exports/source_mirrors.dart';
@@ -86,8 +88,8 @@ class Class extends OwnedIndexable<dart2js_mirrors.Dart2JsInterfaceTypeMirror>
interfaces = superinterfaces.toList();
variables = createVariables(
dart2js_util.variablesOf(classMirror.declarations), this);
- methods = createMethods(classMirror.declarations.values.where(
- (mirror) => mirror is MethodMirror), this);
+ methods = createMethods(new TypeOfIterable<MethodMirror>(
herhut 2014/04/28 08:24:41 Maybe rather expose [anyMethodOf] and use that. Wo
kevmoo 2014/04/28 09:23:01 Done.
+ classMirror.declarations.values), this);
// Tell superclass that you are a subclass, unless you are not
// visible or an intermediary mixin class.
@@ -243,3 +245,29 @@ class Class extends OwnedIndexable<dart2js_mirrors.Dart2JsInterfaceTypeMirror>
bool isValidMirror(DeclarationMirror mirror) => mirror is ClassMirror;
}
+
+class TypeOfIterable<TTarget> extends IterableBase<TTarget> {
herhut 2014/04/28 08:24:41 Nit: I prefer using just T for the type variable b
+ final Iterable _source;
+
+ TypeOfIterable(this._source);
+
+ Iterator<TTarget> get iterator =>
+ new _TypeOfIterator<TTarget>(_source.iterator);
+}
+
+class _TypeOfIterator<TTarget> implements Iterator<TTarget> {
+ final Iterator _source;
+
+ TTarget get current => _source.current as TTarget;
herhut 2014/04/28 08:24:41 Do you really need the runtime check via as here?
+
+ _TypeOfIterator(this._source);
+
+ bool moveNext() {
+ while(_source.moveNext()) {
+ if (_source.current is TTarget) {
+ return true;
+ }
+ }
+ return false;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698