Skip to content

Commit

Permalink
Merge pull request #17 from DrMarcII/master
Browse files Browse the repository at this point in the history
Fixes suggested by reviewers.
  • Loading branch information
DrMarcII committed Dec 11, 2014
2 parents 021a1e3 + 62a60fe commit 9853692
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
34 changes: 20 additions & 14 deletions dart/lib/src/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ abstract class BasePageLoader implements PageLoader {
}
}

typedef T _LazyFunction<T>();

class _Lazy<T> implements Lazy<T> {
final _LazyFunction _call;

_Lazy(this._call);

T call() => _call();
}

class _ClassInfo {

static final Map<ClassMirror, _ClassInfo> _classInfoCache = <ClassMirror,
Expand Down Expand Up @@ -242,22 +252,18 @@ abstract class _FieldInfo {
}

// Inject PageLoader fields
if (type.simpleName == const Symbol('PageLoader')) {
if (type.simpleName == #PageLoader) {
return new _InjectedPageLoaderFieldInfo(name);
}

var isFunction = false;
if (type.simpleName == const Symbol('Lazy')) {
if (type.simpleName == #Lazy) {
isFunction = true;
if (type.typeArguments.isNotEmpty) {
type = type.typeArguments.single;
} else {
type = null;
}
type = type.typeArguments.isNotEmpty ? type.typeArguments.single : null;
} else if (type is TypedefMirror) {
isFunction = true;
type = (type as TypedefMirror).referent.returnType;
} else if (type.simpleName == const Symbol('Function')) {
} else if (type.simpleName == #Function) {
isFunction = true;
type = null;
}
Expand All @@ -281,7 +287,7 @@ abstract class _FieldInfo {
} else if (datum is Filter) {
filters.add(datum);
} else if (datum is Returns) {
if (type != null && type.simpleName != const Symbol('dynamic')) {
if (type != null && type.simpleName != #dynamic) {
throw new PageLoaderException(
'Field type is not compatible with Returns');
}
Expand All @@ -300,11 +306,11 @@ abstract class _FieldInfo {
implicitDisplayFiltering = false;
}
}
if (type != null && type.simpleName == const Symbol('List')) {
if (type != null && type.simpleName == #List) {
isList = true;
type = type.typeArguments.isNotEmpty ? type.typeArguments.single : null;
}
if (type == null || type.simpleName == const Symbol('dynamic')) {
if (type == null || type.simpleName == #dynamic) {
type = reflectClass(PageLoaderElement);
}

Expand Down Expand Up @@ -363,7 +369,7 @@ class _FinderSingleFieldInfo extends _FinderFieldInfo {
@override
calculateFieldValue(PageLoaderElement context, BasePageLoader loader) {
var element = _getElement(context, _finder, _filters, _isOptional);
if (_instanceType.simpleName != const Symbol('PageLoaderElement') &&
if (_instanceType.simpleName != #PageLoaderElement &&
element != null) {
element = loader._getInstance(_instanceType, element);
}
Expand All @@ -384,7 +390,7 @@ class _FinderListFieldInfo extends _FinderFieldInfo {
@override
calculateFieldValue(PageLoaderElement context, BasePageLoader loader) {
List elements = _getElements(context, _finder, _filters);
if (_instanceType.simpleName != const Symbol('PageLoaderElement')) {
if (_instanceType.simpleName != #PageLoaderElement) {
elements = elements.map(
(element) => loader._getInstance(_instanceType, element)).toList();
}
Expand All @@ -402,7 +408,7 @@ class _FinderFunctionFieldInfo extends _FinderFieldInfo {

@override
calculateFieldValue(PageLoaderElement context, BasePageLoader loader) {
return new Lazy(() => _impl.calculateFieldValue(context, loader));
return new _Lazy(() => _impl.calculateFieldValue(context, loader));
}
}

Expand Down
9 changes: 2 additions & 7 deletions dart/lib/src/interfaces.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ import 'package:matcher/matcher.dart';

import 'dart:collection';

class Lazy<T> implements Function {

final Function _load;

Lazy(this._load);

T call() => _load();
abstract class Lazy<T> {
T call();
}

abstract class PageLoader {
Expand Down
2 changes: 1 addition & 1 deletion dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pageloader
version: 1.2.2
version: 1.2.2+1
author: Marc Fisher II
description: Supports the creation of page objects that can be shared between in-browser tests and WebDriver tests.
environment:
Expand Down

0 comments on commit 9853692

Please sign in to comment.