Chromium Code Reviews| Index: runtime/lib/mirrors_impl.dart |
| =================================================================== |
| --- runtime/lib/mirrors_impl.dart (revision 10918) |
| +++ runtime/lib/mirrors_impl.dart (working copy) |
| @@ -261,8 +261,8 @@ |
| MethodMirror _function; |
| MethodMirror function() => _function; |
| - String source() { |
| - throw new NotImplementedException('ClosureMirror.source() not implemented'); |
| + String get source() { |
| + throw new NotImplementedException('ClosureMirror.source not implemented'); |
| } |
| Future<ObjectMirror> apply(List<Object> positionalArguments, |
| @@ -320,23 +320,43 @@ |
| _LocalClassMirrorImpl(ref, |
| this.simpleName, |
| this.isClass, |
| - this._library, |
| + this._owner, |
| this._superclass, |
| this._superinterfaces, |
| this._defaultFactory, |
| this.members) : super(ref) {} |
| final String simpleName; |
| - final bool isClass; |
| - var _library; |
| - LibraryMirror get library() { |
| - if (_library is _LazyLibraryMirror) { |
| - _library = _library.resolve(mirrors); |
| + String _qualifiedName = null; |
| + String get qualifiedName() { |
| + if (_qualifiedName === null) { |
| + _qualifiedName = '${owner.qualifiedName}.${simpleName}'; |
| } |
| - return _library; |
| + return _qualifiedName; |
| } |
| + var _owner; |
| + DeclarationMirror get owner() { |
| + if (_owner is! Mirror) { |
| + _owner = _owner.resolve(mirrors); |
| + } |
| + return _owner; |
| + } |
| + |
| + bool get isPrivate() { |
| + return simpleName.startsWith('_'); |
| + } |
| + |
| + final bool isTopLevel = true; |
| + |
| + SourceLocation get location() { |
| + throw new NotImplementedException( |
| + 'ClassMirror.location not yet implemented'); |
| + } |
| + |
| + final bool isClass; |
| + |
| var _superclass; |
| ClassMirror get superclass() { |
| if (_superclass is _LazyClassMirror) { |
| @@ -366,10 +386,13 @@ |
| return _defaultFactory; |
| } |
| - final Map<String, ClassMirror> members; |
| + final Map<String, Mirror> members; |
| - Map<String, ClassMirror> _methods = null; |
| - Map<String, ClassMirror> _variables = null; |
| + Map<String, MethodMirror> _methods = null; |
| + Map<String, MethodMirror> _constructors = null; |
| + Map<String, MethodMirror> _getters = null; |
| + Map<String, MethodMirror> _setters = null; |
| + Map<String, VariableMirror> _variables = null; |
| Map<String, MethodMirror> get methods() { |
| if (_methods == null) { |
| @@ -379,6 +402,30 @@ |
| return _methods; |
| } |
| + Map<String, MethodMirror> get constructors() { |
| + if (_constructors == null) { |
| + _constructors = filterMap(methods, |
| + (key, value) => (value.isConstructor)); |
| + } |
| + return _constructors; |
| + } |
| + |
| + Map<String, MethodMirror> get getters() { |
| + if (_getters == null) { |
| + _getters = filterMap(methods, |
| + (key, value) => (value.isGetter)); |
| + } |
| + return _getters; |
| + } |
| + |
| + Map<String, MethodMirror> get setters() { |
| + if (_setters == null) { |
| + _setters = filterMap(methods, |
| + (key, value) => (value.isSetter)); |
| + } |
| + return _setters; |
| + } |
| + |
| Map<String, VariableMirror> get variables() { |
| if (_variables == null) { |
| _variables = filterMap(members, |
| @@ -387,13 +434,33 @@ |
| return _variables; |
| } |
| + List<TypeVariableMirror> get typeVariables() { |
| + throw new NotImplementedException( |
| + 'ClassMirror.typeVariables not yet implemented'); |
| + } |
| + |
| + List<TypeMirror> get typeArguments() { |
| + throw new NotImplementedException( |
| + 'ClassMirror.typeArguments not yet implemented'); |
| + } |
| + |
| + bool isUnboundType() { |
| + throw new NotImplementedException( |
| + 'ClassMirror.isUnboundType not yet implemented'); |
| + } |
| + |
| + ClassMirror unboundType() { |
| + throw new NotImplementedException( |
| + 'ClassMirror.unboundType not yet implemented'); |
| + } |
| + |
| String toString() { |
| return "ClassMirror on '$simpleName'"; |
| } |
| Future<InstanceMirror> newInstance(String constructorName, |
| - List positionalArguments, |
| - [Map<String,Dynamic> namedArguments]) { |
| + List positionalArguments, |
| + [Map<String,Dynamic> namedArguments]) { |
| if (namedArguments !== null) { |
| throw new NotImplementedException('named arguments not implemented'); |
| } |
| @@ -434,12 +501,34 @@ |
| this.members) : super(ref) {} |
| final String simpleName; |
| + |
| + String get qualifiedName() { |
|
cshapiro
2012/08/21 03:16:05
// The simple name and the qualified name are the
turnidge
2012/08/21 18:00:49
Switched all short functions (that can fit on one
|
| + // The simple name and the qualified name are the same for a library. |
| + return simpleName; |
| + } |
| + |
| + // Always null for libraries. |
| + final DeclarationMirror owner = null; |
| + |
| + // Always false for libraries. |
| + final bool isPrivate = false; |
| + |
| + // Always false for libraries. |
| + final bool isTopLevel = false; |
| + |
| + SourceLocation get location() { |
| + throw new NotImplementedException( |
| + 'LibraryMirror.location not yet implemented'); |
| + } |
| + |
| final String url; |
| - final Map<String, ClassMirror> members; |
| + final Map<String, Mirror> members; |
| Map<String, ClassMirror> _classes = null; |
| - Map<String, ClassMirror> _functions = null; |
| - Map<String, ClassMirror> _variables = null; |
| + Map<String, MethodMirror> _functions = null; |
| + Map<String, MethodMirror> _getters = null; |
| + Map<String, MethodMirror> _setters = null; |
| + Map<String, VariableMirror> _variables = null; |
| Map<String, ClassMirror> get classes() { |
| if (_classes == null) { |
| @@ -457,6 +546,22 @@ |
| return _functions; |
| } |
| + Map<String, MethodMirror> get getters() { |
| + if (_getters == null) { |
| + _getters = filterMap(functions, |
| + (key, value) => (value.isGetter)); |
| + } |
| + return _getters; |
| + } |
| + |
| + Map<String, MethodMirror> get setters() { |
| + if (_setters == null) { |
| + _setters = filterMap(functions, |
| + (key, value) => (value.isSetter)); |
| + } |
| + return _setters; |
| + } |
| + |
| Map<String, VariableMirror> get variables() { |
| if (_variables == null) { |
| _variables = filterMap(members, |
| @@ -487,31 +592,79 @@ |
| final String simpleName; |
| + String _qualifiedName = null; |
| + String get qualifiedName() { |
| + if (_qualifiedName === null) { |
| + _qualifiedName = '${owner.qualifiedName}.${simpleName}'; |
| + } |
| + return _qualifiedName; |
| + } |
| + |
| var _owner; |
| - Mirror get owner() { |
| + DeclarationMirror get owner() { |
| if (_owner is! Mirror) { |
| _owner = _owner.resolve(mirrors); |
| } |
| return _owner; |
| } |
| - final List<ParameterMirror> parameters; |
| + bool get isPrivate() { |
| + return simpleName.startsWith('_') || constructorName.startsWith('_'); |
| + } |
| bool get isTopLevel() { |
| return owner is LibraryMirror; |
| } |
| + SourceLocation get location() { |
| + throw new NotImplementedException( |
| + 'MethodMirror.location not yet implemented'); |
| + } |
| + |
| + TypeMirror get returnType() { |
| + throw new NotImplementedException( |
| + 'MethodMirror.returnType not yet implemented'); |
| + } |
| + |
| + final List<ParameterMirror> parameters; |
| + |
| final bool isStatic; |
| + final bool isAbstract; |
| - bool get isMethod() { |
| + bool get isRegularMethod() { |
| return !isGetter && !isSetter && !isConstructor; |
| } |
| - final bool isAbstract; |
| + TypeMirror get isOperator() { |
| + throw new NotImplementedException( |
| + 'MethodMirror.isOperator not yet implemented'); |
| + } |
| + |
| final bool isGetter; |
| final bool isSetter; |
| final bool isConstructor; |
| + var _constructorName = null; |
| + String get constructorName() { |
| + if (_constructorName === null) { |
| + if (!isConstructor) { |
| + _constructorName = ''; |
| + } else { |
| + var parts = simpleName.split('.'); |
| + if (parts.length > 2) { |
| + throw new MirrorException( |
| + 'Internal error in MethodMirror.constructorName: ' |
| + 'malformed name <$simpleName>'); |
| + } else if (parts.length == 2) { |
| + _constructorName = parts[1]; |
| + } else { |
| + _constructorName = ''; |
| + } |
| + } |
| + } |
| + return _constructorName; |
| + } |
| + |
| final bool isConstConstructor; |
| final bool isGenerativeConstructor; |
| final bool isRedirectingConstructor; |
| @@ -522,19 +675,6 @@ |
| } |
| } |
| -class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl |
| - implements ParameterMirror { |
| - // TODO(rmacnak): Fill these mirrors will real information |
| - _LocalParameterMirrorImpl(this.isOptional) |
| - : super(null, null, false, false) {} |
| - |
| - final bool isOptional; |
| - |
| - TypeMirror get type() => null; |
| - String get defaultValue() => null; |
| - bool get hasDefaultValue() => null; |
| -} |
| - |
| class _LocalVariableMirrorImpl extends _LocalMirrorImpl |
| implements VariableMirror { |
| _LocalVariableMirrorImpl(this.simpleName, |
| @@ -544,18 +684,40 @@ |
| final String simpleName; |
| + String _qualifiedName = null; |
| + String get qualifiedName() { |
| + if (_qualifiedName === null) { |
| + _qualifiedName = '${owner.qualifiedName}.${simpleName}'; |
| + } |
| + return _qualifiedName; |
| + } |
| + |
| var _owner; |
| - Mirror get owner() { |
| + DeclarationMirror get owner() { |
| if (_owner is! Mirror) { |
| _owner = _owner.resolve(mirrors); |
| } |
| return _owner; |
| } |
| + bool get isPrivate() { |
| + return simpleName.startsWith('_'); |
| + } |
| + |
| bool get isTopLevel() { |
| return owner is LibraryMirror; |
| } |
| + SourceLocation get location() { |
| + throw new NotImplementedException( |
| + 'MethodMirror.location not yet implemented'); |
| + } |
| + |
| + TypeMirror get returnType() { |
| + throw new NotImplementedException( |
| + 'MethodMirror.returnType not yet implemented'); |
| + } |
| + |
| final bool isStatic; |
| final bool isFinal; |
| @@ -564,6 +726,19 @@ |
| } |
| } |
| +class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl |
| + implements ParameterMirror { |
| + // TODO(rmacnak): Fill these mirrors will real information |
|
cshapiro
2012/08/21 03:16:05
Still relevant? Should this be a TODO(turnidge)?
turnidge
2012/08/21 18:00:49
Will change these unimplemented accessors to throw
|
| + _LocalParameterMirrorImpl(this.isOptional) |
| + : super(null, null, false, false) {} |
| + |
| + final bool isOptional; |
| + |
| + TypeMirror get type() => null; |
| + String get defaultValue() => null; |
| + bool get hasDefaultValue() => null; |
| +} |
| + |
| class _Mirrors { |
| // Does a port refer to our local isolate? |
| static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort'; |