mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
b101a7d002
Change-Id: Ib33169c3e0ffc870915c189404074a1dea472546 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196548 Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: Leaf Petersen <leafp@google.com>
71 lines
3 KiB
Dart
71 lines
3 KiB
Dart
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// @dart = 2.9
|
|
|
|
import 'dart:mirrors';
|
|
import 'package:expect/expect.dart';
|
|
|
|
class A<T> {}
|
|
|
|
class B<T extends A> extends A implements C {
|
|
A m(A a) {}
|
|
A field;
|
|
}
|
|
|
|
class C<S, T> {}
|
|
|
|
class D extends A<int> {}
|
|
|
|
main() {
|
|
ClassMirror aDecl = reflectClass(A);
|
|
ClassMirror bDecl = reflectClass(B);
|
|
ClassMirror cDecl = reflectClass(C);
|
|
TypeMirror aInstance = reflect(new A()).type;
|
|
TypeMirror aInstanceDynamic = reflect(new A<dynamic>()).type;
|
|
TypeMirror dInstance = reflect(new D()).type;
|
|
TypeMirror cInstance = reflect(new C<dynamic, dynamic>()).type;
|
|
TypeMirror cNestedInstance = reflect(new C<C, dynamic>()).type;
|
|
TypeMirror cTypeArgument = cNestedInstance.typeArguments.first;
|
|
TypeMirror superA = bDecl.superclass;
|
|
TypeMirror superC = bDecl.superinterfaces.single;
|
|
MethodMirror m = bDecl.declarations[#m] as MethodMirror;
|
|
VariableMirror field = bDecl.declarations[#field] as VariableMirror;
|
|
TypeMirror returnTypeA = m.returnType;
|
|
TypeMirror parameterTypeA = m.parameters.first.type;
|
|
TypeMirror fieldTypeA = field.type;
|
|
TypeMirror upperBoundA = bDecl.typeVariables.single.upperBound;
|
|
TypeMirror dynamicMirror = currentMirrorSystem().dynamicType;
|
|
|
|
Expect.isTrue(aDecl.isOriginalDeclaration);
|
|
Expect.isTrue(reflect(dInstance).type.isOriginalDeclaration);
|
|
Expect.isFalse(aInstance.isOriginalDeclaration);
|
|
Expect.isFalse(aInstanceDynamic.isOriginalDeclaration);
|
|
Expect.isFalse(superA.isOriginalDeclaration);
|
|
Expect.isFalse(superC.isOriginalDeclaration);
|
|
Expect.isFalse(returnTypeA.isOriginalDeclaration);
|
|
Expect.isFalse(parameterTypeA.isOriginalDeclaration);
|
|
Expect.isFalse(fieldTypeA.isOriginalDeclaration);
|
|
Expect.isFalse(upperBoundA.isOriginalDeclaration);
|
|
Expect.isFalse(cInstance.isOriginalDeclaration);
|
|
Expect.isFalse(cNestedInstance.isOriginalDeclaration);
|
|
Expect.isFalse(cTypeArgument.isOriginalDeclaration);
|
|
|
|
Expect.isTrue(aDecl.typeArguments.isEmpty);
|
|
Expect.isTrue(dInstance.typeArguments.isEmpty);
|
|
Expect.equals(dynamicMirror, aInstance.typeArguments.single);
|
|
Expect.equals(dynamicMirror, aInstanceDynamic.typeArguments.single);
|
|
Expect.equals(dynamicMirror, superA.typeArguments.single);
|
|
Expect.equals(dynamicMirror, superC.typeArguments.first);
|
|
Expect.equals(dynamicMirror, superC.typeArguments.last);
|
|
Expect.equals(dynamicMirror, returnTypeA.typeArguments.single);
|
|
Expect.equals(dynamicMirror, parameterTypeA.typeArguments.single);
|
|
Expect.equals(dynamicMirror, fieldTypeA.typeArguments.single);
|
|
Expect.equals(dynamicMirror, upperBoundA.typeArguments.single);
|
|
Expect.equals(dynamicMirror, cInstance.typeArguments.first);
|
|
Expect.equals(dynamicMirror, cInstance.typeArguments.last);
|
|
Expect.equals(dynamicMirror, cNestedInstance.typeArguments.last);
|
|
Expect.equals(dynamicMirror, cTypeArgument.typeArguments.first);
|
|
Expect.equals(dynamicMirror, cTypeArgument.typeArguments.last);
|
|
}
|