Index: runtime/lib/mirrors.cc |
diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc |
index e897ab5b756b22e4e9ef9591c03ba349e858a95b..adc871db964f7a6583b15c021f1b3d33d6f871bc 100644 |
--- a/runtime/lib/mirrors.cc |
+++ b/runtime/lib/mirrors.cc |
@@ -300,6 +300,9 @@ static RawInstance* CreateClassMirror(const Class& cls, |
const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); |
+ // Non-generics always have their runtime types. Generics may or may not. |
+ ASSERT(!(cls.NumTypeParameters() == 0) || !type.IsNull()); |
siva
2013/08/28 23:12:06
The comment here is very cryptic, you probably sho
|
+ |
const Array& args = Array::Handle(Array::New(4)); |
args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
args.SetAt(1, type); |
@@ -512,11 +515,7 @@ DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) { |
GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
const Class& klass = Class::Handle(ref.GetClassReferent()); |
const Library& library = Library::Handle(klass.library()); |
- // TODO(rmacnak): Revisit when we decide what to do about |
- // reflectClass(dynamic). |
- if (library.IsNull()) { |
- return Instance::null(); |
- } |
+ ASSERT(!library.IsNull()); |
return CreateLibraryMirror(library); |
} |
@@ -632,6 +631,8 @@ DEFINE_NATIVE_ENTRY(LibraryMirror_members, 2) { |
Object& entry = Object::Handle(); |
DictionaryIterator entries(library); |
+ AbstractType& type = AbstractType::Handle(); |
+ |
while (entries.HasNext()) { |
entry = entries.GetNext(); |
if (entry.IsClass()) { |
@@ -641,9 +642,13 @@ DEFINE_NATIVE_ENTRY(LibraryMirror_members, 2) { |
if (!klass.IsCanonicalSignatureClass() && |
!klass.IsDynamicClass() && |
!RawObject::IsImplementationClassId(klass.id())) { |
- member_mirror = CreateClassMirror(klass, |
- AbstractType::Handle(), |
- owner_mirror); |
+ if (klass.NumTypeParameters() == 0) { |
+ // Include runtime type for non-generics only. |
+ type = RawTypeOfClass(klass); |
+ } else { |
+ type = AbstractType::null(); |
+ } |
+ member_mirror = CreateClassMirror(klass, type, owner_mirror); |
member_mirrors.Add(member_mirror); |
} |
} else if (entry.IsField()) { |
@@ -713,7 +718,11 @@ DEFINE_NATIVE_ENTRY(ClassMirror_type_arguments, 1) { |
DEFINE_NATIVE_ENTRY(TypeVariableMirror_owner, 1) { |
GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); |
- return CreateClassMirror(Class::Handle(param.parameterized_class()), |
+ const Class& owner = Class::Handle(param.parameterized_class()); |
+ // The owner of a type variable must be a generic class: pass a null runtime |
+ // type to get a mirror on the declaration. |
+ ASSERT(owner.NumTypeParameters() != 0); |
+ return CreateClassMirror(owner, |
AbstractType::Handle(), |
Instance::null_instance()); |
} |
@@ -1278,9 +1287,13 @@ DEFINE_NATIVE_ENTRY(MethodMirror_owner, 1) { |
if (owner.IsTopLevel()) { |
return CreateLibraryMirror(Library::Handle(owner.library())); |
} |
- return CreateClassMirror(owner, |
- AbstractType::Handle(), |
- Object::null_instance()); |
+ |
+ AbstractType& type = AbstractType::Handle(); |
+ if (owner.NumTypeParameters() == 0) { |
+ // Include runtime type for non-generics only. |
+ type = RawTypeOfClass(owner); |
+ } |
+ return CreateClassMirror(owner, type, Object::null_instance()); |
} |