Format tests/lib/mirrors using 3.8 style.

Change-Id: I9f922f8a4106f993c63b55ebbe3c54ea999cbbd4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426287
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
This commit is contained in:
Robert Nystrom
2025-05-05 02:31:55 -07:00
committed by Commit Queue
parent 36117c443c
commit d6ef495a9a
92 changed files with 1389 additions and 818 deletions
+3 -1
View File
@@ -14,5 +14,7 @@ abstract class Foo {}
void main() {
expect(
'Class(s(Foo) in s(test.abstract_test), top-level)', reflectClass(Foo));
'Class(s(Foo) in s(test.abstract_test), top-level)',
reflectClass(Foo),
);
}
@@ -30,7 +30,7 @@ main() {
'C',
'D',
'E',
'F'
'F',
];
var symbols = <dynamic>[];
for (var high in digits) {
+5 -2
View File
@@ -30,8 +30,11 @@ main() {
var symbol = const Symbol('a');
var requiredParameters = [1];
var optionalParameters = new Map<Symbol, int>()..[symbol] = 42;
Invocation i =
Function.apply(new G(), requiredParameters, optionalParameters);
Invocation i = Function.apply(
new G(),
requiredParameters,
optionalParameters,
);
Expect.equals(const Symbol('call'), i.memberName);
Expect.listEquals(requiredParameters, i.positionalArguments);
@@ -72,11 +72,15 @@ void badClassStaticInvoke() {
Map<String, String> map = Map<String, String>();
map['bar'] = 'Hello world!';
final cm = reflectClass(Foo);
Expect.throwsTypeError(() => cm.invoke(#baz, [
map
], {
#bar: {'boo': 'bah'}
}));
Expect.throwsTypeError(
() => cm.invoke(
#baz,
[map],
{
#bar: {'boo': 'bah'},
},
),
);
}
void badStaticInvoke() {
@@ -6,6 +6,9 @@
// "mixin", "mixin class" or the test should be left at 2.19.
// @dart=2.19
// Don't let the formatter change the location of things.
// dart format off
part of test.class_location;
class ClassInOtherFile {}
@@ -6,6 +6,9 @@
// "mixin", "mixin class" or the test should be left at 2.19.
// @dart=2.19
// Don't let the formatter change the location of things.
// dart format off
library test.class_location;
import "dart:mirrors";
@@ -52,21 +55,21 @@ main() {
String otherSuffix = 'class_mirror_location_other.dart';
// This file.
expectLocation(reflectClass(ClassInMainFile), mainSuffix, 12, 1);
expectLocation(reflectClass(SpaceIndentedInMainFile), mainSuffix, 13, 3);
expectLocation(reflectClass(TabIndentedInMainFile), mainSuffix, 14, 2);
expectLocation(reflectClass(AbstractClass), mainSuffix, 16, 1);
expectLocation(reflectType(Predicate), mainSuffix, 17, 1);
expectLocation(reflectClass(MA), mainSuffix, 21, 1);
expectLocation(reflectClass(MA2), mainSuffix, 22, 1);
expectLocation(reflectClass(WithMetadata), mainSuffix, 26, 1);
expectLocation(reflectClass(Enum), mainSuffix, 29, 1);
expectLocation(reflectClass(AnnotatedEnum), mainSuffix, 31, 1);
expectLocation(reflectClass(ClassInMainFile), mainSuffix, 19, 1);
expectLocation(reflectClass(SpaceIndentedInMainFile), mainSuffix, 20, 3);
expectLocation(reflectClass(TabIndentedInMainFile), mainSuffix, 21, 2);
expectLocation(reflectClass(AbstractClass), mainSuffix, 23, 1);
expectLocation(reflectType(Predicate), mainSuffix, 24, 1);
expectLocation(reflectClass(MA), mainSuffix, 28, 1);
expectLocation(reflectClass(MA2), mainSuffix, 29, 1);
expectLocation(reflectClass(WithMetadata), mainSuffix, 34, 1);
expectLocation(reflectClass(Enum), mainSuffix, 36, 1);
expectLocation(reflectClass(AnnotatedEnum), mainSuffix, 39, 1);
// Another part.
expectLocation(reflectClass(ClassInOtherFile), otherSuffix, 7, 1);
expectLocation(reflectClass(SpaceIndentedInOtherFile), otherSuffix, 9, 3);
expectLocation(reflectClass(TabIndentedInOtherFile), otherSuffix, 11, 2);
expectLocation(reflectClass(ClassInOtherFile), otherSuffix, 14, 1);
expectLocation(reflectClass(SpaceIndentedInOtherFile), otherSuffix, 16, 3);
expectLocation(reflectClass(TabIndentedInOtherFile), otherSuffix, 18, 2);
// Synthetic classes.
Expect.isNull(reflectClass(MA).superclass!.location);
@@ -106,7 +106,9 @@ void testE(Env env) {
Expect.isFalse(mapRAndHelperOfString.isOriginalDeclaration);
Expect.equals(eR, mapRAndHelperOfString.typeArguments.first);
Expect.equals(
env.getHelperOfString(), mapRAndHelperOfString.typeArguments.last);
env.getHelperOfString(),
mapRAndHelperOfString.typeArguments.last,
);
}
void testF(Env env) {
@@ -14,12 +14,21 @@ class C {
main() {
LibraryMirror thisLibrary = reflectClass(C).owner as LibraryMirror;
Expect.equals(thisLibrary.declarations[#topLevelMethod],
(reflect(topLevelMethod) as ClosureMirror).function, "topLevel");
Expect.equals(
thisLibrary.declarations[#topLevelMethod],
(reflect(topLevelMethod) as ClosureMirror).function,
"topLevel",
);
Expect.equals(reflectClass(C).declarations[#staticMethod],
(reflect(C.staticMethod) as ClosureMirror).function, "static");
Expect.equals(
reflectClass(C).declarations[#staticMethod],
(reflect(C.staticMethod) as ClosureMirror).function,
"static",
);
Expect.equals(reflectClass(C).declarations[#instanceMethod],
(reflect(new C().instanceMethod) as ClosureMirror).function, "instance");
Expect.equals(
reflectClass(C).declarations[#instanceMethod],
(reflect(new C().instanceMethod) as ClosureMirror).function,
"instance",
);
}
@@ -16,15 +16,9 @@ class A {
class B implements A {
final _x, _y, _z;
B([x = 'x', y = 'y'])
: _x = x,
_y = y,
_z = null;
B([x = 'x', y = 'y']) : _x = x, _y = y, _z = null;
B.more([x = 'x', y = 'y', z = 'z'])
: _x = x,
_y = y,
_z = z;
B.more([x = 'x', y = 'y', z = 'z']) : _x = x, _y = y, _z = z;
toString() => 'B(x=$_x, y=$_y, z=$_z)';
}
+22 -12
View File
@@ -45,12 +45,15 @@ main() {
expect('{Foo: Method(s(Foo) in s(Foo), constructor)}', fooConstructors);
expect('{Bar: Method(s(Bar) in s(Bar), constructor)}', barConstructors);
expect('{Baz.named: Method(s(Baz.named) in s(Baz), constructor)}',
bazConstructors);
expect(
'{Biz: Method(s(Biz) in s(Biz), constructor),'
' Biz.named: Method(s(Biz.named) in s(Biz), constructor)}',
bizConstructors);
'{Baz.named: Method(s(Baz.named) in s(Baz), constructor)}',
bazConstructors,
);
expect(
'{Biz: Method(s(Biz) in s(Biz), constructor),'
' Biz.named: Method(s(Biz.named) in s(Biz), constructor)}',
bizConstructors,
);
print(bizConstructors);
expect('[]', fooConstructors.values.single.parameters);
@@ -61,13 +64,20 @@ main() {
}
expect(
'[s()]', fooConstructors.values.map((m) => m.constructorName).toList());
'[s()]',
fooConstructors.values.map((m) => m.constructorName).toList(),
);
expect(
'[s()]', barConstructors.values.map((m) => m.constructorName).toList());
expect('[s(named)]',
bazConstructors.values.map((m) => m.constructorName).toList());
'[s()]',
barConstructors.values.map((m) => m.constructorName).toList(),
);
expect(
'[s(), s(named)]',
bizConstructors.values.map((m) => m.constructorName).toList()
..sort(compareSymbols));
'[s(named)]',
bazConstructors.values.map((m) => m.constructorName).toList(),
);
expect(
'[s(), s(named)]',
bizConstructors.values.map((m) => m.constructorName).toList()
..sort(compareSymbols),
);
}
+4 -4
View File
@@ -89,7 +89,7 @@ class Superclass<S> {
Superclass.inheritedGenerativeConstructor(this.inheritedInstanceVariable);
Superclass.inheritedRedirectingConstructor(x)
: this.inheritedGenerativeConstructor(x * 2);
: this.inheritedGenerativeConstructor(x * 2);
factory Superclass.inheritedNormalFactory(y) =>
new Superclass.inheritedRedirectingConstructor(y * 3);
factory Superclass.inheritedRedirectingFactory(z) =
@@ -97,7 +97,7 @@ class Superclass<S> {
Superclass._inheritedGenerativeConstructor(this._inheritedInstanceVariable);
Superclass._inheritedRedirectingConstructor(x)
: this._inheritedGenerativeConstructor(x * 2);
: this._inheritedGenerativeConstructor(x * 2);
factory Superclass._inheritedNormalFactory(y) =>
new Superclass._inheritedRedirectingConstructor(y * 3);
factory Superclass._inheritedRedirectingFactory(z) =
@@ -132,13 +132,13 @@ abstract class Class<C> extends Superclass<C>
static _staticMethod() => null;
Class.generativeConstructor(this.instanceVariable)
: super.inheritedGenerativeConstructor(0);
: super.inheritedGenerativeConstructor(0);
Class.redirectingConstructor(x) : this.generativeConstructor(x * 2);
factory Class.normalFactory(y) => new ConcreteClass(y * 3);
factory Class.redirectingFactory(z) = Class<C>.normalFactory;
Class._generativeConstructor(this._instanceVariable)
: super._inheritedGenerativeConstructor(0);
: super._inheritedGenerativeConstructor(0);
Class._redirectingConstructor(x) : this._generativeConstructor(x * 2);
factory Class._normalFactory(y) => new ConcreteClass(y * 3);
factory Class._redirectingFactory(z) = Class<C>._normalFactory;
@@ -40,7 +40,7 @@ class Superclass<S> {
Superclass.inheritedGenerativeConstructor(this.inheritedInstanceVariable);
Superclass.inheritedRedirectingConstructor(x)
: this.inheritedGenerativeConstructor(x * 2);
: this.inheritedGenerativeConstructor(x * 2);
factory Superclass.inheritedNormalFactory(y) =>
new Superclass.inheritedRedirectingConstructor(y * 3);
factory Superclass.inheritedRedirectingFactory(z) =
@@ -63,7 +63,7 @@ abstract class Class<C> extends Superclass<C> implements Interface<C> {
static staticMethod() => null;
Class.generativeConstructor(this.instanceVariable)
: super.inheritedGenerativeConstructor(0);
: super.inheritedGenerativeConstructor(0);
Class.redirectingConstructor(x) : this.generativeConstructor(x * 2);
factory Class.normalFactory(y) => new ConcreteClass(y * 3);
factory Class.redirectingFactory(z) = Class<C>.normalFactory;
+11 -6
View File
@@ -15,21 +15,26 @@ main() {
var classDeclarations = reflectClass(C).declarations;
Expect.isTrue(classDeclarations is Map<Symbol, DeclarationMirror>);
Expect.isTrue(classDeclarations.values is Iterable<DeclarationMirror>);
Expect.isTrue(classDeclarations.values.where((x) => true)
is Iterable<DeclarationMirror>);
Expect.isTrue(
classDeclarations.values.where((x) => true) is Iterable<DeclarationMirror>,
);
Expect.isFalse(classDeclarations is Map<Symbol, MethodMirror>);
Expect.isFalse(classDeclarations.values is Iterable<MethodMirror>);
Expect.isFalse(
classDeclarations.values.where((x) => true) is Iterable<MethodMirror>);
classDeclarations.values.where((x) => true) is Iterable<MethodMirror>,
);
var libraryDeclarations =
(reflectClass(C).owner as LibraryMirror).declarations;
Expect.isTrue(libraryDeclarations is Map<Symbol, DeclarationMirror>);
Expect.isTrue(libraryDeclarations.values is Iterable<DeclarationMirror>);
Expect.isTrue(libraryDeclarations.values.where((x) => true)
is Iterable<DeclarationMirror>);
Expect.isTrue(
libraryDeclarations.values.where((x) => true)
is Iterable<DeclarationMirror>,
);
Expect.isFalse(libraryDeclarations is Map<Symbol, ClassMirror>);
Expect.isFalse(libraryDeclarations.values is Iterable<ClassMirror>);
Expect.isFalse(
libraryDeclarations.values.where((x) => true) is Iterable<ClassMirror>);
libraryDeclarations.values.where((x) => true) is Iterable<ClassMirror>,
);
}
@@ -20,10 +20,9 @@ class E {
String foo() {
String c = reflectClass(E).metadata[0].invoke(#toString, []).reflectee;
String d = reflectClass(E)
.declarations[#f]!
.metadata[0]
.invoke(#toString, []).reflectee;
String d = reflectClass(
E,
).declarations[#f]!.metadata[0].invoke(#toString, []).reflectee;
InstanceMirror i = currentMirrorSystem().findLibrary(#main).metadata[0];
String a = i.invoke(#toString, []).reflectee;
String b = i.getField(#b).invoke(#toString, []).reflectee;
@@ -19,9 +19,12 @@ class FakeFunctionNSM {
class C {
get fakeFunctionCall => new FakeFunctionCall();
get fakeFunctionNSM => new FakeFunctionNSM();
get closure => (x, y) => '2 $this $x $y';
get closureOpt => (x, y, [z, w]) => '3 $this $x $y $z $w';
get closureNamed => (x, y, {z, w}) => '4 $this $x $y $z $w';
get closure =>
(x, y) => '2 $this $x $y';
get closureOpt =>
(x, y, [z, w]) => '3 $this $x $y $z $w';
get closureNamed =>
(x, y, {z, w}) => '4 $this $x $y $z $w';
get notAClosure => 'Not a closure';
noSuchMethod(msg) => 'DNU';
+22 -14
View File
@@ -11,8 +11,9 @@ main() async {
IsolateMirror isolate = currentMirrorSystem().isolate;
print(isolate);
LibraryMirror success =
await isolate.loadUri(Uri.parse("dynamic_load_success.dart"));
LibraryMirror success = await isolate.loadUri(
Uri.parse("dynamic_load_success.dart"),
);
print(success);
InstanceMirror result = success.invoke(#advanceCounter, []);
print(result);
@@ -21,8 +22,9 @@ main() async {
print(result);
Expect.equals(2, result.reflectee);
LibraryMirror success2 =
await isolate.loadUri(Uri.parse("dynamic_load_success.dart"));
LibraryMirror success2 = await isolate.loadUri(
Uri.parse("dynamic_load_success.dart"),
);
print(success2);
Expect.equals(success, success2);
result = success2.invoke(#advanceCounter, []);
@@ -42,10 +44,12 @@ main() async {
error = e;
}
print(error);
Expect.isTrue(error.toString().contains("Cannot open file") ||
error.toString().contains("file not found") ||
error.toString().contains("No such file or directory") ||
error.toString().contains("The system cannot find the file specified"));
Expect.isTrue(
error.toString().contains("Cannot open file") ||
error.toString().contains("file not found") ||
error.toString().contains("No such file or directory") ||
error.toString().contains("The system cannot find the file specified"),
);
Expect.isTrue(error.toString().contains("DOES_NOT_EXIST"));
Future<LibraryMirror> bad_load2 = isolate.loadUri(Uri.parse("dart:_builtin"));
@@ -60,16 +64,18 @@ main() async {
Expect.isTrue(error2.toString().contains("dart:_builtin"));
// Check error is not sticky.
LibraryMirror success3 =
await isolate.loadUri(Uri.parse("dynamic_load_success.dart"));
LibraryMirror success3 = await isolate.loadUri(
Uri.parse("dynamic_load_success.dart"),
);
print(success3);
Expect.equals(success, success3);
result = success3.invoke(#advanceCounter, []);
print(result);
Expect.equals(4, result.reflectee); // Same library, same state.
Future<LibraryMirror> bad_load3 =
isolate.loadUri(Uri.parse("dynamic_load_error.dart"));
Future<LibraryMirror> bad_load3 = isolate.loadUri(
Uri.parse("dynamic_load_error.dart"),
);
var error3;
try {
await bad_load3;
@@ -77,7 +83,9 @@ main() async {
error3 = e;
}
print(error3);
Expect.isTrue(error3.toString().contains("library url expected") ||
error3.toString().contains("Error: Expected a String"));
Expect.isTrue(
error3.toString().contains("library url expected") ||
error3.toString().contains("Error: Expected a String"),
);
Expect.isTrue(error3.toString().contains("dynamic_load_error.dart"));
}
+36 -29
View File
@@ -18,17 +18,17 @@ main() {
Expect.isTrue(reflectClass(Suite).isEnum);
Expect.isFalse(reflectClass(Suite).isAbstract);
Expect.equals(
0,
reflectClass(Suite)
.declarations
.values
.where((d) => d is MethodMirror && d.isConstructor)
.length);
0,
reflectClass(Suite).declarations.values
.where((d) => d is MethodMirror && d.isConstructor)
.length,
);
Expect.equals(
reflectClass(Suite),
(reflectClass(C).owner as LibraryMirror).declarations[#Suite],
"found in library");
reflectClass(Suite),
(reflectClass(C).owner as LibraryMirror).declarations[#Suite],
"found in library",
);
Expect.equals(reflectClass(Suite), reflect(Suite.CLUBS).type);
@@ -38,28 +38,35 @@ main() {
Expect.equals(3, reflect(Suite.HEARTS).getField(#index).reflectee);
Expect.equals(
"Suite.CLUBS", reflect(Suite.CLUBS).invoke(#toString, []).reflectee);
Expect.equals("Suite.DIAMONDS",
reflect(Suite.DIAMONDS).invoke(#toString, []).reflectee);
"Suite.CLUBS",
reflect(Suite.CLUBS).invoke(#toString, []).reflectee,
);
Expect.equals(
"Suite.SPADES", reflect(Suite.SPADES).invoke(#toString, []).reflectee);
"Suite.DIAMONDS",
reflect(Suite.DIAMONDS).invoke(#toString, []).reflectee,
);
Expect.equals(
"Suite.HEARTS", reflect(Suite.HEARTS).invoke(#toString, []).reflectee);
"Suite.SPADES",
reflect(Suite.SPADES).invoke(#toString, []).reflectee,
);
Expect.equals(
"Suite.HEARTS",
reflect(Suite.HEARTS).invoke(#toString, []).reflectee,
);
Expect.setEquals(
[
'Variable(s(index) in s(Suite), final)',
'Variable(s(CLUBS) in s(Suite), static, final)',
'Variable(s(DIAMONDS) in s(Suite), static, final)',
'Variable(s(SPADES) in s(Suite), static, final)',
'Variable(s(HEARTS) in s(Suite), static, final)',
'Variable(s(values) in s(Suite), static, final)',
'Method(s(hashCode) in s(Suite), getter)',
'Method(s(toString) in s(Suite))'
],
reflectClass(Suite)
.declarations
.values
.where((d) => !d.isPrivate)
.map(stringify));
[
'Variable(s(index) in s(Suite), final)',
'Variable(s(CLUBS) in s(Suite), static, final)',
'Variable(s(DIAMONDS) in s(Suite), static, final)',
'Variable(s(SPADES) in s(Suite), static, final)',
'Variable(s(HEARTS) in s(Suite), static, final)',
'Variable(s(values) in s(Suite), static, final)',
'Method(s(hashCode) in s(Suite), getter)',
'Method(s(toString) in s(Suite))',
],
reflectClass(
Suite,
).declarations.values.where((d) => !d.isPrivate).map(stringify),
);
}
+42 -29
View File
@@ -34,14 +34,20 @@ checkEquality(List<Map<String, Object?>> equivalenceClasses) {
equivalenceClass.forEach((otherName, otherMember) {
// Reflexivity, symmetry and transitivity.
Expect.equals(member, otherMember, "$name == $otherName");
Expect.equals(member.hashCode, otherMember.hashCode,
"$name.hashCode == $otherName.hashCode");
Expect.equals(
member.hashCode,
otherMember.hashCode,
"$name.hashCode == $otherName.hashCode",
);
});
for (var otherEquivalenceClass in equivalenceClasses) {
if (otherEquivalenceClass == equivalenceClass) continue;
otherEquivalenceClass.forEach((otherName, otherMember) {
Expect.notEquals(
member, otherMember, "$name != $otherName"); // Exclusion.
member,
otherMember,
"$name != $otherName",
); // Exclusion.
// Hash codes may or may not be equal.
});
}
@@ -52,8 +58,9 @@ checkEquality(List<Map<String, Object?>> equivalenceClasses) {
void subroutine() {}
main() {
LibraryMirror thisLibrary = currentMirrorSystem()
.findLibrary(const Symbol('test.class_equality_test'));
LibraryMirror thisLibrary = currentMirrorSystem().findLibrary(
const Symbol('test.class_equality_test'),
);
var o1 = new Object();
var o2 = new Object();
@@ -66,51 +73,54 @@ main() {
{'reflect(o2)': reflect(o2), 'reflect(o2), again': reflect(o2)},
{
'reflect(badEqualityHash1)': reflect(badEqualityHash1),
'reflect(badEqualityHash1), again': reflect(badEqualityHash1)
'reflect(badEqualityHash1), again': reflect(badEqualityHash1),
},
{
'reflect(badEqualityHash2)': reflect(badEqualityHash2),
'reflect(badEqualityHash2), again': reflect(badEqualityHash2)
'reflect(badEqualityHash2), again': reflect(badEqualityHash2),
},
{'reflect(true)': reflect(true), 'reflect(true), again': reflect(true)},
{'reflect(false)': reflect(false), 'reflect(false), again': reflect(false)},
{'reflect(null)': reflect(null), 'reflect(null), again': reflect(null)},
{
'reflect(3.5+4.5)': reflect(3.5 + 4.5),
'reflect(6.5+1.5)': reflect(6.5 + 1.5)
'reflect(6.5+1.5)': reflect(6.5 + 1.5),
},
{'reflect(3+4)': reflect(3 + 4), 'reflect(6+1)': reflect(6 + 1)},
{'reflect("foo")': reflect("foo"), 'reflect("foo"), again': reflect("foo")},
{
'currentMirrorSystem().voidType': currentMirrorSystem().voidType,
'thisLibrary.declarations[#subroutine].returnType':
(thisLibrary.declarations[#subroutine] as MethodMirror).returnType
(thisLibrary.declarations[#subroutine] as MethodMirror).returnType,
},
{
'currentMirrorSystem().dynamicType': currentMirrorSystem().dynamicType,
'thisLibrary.declarations[#main].returnType':
(thisLibrary.declarations[#main] as MethodMirror).returnType
(thisLibrary.declarations[#main] as MethodMirror).returnType,
},
{
'reflectClass(A)': reflectClass(A),
'thisLibrary.declarations[#A]': thisLibrary.declarations[#A],
'reflect(new A<int>()).type.originalDeclaration':
reflect(new A<int>()).type.originalDeclaration
'reflect(new A<int>()).type.originalDeclaration': reflect(
new A<int>(),
).type.originalDeclaration,
},
{
'reflectClass(B).superclass': reflectClass(B).superclass,
'reflect(new A<int>()).type': reflect(new A<int>()).type
'reflect(new A<int>()).type': reflect(new A<int>()).type,
},
{
'reflectClass(B)': reflectClass(B),
'thisLibrary.declarations[#B]': thisLibrary.declarations[#B],
'reflect(new B()).type': reflect(new B()).type
'reflect(new B()).type': reflect(new B()).type,
},
{
'reflectClass(BadEqualityHash).declarations[#==]':
reflectClass(BadEqualityHash).declarations[#==],
'reflect(new BadEqualityHash()).type.declarations[#==]':
reflect(new BadEqualityHash()).type.declarations[#==]
'reflectClass(BadEqualityHash).declarations[#==]': reflectClass(
BadEqualityHash,
).declarations[#==],
'reflect(new BadEqualityHash()).type.declarations[#==]': reflect(
new BadEqualityHash(),
).type.declarations[#==],
},
{
'reflectClass(BadEqualityHash).declarations[#==].parameters[0]':
@@ -119,18 +129,20 @@ main() {
'reflect(new BadEqualityHash()).type.declarations[#==].parameters[0]':
(reflect(new BadEqualityHash()).type.declarations[#==]
as MethodMirror)
.parameters[0]
.parameters[0],
},
{
'reflectClass(BadEqualityHash).declarations[#count]':
reflectClass(BadEqualityHash).declarations[#count],
'reflect(new BadEqualityHash()).type.declarations[#count]':
reflect(new BadEqualityHash()).type.declarations[#count]
'reflectClass(BadEqualityHash).declarations[#count]': reflectClass(
BadEqualityHash,
).declarations[#count],
'reflect(new BadEqualityHash()).type.declarations[#count]': reflect(
new BadEqualityHash(),
).type.declarations[#count],
},
{
'reflectType(Predicate)': reflectType(Predicate),
'thisLibrary.declarations[#somePredicate].type':
(thisLibrary.declarations[#somePredicate] as VariableMirror).type
(thisLibrary.declarations[#somePredicate] as VariableMirror).type,
},
{
'reflectType(Predicate).referent':
@@ -138,13 +150,14 @@ main() {
'thisLibrary.declarations[#somePredicate].type.referent':
((thisLibrary.declarations[#somePredicate] as VariableMirror).type
as TypedefMirror)
.referent
.referent,
},
{
'reflectClass(A).typeVariables.single':
reflectClass(A).typeVariables.single,
'reflectClass(A).typeVariables.single': reflectClass(
A,
).typeVariables.single,
'reflect(new A<int>()).type.originalDeclaration.typeVariables.single':
reflect(new A<int>()).type.originalDeclaration.typeVariables.single
reflect(new A<int>()).type.originalDeclaration.typeVariables.single,
},
{'currentMirrorSystem()': currentMirrorSystem()},
{'currentMirrorSystem().isolate': currentMirrorSystem().isolate},
@@ -153,7 +166,7 @@ main() {
'reflectClass(A).owner': reflectClass(A).owner,
'reflectClass(B).owner': reflectClass(B).owner,
'reflect(new A()).type.owner': reflect(new A()).type.owner,
'reflect(new B()).type.owner': reflect(new B()).type.owner
'reflect(new B()).type.owner': reflect(new B()).type.owner,
},
]);
}
@@ -27,8 +27,10 @@ main() {
Expect.equals(7, cm.invoke(#call, [3, 4]).reflectee);
Expect.throwsNoSuchMethodError(() => cm.invoke(#call, [3]), "Wrong arity");
Expect.equals(49, cm.invoke(#method, [7]).reflectee);
Expect.throwsNoSuchMethodError(() => cm.invoke(#method, [3, 4]),
"Wrong arity");
Expect.throwsNoSuchMethodError(
() => cm.invoke(#method, [3, 4]),
"Wrong arity",
);
Expect.equals(7, cm.apply([3, 4]).reflectee);
Expect.throwsNoSuchMethodError(() => cm.apply([3]), "Wrong arity");
@@ -31,54 +31,61 @@ class A<T> {
main() {
ClassMirror cm = reflect(new A<String>()).type;
Expect.setEquals([
'Variable(s(_instanceVariable) in s(A), private)',
'Variable(s(_staticVariable) in s(A), private, static)',
'Variable(s(instanceVariable) in s(A))',
'Variable(s(staticVariable) in s(A), static)'
], cm.declarations.values.where((dm) => dm is VariableMirror).map(stringify),
'variables');
Expect.setEquals(
[
'Variable(s(_instanceVariable) in s(A), private)',
'Variable(s(_staticVariable) in s(A), private, static)',
'Variable(s(instanceVariable) in s(A))',
'Variable(s(staticVariable) in s(A), static)',
],
cm.declarations.values.where((dm) => dm is VariableMirror).map(stringify),
'variables',
);
Expect.setEquals(
[
'Method(s(_instanceGetter) in s(A), private, getter)',
'Method(s(_staticGetter) in s(A), private, static, getter)',
'Method(s(instanceGetter) in s(A), getter)',
'Method(s(staticGetter) in s(A), static, getter)'
],
cm.declarations.values
.where((dm) => dm is MethodMirror && dm.isGetter)
.map(stringify),
'getters');
[
'Method(s(_instanceGetter) in s(A), private, getter)',
'Method(s(_staticGetter) in s(A), private, static, getter)',
'Method(s(instanceGetter) in s(A), getter)',
'Method(s(staticGetter) in s(A), static, getter)',
],
cm.declarations.values
.where((dm) => dm is MethodMirror && dm.isGetter)
.map(stringify),
'getters',
);
Expect.setEquals(
[
'Method(s(_instanceSetter=) in s(A), private, setter)',
'Method(s(_staticSetter=) in s(A), private, static, setter)',
'Method(s(instanceSetter=) in s(A), setter)',
'Method(s(staticSetter=) in s(A), static, setter)'
],
cm.declarations.values
.where((dm) => dm is MethodMirror && dm.isSetter)
.map(stringify),
'setters');
[
'Method(s(_instanceSetter=) in s(A), private, setter)',
'Method(s(_staticSetter=) in s(A), private, static, setter)',
'Method(s(instanceSetter=) in s(A), setter)',
'Method(s(staticSetter=) in s(A), static, setter)',
],
cm.declarations.values
.where((dm) => dm is MethodMirror && dm.isSetter)
.map(stringify),
'setters',
);
Expect.setEquals(
[
'Method(s(_instanceMethod) in s(A), private)',
'Method(s(_staticMethod) in s(A), private, static)',
'Method(s(instanceMethod) in s(A))',
'Method(s(staticMethod) in s(A), static)'
],
cm.declarations.values
.where((dm) => dm is MethodMirror && dm.isRegularMethod)
.map(stringify),
'methods');
[
'Method(s(_instanceMethod) in s(A), private)',
'Method(s(_staticMethod) in s(A), private, static)',
'Method(s(instanceMethod) in s(A))',
'Method(s(staticMethod) in s(A), static)',
],
cm.declarations.values
.where((dm) => dm is MethodMirror && dm.isRegularMethod)
.map(stringify),
'methods',
);
Expect.setEquals(
['Method(s(A) in s(A), constructor)'],
cm.declarations.values
.where((dm) => dm is MethodMirror && dm.isConstructor)
.map(stringify),
'constructors');
['Method(s(A) in s(A), constructor)'],
cm.declarations.values
.where((dm) => dm is MethodMirror && dm.isConstructor)
.map(stringify),
'constructors',
);
}
@@ -36,17 +36,21 @@ main() {
ClassMirror collectionDecl = reflectClass(Collection);
ClassMirror serializableDecl = reflectClass(Serializable);
ClassMirror orderedCollectionDecl = reflectClass(OrderedCollection);
ClassMirror abstractOrderedCollectionDecl =
reflectClass(AbstractOrderedCollection);
ClassMirror customOrderedCollectionDecl =
reflectClass(CustomOrderedCollection);
ClassMirror abstractOrderedCollectionDecl = reflectClass(
AbstractOrderedCollection,
);
ClassMirror customOrderedCollectionDecl = reflectClass(
CustomOrderedCollection,
);
ClassMirror orderedIntegerCollection = reflectClass(OrderedIntegerCollection);
ClassMirror customOrderedIntegerCollection =
reflectClass(CustomOrderedIntegerCollection);
ClassMirror customOrderedIntegerCollection = reflectClass(
CustomOrderedIntegerCollection,
);
ClassMirror serializerDecl = reflectClass(Serializer);
ClassMirror collectionSerializerDecl = reflectClass(CollectionSerializer);
ClassMirror orderedCollectionSerializerDecl =
reflectClass(OrderedCollectionSerializer);
ClassMirror orderedCollectionSerializerDecl = reflectClass(
OrderedCollectionSerializer,
);
ClassMirror orderedCollectionOfInt = orderedIntegerCollection.superclass!;
ClassMirror customOrderedCollectionOfInt =
@@ -55,8 +59,9 @@ main() {
ClassMirror serializerOfOrderedCollection =
orderedCollectionSerializerDecl.superclass!;
ClassMirror collectionOfDynamic = reflect(new Collection()).type;
ClassMirror orderedCollectionOfDynamic =
reflect(new OrderedCollection()).type;
ClassMirror orderedCollectionOfDynamic = reflect(
new OrderedCollection(),
).type;
ClassMirror collectionWithSerializableOfOrderedCollection =
orderedCollectionDecl.superclass!;
@@ -77,7 +82,8 @@ main() {
Expect.isFalse(serializerOfOrderedCollection.isOriginalDeclaration);
Expect.isFalse(collectionOfDynamic.isOriginalDeclaration);
Expect.isFalse(
collectionWithSerializableOfOrderedCollection.isOriginalDeclaration);
collectionWithSerializableOfOrderedCollection.isOriginalDeclaration,
);
TypeVariableMirror rFromSerializer = serializerDecl.typeVariables.single;
ClassMirror serializableOfR = rFromSerializer.upperBound as ClassMirror;
@@ -34,15 +34,18 @@ main() {
TypedefMirror transformOfR =
(reflectClass(C).declarations[#transformOfR] as VariableMirror).type
as TypedefMirror;
TypedefMirror transformOfDouble = (reflect(new C<double>())
.type
.declarations[#transformOfR] as VariableMirror)
.type as TypedefMirror;
TypedefMirror transformOfDouble =
(reflect(new C<double>()).type.declarations[#transformOfR]
as VariableMirror)
.type
as TypedefMirror;
TypeVariableMirror tFromGenericPredicate =
reflectTypeDeclaration(GenericPredicate).typeVariables[0];
TypeVariableMirror sFromGenericTransform =
reflectTypeDeclaration(GenericTransform).typeVariables[0];
TypeVariableMirror tFromGenericPredicate = reflectTypeDeclaration(
GenericPredicate,
).typeVariables[0];
TypeVariableMirror sFromGenericTransform = reflectTypeDeclaration(
GenericTransform,
).typeVariables[0];
TypeVariableMirror rFromC = reflectClass(C).typeVariables[0];
// Typedefs.
@@ -63,7 +66,8 @@ main() {
typeArguments(transformOfDouble, [reflectClass(double)]);
Expect.isTrue(
reflectTypeDeclaration(NonGenericPredicate).isOriginalDeclaration);
reflectTypeDeclaration(NonGenericPredicate).isOriginalDeclaration,
);
Expect.isTrue(reflectTypeDeclaration(GenericPredicate).isOriginalDeclaration);
Expect.isTrue(reflectTypeDeclaration(GenericTransform).isOriginalDeclaration);
Expect.isFalse(predicateOfNum.isOriginalDeclaration);
@@ -89,38 +93,56 @@ main() {
typeArguments(transformOfDouble.referent, []);
// Function types are always non-generic. Only the typedef is generic.
Expect.isTrue(reflectTypeDeclaration(NonGenericPredicate)
.referent
.isOriginalDeclaration);
Expect.isTrue(
reflectTypeDeclaration(GenericPredicate).referent.isOriginalDeclaration);
reflectTypeDeclaration(NonGenericPredicate).referent.isOriginalDeclaration,
);
Expect.isTrue(
reflectTypeDeclaration(GenericTransform).referent.isOriginalDeclaration);
reflectTypeDeclaration(GenericPredicate).referent.isOriginalDeclaration,
);
Expect.isTrue(
reflectTypeDeclaration(GenericTransform).referent.isOriginalDeclaration,
);
Expect.isTrue(predicateOfNum.referent.isOriginalDeclaration);
Expect.isTrue(transformOfString.referent.isOriginalDeclaration);
Expect.isTrue(transformOfR.referent.isOriginalDeclaration);
Expect.isTrue(transformOfDouble.referent.isOriginalDeclaration);
Expect.equals(reflectClass(num),
reflectTypeDeclaration(NonGenericPredicate).referent.parameters[0].type);
Expect.equals(tFromGenericPredicate,
reflectTypeDeclaration(GenericPredicate).referent.parameters[0].type);
Expect.equals(sFromGenericTransform,
reflectTypeDeclaration(GenericTransform).referent.parameters[0].type);
Expect.equals(
reflectClass(num),
reflectTypeDeclaration(NonGenericPredicate).referent.parameters[0].type,
);
Expect.equals(
tFromGenericPredicate,
reflectTypeDeclaration(GenericPredicate).referent.parameters[0].type,
);
Expect.equals(
sFromGenericTransform,
reflectTypeDeclaration(GenericTransform).referent.parameters[0].type,
);
Expect.equals(reflectClass(num), predicateOfNum.referent.parameters[0].type);
Expect.equals(
reflectClass(String), transformOfString.referent.parameters[0].type);
reflectClass(String),
transformOfString.referent.parameters[0].type,
);
Expect.equals(rFromC, transformOfR.referent.parameters[0].type);
Expect.equals(
reflectClass(double), transformOfDouble.referent.parameters[0].type);
reflectClass(double),
transformOfDouble.referent.parameters[0].type,
);
Expect.equals(reflectClass(bool),
reflectTypeDeclaration(NonGenericPredicate).referent.returnType);
Expect.equals(reflectClass(bool),
reflectTypeDeclaration(GenericPredicate).referent.returnType);
Expect.equals(sFromGenericTransform,
reflectTypeDeclaration(GenericTransform).referent.returnType);
Expect.equals(
reflectClass(bool),
reflectTypeDeclaration(NonGenericPredicate).referent.returnType,
);
Expect.equals(
reflectClass(bool),
reflectTypeDeclaration(GenericPredicate).referent.returnType,
);
Expect.equals(
sFromGenericTransform,
reflectTypeDeclaration(GenericTransform).referent.returnType,
);
Expect.equals(reflectClass(bool), predicateOfNum.referent.returnType);
Expect.equals(reflectClass(String), transformOfString.referent.returnType);
Expect.equals(rFromC, transformOfR.referent.returnType);
+3 -1
View File
@@ -8,7 +8,9 @@ import 'package:expect/expect.dart';
typeParameters(mirror, parameterNames) {
Expect.listEquals(
parameterNames, mirror.typeVariables.map((v) => v.simpleName).toList());
parameterNames,
mirror.typeVariables.map((v) => v.simpleName).toList(),
);
}
typeArguments(mirror, argumentMirrors) {
@@ -17,15 +17,19 @@ checkClass(classMirror) {
Expect.notEquals(null, classMirror.owner);
Expect.isTrue(classMirror.owner is LibraryMirror);
if (!isAnonymousMixinApplication(classMirror)) {
Expect.equals(classMirror.originalDeclaration,
classMirror.owner.declarations[classMirror.simpleName]);
Expect.equals(
classMirror.originalDeclaration,
classMirror.owner.declarations[classMirror.simpleName],
);
} else {
Expect.isNull(classMirror.owner.declarations[classMirror.simpleName]);
}
Expect.isTrue(classMirror.superinterfaces is List);
if (classMirror.superclass == null) {
Expect.isTrue((reflectClass(Object) == classMirror) ||
(classMirror.toString() == "ClassMirror on 'FutureOr'"));
Expect.isTrue(
(reflectClass(Object) == classMirror) ||
(classMirror.toString() == "ClassMirror on 'FutureOr'"),
);
} else {
checkClass(classMirror.superclass);
}
+3 -1
View File
@@ -39,7 +39,9 @@ testPrivateWrongLibrary() {
var c = new C();
var im = reflect(c);
var selector = MirrorSystem.getSymbol(
'_field', reflectClass(Mirror).owner as LibraryMirror);
'_field',
reflectClass(Mirror).owner as LibraryMirror,
);
for (int i = 0; i < (2 * optimizationThreshold); i++) {
Expect.throwsNoSuchMethodError(() => im.getField(selector));
+3 -1
View File
@@ -38,7 +38,9 @@ testPrivateWrongLibrary() {
var c = new C();
var im = reflect(c);
var selector = MirrorSystem.getSymbol(
'_field', reflectClass(Mirror).owner as LibraryMirror);
'_field',
reflectClass(Mirror).owner as LibraryMirror,
);
for (int i = 0; i < (2 * optimizationThreshold); i++) {
Expect.throwsNoSuchMethodError(() => im.setField(selector, i));
+3 -1
View File
@@ -18,6 +18,8 @@ class Bar extends Foo {}
void main() {
expect(
'Variable(s(field) in s(Foo))', reflectClass(Foo).declarations[#field]);
'Variable(s(field) in s(Foo))',
reflectClass(Foo).declarations[#field],
);
expect('<null>', reflectClass(Bar).declarations[#field]);
}
@@ -21,7 +21,12 @@ main() {
ClassMirror cm = reflectClass(C);
// N.B.: Does not include #implementMe.
Expect.setEquals([#hashCode, #runtimeType, #==, #noSuchMethod, #toString],
selectKeys(cm.instanceMembers, (dm) => !dm.isPrivate));
Expect.setEquals([
#hashCode,
#runtimeType,
#==,
#noSuchMethod,
#toString,
], selectKeys(cm.instanceMembers, (dm) => !dm.isPrivate));
// Filter out private to avoid implementation-specific members of Object.
}
@@ -22,7 +22,8 @@ abstract class C extends S {
method() {}
get getter {}
set setter(x) {}
/* abstract */ notOverridden();
/* abstract */
notOverridden();
}
selectKeys<K, V>(Map<K, V> map, bool Function(V) predicate) {
@@ -45,18 +46,22 @@ main() {
#runtimeType,
#==,
#noSuchMethod,
#toString
#toString,
], selectKeys(sMirror.instanceMembers, (dynamic dm) => !dm.isPrivate));
// Filter out private to avoid implementation-specific members of Object.
Expect.equals(sMirror, sMirror.instanceMembers[#field]!.owner);
Expect.equals(
sMirror, sMirror.instanceMembers[const Symbol('field=')]!.owner);
sMirror,
sMirror.instanceMembers[const Symbol('field=')]!.owner,
);
Expect.equals(sMirror, sMirror.instanceMembers[#finalField]!.owner);
Expect.equals(sMirror, sMirror.instanceMembers[#method]!.owner);
Expect.equals(sMirror, sMirror.instanceMembers[#getter]!.owner);
Expect.equals(
sMirror, sMirror.instanceMembers[const Symbol('setter=')]!.owner);
sMirror,
sMirror.instanceMembers[const Symbol('setter=')]!.owner,
);
Expect.setEquals([
#field,
@@ -70,18 +75,22 @@ main() {
#runtimeType,
#==,
#noSuchMethod,
#toString
#toString,
], selectKeys(cMirror.instanceMembers, (dynamic dm) => !dm.isPrivate));
// Filter out private to avoid implementation-specific members of Object.
Expect.equals(cMirror, cMirror.instanceMembers[#field]!.owner);
Expect.equals(
cMirror, cMirror.instanceMembers[const Symbol('field=')]!.owner);
cMirror,
cMirror.instanceMembers[const Symbol('field=')]!.owner,
);
Expect.equals(cMirror, cMirror.instanceMembers[#finalField]!.owner);
Expect.equals(cMirror, cMirror.instanceMembers[#method]!.owner);
Expect.equals(cMirror, cMirror.instanceMembers[#getter]!.owner);
Expect.equals(
cMirror, cMirror.instanceMembers[const Symbol('setter=')]!.owner);
cMirror,
cMirror.instanceMembers[const Symbol('setter=')]!.owner,
);
Expect.equals(sMirror, sMirror.instanceMembers[#notOverridden]!.owner);
Expect.equals(sMirror, cMirror.instanceMembers[#notOverridden]!.owner);
@@ -13,9 +13,10 @@ assertInstantiationErrorOnGenerativeConstructors(classMirror) {
if (!decl.isGenerativeConstructor) return;
var args = new List<dynamic>.filled(decl.parameters.length, null);
Expect.throws(
() => classMirror.newInstance(decl.constructorName, args),
(e) => e is AbstractClassInstantiationError,
'${decl.qualifiedName} should have failed');
() => classMirror.newInstance(decl.constructorName, args),
(e) => e is AbstractClassInstantiationError,
'${decl.qualifiedName} should have failed',
);
});
}
@@ -19,9 +19,12 @@ class FakeFunctionNSM {
class C {
get fakeFunctionCall => new FakeFunctionCall();
get fakeFunctionNSM => new FakeFunctionNSM();
get closure => (x, y) => '2 $this $x $y';
get closureOpt => (x, y, [z, w]) => '3 $this $x $y $z $w';
get closureNamed => (x, y, {z, w}) => '4 $this $x $y $z $w';
get closure =>
(x, y) => '2 $this $x $y';
get closureOpt =>
(x, y, [z, w]) => '3 $this $x $y $z $w';
get closureNamed =>
(x, y, {z, w}) => '4 $this $x $y $z $w';
tearOff(x, y) => '22 $this $x $y';
tearOffOpt(x, y, [z, w]) => '33 $this $x $y $z $w';
tearOffNamed(x, y, {z, w}) => '44 $this $x $y $z $w';
@@ -49,7 +52,9 @@ main() {
im = reflect(c.closureNamed);
Expect.equals(
'4 C 14 15 null 16', im.invoke(#call, [14, 15], {#w: 16}).reflectee);
'4 C 14 15 null 16',
im.invoke(#call, [14, 15], {#w: 16}).reflectee,
);
im = reflect(c.tearOff);
Expect.equals('22 C 9 10', im.invoke(#call, [9, 10]).reflectee);
@@ -59,5 +64,7 @@ main() {
im = reflect(c.tearOffNamed);
Expect.equals(
'44 C 14 15 null 16', im.invoke(#call, [14, 15], {#w: 16}).reflectee);
'44 C 14 15 null 16',
im.invoke(#call, [14, 15], {#w: 16}).reflectee,
);
}
@@ -53,9 +53,13 @@ testInstanceReflective() {
Expect.equals('7, 8', im.invoke(#fakeFunctionNSM, [7, 8]).reflectee);
Expect.equals('2 C 9 10', im.invoke(#closure, [9, 10]).reflectee);
Expect.equals(
'3 C 11 12 13 null', im.invoke(#closureOpt, [11, 12, 13]).reflectee);
Expect.equals('4 C 14 15 null 16',
im.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee);
'3 C 11 12 13 null',
im.invoke(#closureOpt, [11, 12, 13]).reflectee,
);
Expect.equals(
'4 C 14 15 null 16',
im.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee,
);
Expect.equals('DNU', im.invoke(#doesNotExist, [17, 18]).reflectee);
Expect.throwsNoSuchMethodError(() => im.invoke(#closure, ['wrong arity']));
Expect.throwsNoSuchMethodError(() => im.invoke(#notAClosure, []));
@@ -85,9 +89,13 @@ testClassReflective() {
Expect.equals('7, 8', cm.invoke(#fakeFunctionNSM, [7, 8]).reflectee);
Expect.equals('2 9 10', cm.invoke(#closure, [9, 10]).reflectee);
Expect.equals(
'3 11 12 13 null', cm.invoke(#closureOpt, [11, 12, 13]).reflectee);
Expect.equals('4 14 15 null 16',
cm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee);
'3 11 12 13 null',
cm.invoke(#closureOpt, [11, 12, 13]).reflectee,
);
Expect.equals(
'4 14 15 null 16',
cm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee,
);
Expect.throwsNoSuchMethodError(() => cm.invoke(#closure, ['wrong arity']));
}
@@ -113,9 +121,13 @@ testLibraryReflective() {
Expect.equals('7, 8', lm.invoke(#fakeFunctionNSM, [7, 8]).reflectee);
Expect.equals('2 9 10', lm.invoke(#closure, [9, 10]).reflectee);
Expect.equals(
'3 11 12 13 null', lm.invoke(#closureOpt, [11, 12, 13]).reflectee);
Expect.equals('4 14 15 null 16',
lm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee);
'3 11 12 13 null',
lm.invoke(#closureOpt, [11, 12, 13]).reflectee,
);
Expect.equals(
'4 14 15 null 16',
lm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee,
);
Expect.throwsNoSuchMethodError(() => lm.invoke(#closure, ['wrong arity']));
}
@@ -84,19 +84,29 @@ main() {
// Now the same thing through mirrors and mirror-invocation.
f = getAMirror().getField(#codeUnitAt);
Expect.equals(
"codeUnitAt-42", f.invoke(#call, [42], <Symbol, dynamic>{}).reflectee);
"codeUnitAt-42",
f.invoke(#call, [42], <Symbol, dynamic>{}).reflectee,
);
f = getAMirror().getField(#toUpperCase);
Expect.equals(
"toUpperCase", f.invoke(#call, [], <Symbol, dynamic>{}).reflectee);
"toUpperCase",
f.invoke(#call, [], <Symbol, dynamic>{}).reflectee,
);
f = getAMirror().getField(#indexOf);
Expect.equals(
"indexOf-499", f.invoke(#call, [499], <Symbol, dynamic>{}).reflectee);
"indexOf-499",
f.invoke(#call, [499], <Symbol, dynamic>{}).reflectee,
);
f = getAMirror().getField(#lastIndexOf);
Expect.equals(
"lastIndexOf-FOO,BAR", f.invoke(#call, ["FOO", "BAR"]).reflectee);
"lastIndexOf-FOO,BAR",
f.invoke(#call, ["FOO", "BAR"]).reflectee,
);
f = getAMirror().getField(#splitMapJoin);
Expect.equals("splitMapJoin-1,2,3",
f.invoke(#call, [1], {#onMatch: 2, #onNonMatch: 3}).reflectee);
Expect.equals(
"splitMapJoin-1,2,3",
f.invoke(#call, [1], {#onMatch: 2, #onNonMatch: 3}).reflectee,
);
f = getAMirror().getField(#trim);
Expect.equals("trim-true", f.invoke(#call, [], {#named: true}).reflectee);
@@ -118,16 +128,24 @@ main() {
f = getAMirror().getField(#endsWith);
Expect.equals(
"endsWith-42", f.invoke(#call, [42], <Symbol, dynamic>{}).reflectee);
"endsWith-42",
f.invoke(#call, [42], <Symbol, dynamic>{}).reflectee,
);
f = getAMirror().getField(#toLowerCase);
Expect.equals(
"toLowerCase", f.invoke(#call, [], <Symbol, dynamic>{}).reflectee);
"toLowerCase",
f.invoke(#call, [], <Symbol, dynamic>{}).reflectee,
);
f = getAMirror().getField(#indexOf);
Expect.equals(
"indexOf-499", f.invoke(#call, [499], <Symbol, dynamic>{}).reflectee);
"indexOf-499",
f.invoke(#call, [499], <Symbol, dynamic>{}).reflectee,
);
f = getAMirror().getField(#matchAsPrefix);
Expect.equals(
"matchAsPrefix-FOO,BAR", f.invoke(#call, ["FOO", "BAR"]).reflectee);
"matchAsPrefix-FOO,BAR",
f.invoke(#call, ["FOO", "BAR"]).reflectee,
);
f = getAMirror().getField(#toList);
Expect.equals("toList-1", f.invoke(#call, [], {#growable: 1}).reflectee);
f = getAMirror().getField(#toSet);
+18 -12
View File
@@ -10,26 +10,32 @@ import 'package:expect/expect.dart';
import 'other_library.dart';
main() {
LibraryMirror thisLibrary =
currentMirrorSystem().findLibrary(#test.invoke_import_test);
LibraryMirror thisLibrary = currentMirrorSystem().findLibrary(
#test.invoke_import_test,
);
Expect.throwsNoSuchMethodError(
() => thisLibrary.invoke(#topLevelMethod, []),
'Should not invoke imported method #topLevelMethod');
() => thisLibrary.invoke(#topLevelMethod, []),
'Should not invoke imported method #topLevelMethod',
);
Expect.throwsNoSuchMethodError(
() => thisLibrary.getField(#topLevelGetter),
'Should not invoke imported getter #topLevelGetter');
() => thisLibrary.getField(#topLevelGetter),
'Should not invoke imported getter #topLevelGetter',
);
Expect.throwsNoSuchMethodError(
() => thisLibrary.getField(#topLevelField),
'Should not invoke imported field #topLevelField');
() => thisLibrary.getField(#topLevelField),
'Should not invoke imported field #topLevelField',
);
Expect.throwsNoSuchMethodError(
() => thisLibrary.setField(#topLevelSetter, 23),
'Should not invoke imported setter #topLevelSetter');
() => thisLibrary.setField(#topLevelSetter, 23),
'Should not invoke imported setter #topLevelSetter',
);
Expect.throwsNoSuchMethodError(
() => thisLibrary.setField(#topLevelField, 23),
'Should not invoke imported field #topLevelField');
() => thisLibrary.setField(#topLevelField, 23),
'Should not invoke imported field #topLevelField',
);
}
@@ -32,7 +32,8 @@ main() {
LibraryMirror lm = cm.owner as LibraryMirror;
Expect.throwsNoSuchMethodError(
() => lm.invoke(#_libraryFunction, [':', ')']));
() => lm.invoke(#_libraryFunction, [':', ')']),
);
Expect.throwsNoSuchMethodError(() => lm.getField(#_libraryGetter));
Expect.throwsNoSuchMethodError(() => lm.getField(#_libraryField));
Expect.throwsNoSuchMethodError(() => lm.setField(#_librarySetter, 'lfoo'));
+36 -13
View File
@@ -71,9 +71,13 @@ testSync() {
result = cm.invoke(const Symbol('staticFunction'), [3, 4]);
Expect.equals('(3,4)', result.reflectee);
Expect.throwsNoSuchMethodError(
() => cm.invoke(const Symbol('doesntExist'), [3, 4]), 'Not defined');
() => cm.invoke(const Symbol('doesntExist'), [3, 4]),
'Not defined',
);
Expect.throwsNoSuchMethodError(
() => cm.invoke(const Symbol('staticFunction'), [3]), 'Wrong arity');
() => cm.invoke(const Symbol('staticFunction'), [3]),
'Wrong arity',
);
// ClassMirror invokeGetter
result = cm.getField(const Symbol('staticGetter'));
@@ -81,20 +85,26 @@ testSync() {
result = cm.getField(const Symbol('staticField'));
Expect.equals('initial', result.reflectee);
Expect.throwsNoSuchMethodError(
() => cm.getField(const Symbol('doesntExist')), 'Not defined');
() => cm.getField(const Symbol('doesntExist')),
'Not defined',
);
// ClassMirror invokeSetter
result = cm.setField(const Symbol('staticSetter'), 'sfoo');
Expect.equals('sfoo', result.reflectee);
Expect.equals('sset sfoo', C.staticField);
Expect.equals(
'sset sfoo', cm.getField(const Symbol('staticField')).reflectee);
'sset sfoo',
cm.getField(const Symbol('staticField')).reflectee,
);
result = cm.setField(const Symbol('staticField'), 'sbar');
Expect.equals('sbar', result.reflectee);
Expect.equals('sbar', C.staticField);
Expect.equals('sbar', cm.getField(const Symbol('staticField')).reflectee);
Expect.throwsNoSuchMethodError(
() => cm.setField(const Symbol('doesntExist'), 'sbar'), 'Not defined');
() => cm.setField(const Symbol('doesntExist'), 'sbar'),
'Not defined',
);
// ClassMirror invokeConstructor
result = cm.newInstance(Symbol.empty, []);
@@ -104,19 +114,26 @@ testSync() {
Expect.isTrue(result.reflectee is C);
Expect.equals('my value', result.reflectee.field);
Expect.throwsNoSuchMethodError(
() => cm.newInstance(const Symbol('doesntExist'), ['my value']),
'Not defined');
() => cm.newInstance(const Symbol('doesntExist'), ['my value']),
'Not defined',
);
Expect.throwsNoSuchMethodError(
() => cm.newInstance(const Symbol('named'), []), 'Wrong arity');
() => cm.newInstance(const Symbol('named'), []),
'Wrong arity',
);
// LibraryMirror invoke
LibraryMirror lm = cm.owner as LibraryMirror;
result = lm.invoke(const Symbol('libraryFunction'), [':', ')']);
Expect.equals(':)', result.reflectee);
Expect.throwsNoSuchMethodError(
() => lm.invoke(const Symbol('doesntExist'), [':', ')']), 'Not defined');
() => lm.invoke(const Symbol('doesntExist'), [':', ')']),
'Not defined',
);
Expect.throwsNoSuchMethodError(
() => lm.invoke(const Symbol('libraryFunction'), [':']), 'Wrong arity');
() => lm.invoke(const Symbol('libraryFunction'), [':']),
'Wrong arity',
);
// LibraryMirror invokeGetter
result = lm.getField(const Symbol('libraryGetter'));
@@ -124,20 +141,26 @@ testSync() {
result = lm.getField(const Symbol('libraryField'));
Expect.equals('a priori', result.reflectee);
Expect.throwsNoSuchMethodError(
() => lm.getField(const Symbol('doesntExist')), 'Not defined');
() => lm.getField(const Symbol('doesntExist')),
'Not defined',
);
// LibraryMirror invokeSetter
result = lm.setField(const Symbol('librarySetter'), 'lfoo');
Expect.equals('lfoo', result.reflectee);
Expect.equals('lset lfoo', libraryField);
Expect.equals(
'lset lfoo', lm.getField(const Symbol('libraryField')).reflectee);
'lset lfoo',
lm.getField(const Symbol('libraryField')).reflectee,
);
result = lm.setField(const Symbol('libraryField'), 'lbar');
Expect.equals('lbar', result.reflectee);
Expect.equals('lbar', libraryField);
Expect.equals('lbar', lm.getField(const Symbol('libraryField')).reflectee);
Expect.throwsNoSuchMethodError(
() => lm.setField(const Symbol('doesntExist'), 'lbar'), 'Not defined');
() => lm.setField(const Symbol('doesntExist'), 'lbar'),
'Not defined',
);
}
main() {
+2 -1
View File
@@ -8,7 +8,8 @@ import "package:expect/expect.dart";
void main() {
Expect.isTrue(
reflectClass(MyException).superclass!.reflectedType == FormatException);
reflectClass(MyException).superclass!.reflectedType == FormatException,
);
Expect.isTrue(reflectClass(FormatException).reflectedType == FormatException);
}
+5 -6
View File
@@ -11,15 +11,14 @@ import 'package:expect/expect.dart';
import 'stringify.dart';
class Foo {
static dynamic hello = {
'a': 'b',
'c': 'd',
};
static dynamic hello = {'a': 'b', 'c': 'd'};
}
void main() {
expect('Variable(s(hello) in s(Foo), static)',
reflectClass(Foo).declarations[#hello]);
expect(
'Variable(s(hello) in s(Foo), static)',
reflectClass(Foo).declarations[#hello],
);
var reflectee = reflectClass(Foo).getField(#hello).reflectee;
Expect.stringEquals('a, c', reflectee.keys.join(', '));
// Call the lazy getter twice as different things probably happen in the
+3 -2
View File
@@ -19,8 +19,9 @@ main() {
LibraryMirror? mirrorsLibrary = libraries[Uri.parse('dart:mirrors')];
if (mirrorsLibrary == null) {
// In minified mode we don't preserve the URIs.
mirrorsLibrary = libraries.values
.firstWhere((LibraryMirror lm) => lm.simpleName == #dart.mirrors);
mirrorsLibrary = libraries.values.firstWhere(
(LibraryMirror lm) => lm.simpleName == #dart.mirrors,
);
Uri uri = mirrorsLibrary.uri;
Expect.equals("https", uri.scheme);
Expect.equals("dartlang.org", uri.host);
@@ -12,8 +12,11 @@ import 'other_library.dart' deferred as other;
main() {
var ms = currentMirrorSystem();
Expect.throws(() => ms.findLibrary(#test.other_library), (e) => true,
"should not be loaded yet");
Expect.throws(
() => ms.findLibrary(#test.other_library),
(e) => true,
"should not be loaded yet",
);
asyncStart();
other.loadLibrary().then((_) {
@@ -16,17 +16,21 @@ test(MirrorSystem mirrors) {
LibraryMirror b = mirrors.findLibrary(#library_imports_b);
LibraryMirror core = mirrors.findLibrary(#dart.core);
Expect.setEquals(
[a, b, core], hidden.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.setEquals([
a,
b,
core,
], hidden.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.stringEquals(
'import dart.core\n'
'export library_imports_a\n'
' hide somethingFromA\n'
' hide somethingFromBoth\n'
'export library_imports_b\n'
' hide somethingFromB\n',
stringifyDependencies(hidden));
'import dart.core\n'
'export library_imports_a\n'
' hide somethingFromA\n'
' hide somethingFromBoth\n'
'export library_imports_b\n'
' hide somethingFromB\n',
stringifyDependencies(hidden),
);
}
main() {
@@ -17,17 +17,21 @@ test(MirrorSystem mirrors) {
LibraryMirror core = mirrors.findLibrary(#dart.core);
Expect.setEquals(
[a, b, core], shown.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.setEquals([
a,
b,
core,
], shown.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.stringEquals(
'import dart.core\n'
'export library_imports_a\n'
' show somethingFromA\n'
' show somethingFromBoth\n'
'export library_imports_b\n'
' show somethingFromB\n',
stringifyDependencies(shown));
'import dart.core\n'
'export library_imports_a\n'
' show somethingFromA\n'
' show somethingFromBoth\n'
'export library_imports_b\n'
' show somethingFromB\n',
stringifyDependencies(shown),
);
}
main() {
@@ -14,8 +14,9 @@ import 'other_library.dart' deferred as other;
main() {
var ms = currentMirrorSystem();
LibraryMirror thisLibrary = ms.findLibrary(#library_loading_deferred_loading);
LibraryDependencyMirror dep =
thisLibrary.libraryDependencies.singleWhere((d) => d.prefix == #other);
LibraryDependencyMirror dep = thisLibrary.libraryDependencies.singleWhere(
(d) => d.prefix == #other,
);
Expect.isNull(dep.targetLibrary, "should not be loaded yet");
asyncStart();
@@ -12,29 +12,34 @@ import 'dart:math' as eagermath;
import 'dart:math' deferred as lazymath;
test(MirrorSystem mirrors) {
LibraryMirror thisLibrary =
mirrors.findLibrary(#test.library_imports_deferred);
LibraryMirror thisLibrary = mirrors.findLibrary(
#test.library_imports_deferred,
);
LibraryMirror math = mirrors.findLibrary(#dart.math);
var importsOfCollection = thisLibrary.libraryDependencies
.where((dep) => dep.targetLibrary == math)
.toList();
Expect.equals(2, importsOfCollection.length);
Expect.notEquals(importsOfCollection[0].isDeferred,
importsOfCollection[1].isDeferred); // One deferred, one not.
Expect.notEquals(
importsOfCollection[0].isDeferred,
importsOfCollection[1].isDeferred,
); // One deferred, one not.
// Only math is defer-imported.
LibraryDependencyMirror dep =
thisLibrary.libraryDependencies.singleWhere((dep) => dep.isDeferred);
LibraryDependencyMirror dep = thisLibrary.libraryDependencies.singleWhere(
(dep) => dep.isDeferred,
);
Expect.equals(math, dep.targetLibrary);
Expect.stringEquals(
'import dart.math as eagermath\n'
'import dart.math deferred as lazymath\n'
'import dart.mirrors\n'
'import expect\n'
'import test.stringify\n',
stringifyDependencies(thisLibrary));
'import dart.math as eagermath\n'
'import dart.math deferred as lazymath\n'
'import dart.mirrors\n'
'import expect\n'
'import test.stringify\n',
stringifyDependencies(thisLibrary),
);
}
main() {
@@ -16,17 +16,21 @@ test(MirrorSystem mirrors) {
LibraryMirror b = mirrors.findLibrary(#library_imports_b);
LibraryMirror core = mirrors.findLibrary(#dart.core);
Expect.setEquals(
[a, b, core], hidden.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.setEquals([
a,
b,
core,
], hidden.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.stringEquals(
'import dart.core\n'
'import library_imports_a\n'
' hide somethingFromA\n'
' hide somethingFromBoth\n'
'import library_imports_b\n'
' hide somethingFromB\n',
stringifyDependencies(hidden));
'import dart.core\n'
'import library_imports_a\n'
' hide somethingFromA\n'
' hide somethingFromBoth\n'
'import library_imports_b\n'
' hide somethingFromB\n',
stringifyDependencies(hidden),
);
}
main() {
@@ -11,46 +11,57 @@ import 'stringify.dart';
import 'library_imports_metadata.dart';
main() {
LibraryMirror lib =
currentMirrorSystem().findLibrary(#library_imports_metadata);
LibraryMirror lib = currentMirrorSystem().findLibrary(
#library_imports_metadata,
);
LibraryMirror core = currentMirrorSystem().findLibrary(#dart.core);
LibraryMirror mirrors = currentMirrorSystem().findLibrary(#dart.mirrors);
LibraryMirror collection =
currentMirrorSystem().findLibrary(#dart.collection);
LibraryMirror collection = currentMirrorSystem().findLibrary(
#dart.collection,
);
LibraryMirror async = currentMirrorSystem().findLibrary(#dart.async);
Expect.setEquals([core, mirrors, collection, async],
lib.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.setEquals([
core,
mirrors,
collection,
async,
], lib.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.stringEquals(
'import dart.async\n'
'import dart.collection\n'
'import dart.core\n'
'import dart.mirrors as mirrors\n',
stringifyDependencies(lib));
'import dart.async\n'
'import dart.collection\n'
'import dart.core\n'
'import dart.mirrors as mirrors\n',
stringifyDependencies(lib),
);
Expect.listEquals(
[].map(reflect).toList(),
lib.libraryDependencies
.singleWhere((dep) => dep.targetLibrary == core)
.metadata);
[].map(reflect).toList(),
lib.libraryDependencies
.singleWhere((dep) => dep.targetLibrary == core)
.metadata,
);
Expect.listEquals(
[m1].map(reflect).toList(),
lib.libraryDependencies
.singleWhere((dep) => dep.targetLibrary == mirrors)
.metadata);
[m1].map(reflect).toList(),
lib.libraryDependencies
.singleWhere((dep) => dep.targetLibrary == mirrors)
.metadata,
);
Expect.listEquals(
[m2, m3].map(reflect).toList(),
lib.libraryDependencies
.singleWhere((dep) => dep.targetLibrary == collection)
.metadata);
[m2, m3].map(reflect).toList(),
lib.libraryDependencies
.singleWhere((dep) => dep.targetLibrary == collection)
.metadata,
);
Expect.listEquals(
[].map(reflect).toList(),
lib.libraryDependencies
.singleWhere((dep) => dep.targetLibrary == async)
.metadata);
[].map(reflect).toList(),
lib.libraryDependencies
.singleWhere((dep) => dep.targetLibrary == async)
.metadata,
);
}
@@ -11,22 +11,27 @@ import 'stringify.dart';
import 'library_imports_prefixed_show_hide.dart';
test(MirrorSystem mirrors) {
LibraryMirror prefixed_show_hide =
mirrors.findLibrary(#library_imports_prefixed_show_hide);
LibraryMirror prefixed_show_hide = mirrors.findLibrary(
#library_imports_prefixed_show_hide,
);
LibraryMirror a = mirrors.findLibrary(#library_imports_a);
LibraryMirror b = mirrors.findLibrary(#library_imports_b);
LibraryMirror core = mirrors.findLibrary(#dart.core);
Expect.setEquals([a, b, core],
prefixed_show_hide.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.setEquals([
a,
b,
core,
], prefixed_show_hide.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.stringEquals(
'import dart.core\n'
'import library_imports_a as prefixa\n'
' show somethingFromA\n'
'import library_imports_b as prefixb\n'
' hide somethingFromB\n',
stringifyDependencies(prefixed_show_hide));
'import dart.core\n'
'import library_imports_a as prefixa\n'
' show somethingFromA\n'
'import library_imports_b as prefixb\n'
' hide somethingFromB\n',
stringifyDependencies(prefixed_show_hide),
);
}
main() {
@@ -16,14 +16,18 @@ test(MirrorSystem mirrors) {
LibraryMirror b = mirrors.findLibrary(#library_imports_b);
LibraryMirror core = mirrors.findLibrary(#dart.core);
Expect.setEquals([a, b, core],
prefixed.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.setEquals([
a,
b,
core,
], prefixed.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.stringEquals(
'import dart.core\n'
'import library_imports_a as prefixa\n'
'import library_imports_b as prefixb\n',
stringifyDependencies(prefixed));
'import dart.core\n'
'import library_imports_a as prefixa\n'
'import library_imports_b as prefixb\n',
stringifyDependencies(prefixed),
);
}
main() {
@@ -16,17 +16,21 @@ test(MirrorSystem mirrors) {
LibraryMirror b = mirrors.findLibrary(#library_imports_b);
LibraryMirror core = mirrors.findLibrary(#dart.core);
Expect.setEquals(
[a, b, core], shown.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.setEquals([
a,
b,
core,
], shown.libraryDependencies.map((dep) => dep.targetLibrary));
Expect.stringEquals(
'import dart.core\n'
'import library_imports_a\n'
' show somethingFromA\n'
' show somethingFromBoth\n'
'import library_imports_b\n'
' show somethingFromB\n',
stringifyDependencies(shown));
'import dart.core\n'
'import library_imports_a\n'
' show somethingFromA\n'
' show somethingFromBoth\n'
'import library_imports_b\n'
' show somethingFromB\n',
stringifyDependencies(shown),
);
}
main() {
+4 -2
View File
@@ -12,7 +12,9 @@ import 'metadata_test.dart';
main() {
MirrorSystem mirrors = currentMirrorSystem();
checkMetadata(
mirrors.findLibrary(#test.library_metadata_test), [string, symbol]);
checkMetadata(mirrors.findLibrary(#test.library_metadata_test), [
string,
symbol,
]);
checkMetadata(mirrors.findLibrary(#test.metadata_test), []);
}
+4 -2
View File
@@ -24,8 +24,10 @@ main() {
var mirrors = currentMirrorSystem();
test("Test current library uri", () {
if (!Platform.script.toString().endsWith('.dart')) {
print("Skipping library uri test as not running from source "
"(Platform.script = ${Platform.script})");
print(
"Skipping library uri test as not running from source "
"(Platform.script = ${Platform.script})",
);
return;
}
Uri uri = Uri.base.resolveUri(Platform.script);
@@ -26,6 +26,8 @@ main() {
var mirrors = currentMirrorSystem();
test("Test package library uri", () {
testLibraryUri(
ExpectException(""), Uri.parse('package:expect/expect.dart'));
ExpectException(""),
Uri.parse('package:expect/expect.dart'),
);
});
}
+3 -2
View File
@@ -13,8 +13,9 @@ import 'other_library.dart' deferred as other;
main() {
var ms = currentMirrorSystem();
LibraryMirror thisLibrary = ms.findLibrary(#load_library);
var dep =
thisLibrary.libraryDependencies.singleWhere((d) => d.prefix == #other);
var dep = thisLibrary.libraryDependencies.singleWhere(
(d) => d.prefix == #other,
);
Expect.isNull(dep.targetLibrary, "should not be loaded yet");
asyncStart();
@@ -8,13 +8,16 @@ import 'dart:mirrors';
import 'package:expect/expect.dart';
topLevel() => 1;
topLevelLocal() => () => 2;
topLevelLocal() =>
() => 2;
class C {
static klass() => 3;
static klassLocal() => () => 4;
static klassLocal() =>
() => 4;
instance() => 5;
instanceLocal() => () => 6;
instanceLocal() =>
() => 6;
}
main() {
@@ -27,7 +27,10 @@ checkIsExtensionTypeMember(closure, kind, simpleName) {
var methodMirror = closureMirror.function;
Expect.equals(Symbol(simpleName), methodMirror.simpleName);
Expect.equals(
kind, methodMirror.isExtensionTypeMember, "isExtensionTypeMember");
kind,
methodMirror.isExtensionTypeMember,
"isExtensionTypeMember",
);
}
String? getExtensionTypeName(sym) {
@@ -46,21 +49,34 @@ void testExtensionTypeMembers(sym, mirror) {
final methodMirror = mirror as MethodMirror;
if (extensionTypeName != null) {
Expect.equals(
true, methodMirror.isExtensionTypeMember, "isExtensionTypeMember");
true,
methodMirror.isExtensionTypeMember,
"isExtensionTypeMember",
);
Expect.isTrue(
methodMirror.simpleName.toString().contains('$extensionTypeName.'));
methodMirror.simpleName.toString().contains('$extensionTypeName.'),
);
} else {
Expect.equals(
false, methodMirror.isExtensionTypeMember, "isExtensionTypeMember");
false,
methodMirror.isExtensionTypeMember,
"isExtensionTypeMember",
);
}
} else if (mirror is VariableMirror) {
var variableMirror = mirror as VariableMirror;
if (extensionTypeName != null) {
Expect.equals(
true, variableMirror.isExtensionTypeMember, "isExtensionTypeMember");
true,
variableMirror.isExtensionTypeMember,
"isExtensionTypeMember",
);
} else {
Expect.equals(
false, variableMirror.isExtensionTypeMember, "isExtensionTypeMember");
false,
variableMirror.isExtensionTypeMember,
"isExtensionTypeMember",
);
}
}
}
@@ -2,6 +2,9 @@
// 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.
// Don't let the formatter change the location of things.
// dart format off
part of test.method_location;
class ClassInOtherFile {
@@ -2,6 +2,9 @@
// 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.
// Don't let the formatter change the location of things.
// dart format off
library test.method_location;
import "dart:mirrors";
@@ -21,13 +24,15 @@ expectLocation(Mirror mirror, String uriSuffix, int line, int column) {
Expect.isTrue(methodMirror is MethodMirror);
final location = methodMirror.location!;
final uri = location.sourceUri;
Expect.isTrue(uri.toString().endsWith(uriSuffix), "Expected suffix $uriSuffix in $uri");
Expect.isTrue(
uri.toString().endsWith(uriSuffix),
"Expected suffix $uriSuffix in $uri",
);
Expect.equals(line, location.line, "line");
Expect.equals(column, location.column, "column");
}
class ClassInMainFile {
ClassInMainFile();
method() {}
@@ -50,28 +55,47 @@ main() {
String otherSuffix = 'method_mirror_location_other.dart';
// This file.
expectLocation(reflectClass(ClassInMainFile).declarations[#ClassInMainFile]!,
mainSuffix, 31, 3);
expectLocation(
reflectClass(ClassInMainFile).declarations[#method]!, mainSuffix, 33, 3);
expectLocation(reflect(topLevelInMainFile), mainSuffix, 36, 1);
expectLocation(reflect(spaceIndentedInMainFile), mainSuffix, 37, 3);
expectLocation(reflect(tabIndentedInMainFile), mainSuffix, 38, 2);
expectLocation(reflect(localFunction), mainSuffix, 45, 3);
reflectClass(ClassInMainFile).declarations[#ClassInMainFile]!,
mainSuffix,
36,
3,
);
expectLocation(
reflectClass(ClassInMainFile).declarations[#method]!,
mainSuffix,
38,
3,
);
expectLocation(reflect(topLevelInMainFile), mainSuffix, 41, 1);
expectLocation(reflect(spaceIndentedInMainFile), mainSuffix, 42, 3);
expectLocation(reflect(tabIndentedInMainFile), mainSuffix, 43, 2);
expectLocation(reflect(localFunction), mainSuffix, 50, 3);
// Another part.
expectLocation(reflectClass(ClassInOtherFile).declarations[#ClassInOtherFile]!,
otherSuffix, 8, 3);
expectLocation(
reflectClass(ClassInOtherFile).declarations[#method]!, otherSuffix, 10, 3);
expectLocation(reflect(topLevelInOtherFile), otherSuffix, 13, 1);
expectLocation(reflect(spaceIndentedInOtherFile), otherSuffix, 15, 3);
expectLocation(reflect(tabIndentedInOtherFile), otherSuffix, 17, 2);
reflectClass(ClassInOtherFile).declarations[#ClassInOtherFile]!,
otherSuffix,
11,
3,
);
expectLocation(
reflectClass(ClassInOtherFile).declarations[#method]!,
otherSuffix,
13,
3,
);
expectLocation(reflect(topLevelInOtherFile), otherSuffix, 16, 1);
expectLocation(reflect(spaceIndentedInOtherFile), otherSuffix, 18, 3);
expectLocation(reflect(tabIndentedInOtherFile), otherSuffix, 20, 2);
// Synthetic methods.
Expect.isNull(reflectClass(HasImplicitConstructor)
.declarations[#HasImplicitConstructor]!
.location);
Expect.isNull(
(reflectType(Predicate) as TypedefMirror).referent.callMethod.location);
reflectClass(
HasImplicitConstructor,
).declarations[#HasImplicitConstructor]!.location,
);
Expect.isNull(
(reflectType(Predicate) as TypedefMirror).referent.callMethod.location,
);
}
@@ -15,5 +15,7 @@ main() {
// Regression test for http://www.dartbug.com/6335
var closureMirror = reflect(doNothing42) as ClosureMirror;
Expect.equals(
stringifySymbol(closureMirror.function.simpleName), "s(doNothing42)");
stringifySymbol(closureMirror.function.simpleName),
"s(doNothing42)",
);
}
@@ -51,30 +51,85 @@ main() {
var closureMirror = reflect(doNothing42) as ClosureMirror;
checkKinds(closureMirror.function, [true, false, false, false, false]);
var libraryMirror = reflectClass(C).owner as LibraryMirror;
checkKinds(libraryMirror.declarations[#topGetter],
[true, false, true, false, false]);
checkKinds(libraryMirror.declarations[const Symbol("topSetter=")],
[true, false, false, true, false]);
checkKinds(libraryMirror.declarations[#topGetter], [
true,
false,
true,
false,
false,
]);
checkKinds(libraryMirror.declarations[const Symbol("topSetter=")], [
true,
false,
false,
true,
false,
]);
var classMirror;
classMirror = reflectClass(C);
checkKinds(
classMirror.declarations[#foo], [true, false, false, false, false]);
checkKinds(
classMirror.declarations[#priv], [false, false, true, false, false]);
checkKinds(classMirror.declarations[const Symbol("priv=")],
[false, false, false, true, false]);
checkKinds(classMirror.declarations[#foo], [
true,
false,
false,
false,
false,
]);
checkKinds(classMirror.declarations[#priv], [
false,
false,
true,
false,
false,
]);
checkKinds(classMirror.declarations[const Symbol("priv=")], [
false,
false,
false,
true,
false,
]);
checkKinds(classMirror.declarations[#C], [false, false, false, false, true]);
checkKinds(
classMirror.declarations[#C.other], [false, false, false, false, true]);
checkKinds(
classMirror.declarations[#C.other2], [false, false, false, false, true]);
checkKinds(classMirror.declarations[#C.other], [
false,
false,
false,
false,
true,
]);
checkKinds(classMirror.declarations[#C.other2], [
false,
false,
false,
false,
true,
]);
classMirror = reflectClass(AbstractC);
checkKinds(
classMirror.declarations[#AbstractC], [false, false, false, false, true]);
checkKinds(
classMirror.declarations[#bar], [false, true, false, false, false]);
checkKinds(
classMirror.declarations[#priv], [false, true, true, false, false]);
checkKinds(classMirror.declarations[const Symbol("priv=")],
[false, true, false, true, false]);
checkKinds(classMirror.declarations[#AbstractC], [
false,
false,
false,
false,
true,
]);
checkKinds(classMirror.declarations[#bar], [
false,
true,
false,
false,
false,
]);
checkKinds(classMirror.declarations[#priv], [
false,
true,
true,
false,
false,
]);
checkKinds(classMirror.declarations[const Symbol("priv=")], [
false,
true,
false,
true,
false,
]);
}
@@ -21,11 +21,17 @@ main() {
// Source includes line breaks.
Expect.stringEquals(
'multiLineLF(y) {\n return y + 1;\n}', sourceOf(multiLineLF));
'multiLineLF(y) {\n return y + 1;\n}',
sourceOf(multiLineLF),
);
Expect.stringEquals(
'multiLineCR(y) {\r return y + 1;\r}', sourceOf(multiLineCR));
'multiLineCR(y) {\r return y + 1;\r}',
sourceOf(multiLineCR),
);
Expect.stringEquals(
'multiLineCRLF(y) {\r\n return y + 1;\r\n}', sourceOf(multiLineCRLF));
'multiLineCRLF(y) {\r\n return y + 1;\r\n}',
sourceOf(multiLineCRLF),
);
// First and last characters separated from middle by line breaks.
Expect.stringEquals('a\n(){\n}', sourceOf(a));
@@ -23,18 +23,15 @@ foo1() {}
doSomething(e) => e;
int get x => 42;
set x(value) { }
set x(value) {}
class S {}
class C extends S {
var _x;
var _y;
C(this._x, y)
: _y = y,
super();
C(this._x, y) : _y = y, super();
factory C.other(num z) => C(z, z);
factory C.other2() => C(0, 0);
@@ -46,65 +43,79 @@ class C extends S {
// Some comment.
void bar() { /* Not so happy bar. */ }
void bar() {
/* Not so happy bar. */
}
num get someX =>
181;
num get someX => 181;
set someX(v) {
// Discard this one.
}
}
main() {
// Top-level members
LibraryMirror lib = reflectClass(C).owner as LibraryMirror;
expectSource(lib.declarations[#foo1]!,
"foo1() {}");
expectSource(lib.declarations[#x]!,
"int get x => 42;");
expectSource(lib.declarations[const Symbol("x=")]!,
"set x(value) { }");
expectSource(lib.declarations[#foo1]!, "foo1() {}");
expectSource(lib.declarations[#x]!, "int get x => 42;");
expectSource(lib.declarations[const Symbol("x=")]!, "set x(value) {}");
// Class members
ClassMirror cm = reflectClass(C);
expectSource(cm.declarations[#foo]!,
"static dynamic foo() {\n"
" // Happy foo.\n"
" }");
expectSource(cm.declarations[#bar]!,
"void bar() { /* Not so happy bar. */ }");
expectSource(cm.declarations[#someX]!,
"num get someX =>\n"
" 181;");
expectSource(cm.declarations[const Symbol("someX=")]!,
"set someX(v) {\n"
" // Discard this one.\n"
" }");
expectSource(cm.declarations[#C]!,
"C(this._x, y)\n"
" : _y = y,\n"
" super();");
expectSource(cm.declarations[#C.other]!,
"factory C.other(num z) => C(z, z);");
expectSource(cm.declarations[#C.other3]!,
"factory C.other3() = C.other2;");
expectSource(
cm.declarations[#foo]!,
"static dynamic foo() {\n"
" // Happy foo.\n"
" }",
);
expectSource(
cm.declarations[#bar]!,
"void bar() {\n"
" /* Not so happy bar. */\n"
" }",
);
expectSource(
cm.declarations[#someX]!,
"num get someX => 181;",
);
expectSource(
cm.declarations[const Symbol("someX=")]!,
"set someX(v) {\n"
" // Discard this one.\n"
" }",
);
expectSource(
cm.declarations[#C]!,
"C(this._x, y) : _y = y, super();",
);
expectSource(
cm.declarations[#C.other]!,
"factory C.other(num z) => C(z, z);",
);
expectSource(cm.declarations[#C.other3]!, "factory C.other3() = C.other2;");
// Closures
expectSource(reflect((){}), "(){}");
expectSource(reflect((x,y,z) { return x*y*z; }), "(x,y,z) { return x*y*z; }");
expectSource(reflect(() {}), "() {}");
expectSource(
reflect((x, y, z) {
return x * y * z;
}),
"(x, y, z) {\n"
" return x * y * z;\n"
" }",
);
expectSource(reflect((e) => doSomething(e)), "(e) => doSomething(e)");
namedClosure(x,y,z) => 1;
namedClosure(x, y, z) => 1;
var a = () {};
expectSource(reflect(namedClosure), "namedClosure(x,y,z) => 1;");
expectSource(reflect(namedClosure), "namedClosure(x, y, z) => 1;");
expectSource(reflect(a), "() {}");
// Function at first line.
LibraryMirror otherLib = reflectClass(SomethingInOther).owner as LibraryMirror;
expectSource(otherLib.declarations[#main]!,
"""main() {
LibraryMirror otherLib =
reflectClass(SomethingInOther).owner as LibraryMirror;
expectSource(otherLib.declarations[#main]!, """main() {
print("Blah");
}""");
}
@@ -19,34 +19,48 @@ class C {
main() {
var mirrors = currentMirrorSystem();
var libMirror = mirrors.findLibrary(#test.mirrors_nsm_mismatch);
expectMatchingErrors(() => libMirror.invoke(#topLevelMethod, [], {#extra: 1}),
() => topLevelMethod(extra: 1));
expectMatchingErrors(() => libMirror.invoke(#topLevelMethod, ['positional']),
() => topLevelMethod('positional'));
expectMatchingErrors(
() => libMirror.invoke(#topLevelMethod, [], {#extra: 1}),
() => topLevelMethod(extra: 1),
);
expectMatchingErrors(
() => libMirror.invoke(#topLevelMethod, ['positional']),
() => topLevelMethod('positional'),
);
var classMirror = reflectClass(C);
expectMatchingErrors(
() => classMirror.newInstance(#constructor, [], {#extra: 1}),
() => new C.constructor(extra: 1));
() => classMirror.newInstance(#constructor, [], {#extra: 1}),
() => new C.constructor(extra: 1),
);
expectMatchingErrors(
() => classMirror.newInstance(#redirecting, [], {#extra: 1}),
() => new C.redirecting(extra: 1));
expectMatchingErrors(() => classMirror.invoke(#staticMethod, [], {#extra: 1}),
() => C.staticMethod(extra: 1));
() => classMirror.newInstance(#redirecting, [], {#extra: 1}),
() => new C.redirecting(extra: 1),
);
expectMatchingErrors(
() => classMirror.newInstance(#constructor, ['positional']),
() => new C.constructor('positional'));
() => classMirror.invoke(#staticMethod, [], {#extra: 1}),
() => C.staticMethod(extra: 1),
);
expectMatchingErrors(
() => classMirror.newInstance(#redirecting, ['positional']),
() => new C.redirecting('positional'));
expectMatchingErrors(() => classMirror.invoke(#staticMethod, ['positional']),
() => C.staticMethod('positional'));
() => classMirror.newInstance(#constructor, ['positional']),
() => new C.constructor('positional'),
);
expectMatchingErrors(
() => classMirror.newInstance(#redirecting, ['positional']),
() => new C.redirecting('positional'),
);
expectMatchingErrors(
() => classMirror.invoke(#staticMethod, ['positional']),
() => C.staticMethod('positional'),
);
var instanceMirror = reflect(new C.constructor());
expectMatchingErrors(
() => instanceMirror.invoke(#instanceMethod, [], {#extra: 1}),
() => instanceMirror.reflectee.instanceMethod(extra: 1));
() => instanceMirror.invoke(#instanceMethod, [], {#extra: 1}),
() => instanceMirror.reflectee.instanceMethod(extra: 1),
);
expectMatchingErrors(
() => instanceMirror.invoke(#instanceMethod, ['positional']),
() => instanceMirror.reflectee.instanceMethod('positional'));
() => instanceMirror.invoke(#instanceMethod, ['positional']),
() => instanceMirror.reflectee.instanceMethod('positional'),
);
}
+39 -16
View File
@@ -68,8 +68,12 @@ class MirrorsReader extends MirrorsVisitor {
errors.add(new ReadError(errorTag, exception, stackTrace));
}
visitUnsupported(var receiver, String tag, UnsupportedError? exception,
StackTrace stackTrace) {
visitUnsupported(
var receiver,
String tag,
UnsupportedError? exception,
StackTrace stackTrace,
) {
if (verbose) print('visitUnsupported:$receiver.$tag:$exception');
if (!expectUnsupported(receiver, tag, exception) &&
!allowUnsupported(receiver, tag, exception)) {
@@ -79,13 +83,17 @@ class MirrorsReader extends MirrorsVisitor {
/// Override to specify that access is expected to be unsupported.
bool expectUnsupported(
var receiver, String tag, UnsupportedError? exception) =>
false;
var receiver,
String tag,
UnsupportedError? exception,
) => false;
/// Override to allow unsupported access.
bool allowUnsupported(
var receiver, String tag, UnsupportedError? exception) =>
false;
var receiver,
String tag,
UnsupportedError? exception,
) => false;
/// Evaluates the function [f]. Subclasses can override this to handle
/// specific exceptions.
@@ -150,8 +158,11 @@ class MirrorsReader extends MirrorsVisitor {
visitClassMirror(ClassMirror mirror) {
super.visitClassMirror(mirror);
visit(mirror, 'declarations', () => mirror.declarations);
bool hasReflectedType =
visit(mirror, 'hasReflectedType', () => mirror.hasReflectedType);
bool hasReflectedType = visit(
mirror,
'hasReflectedType',
() => mirror.hasReflectedType,
);
visit(mirror, 'instanceMembers', () => mirror.instanceMembers);
visit(mirror, 'mixin', () => mirror.mixin);
if (hasReflectedType) {
@@ -182,8 +193,11 @@ class MirrorsReader extends MirrorsVisitor {
visitInstanceMirror(InstanceMirror mirror) {
super.visitInstanceMirror(mirror);
bool hasReflectee =
visit(mirror, 'hasReflectee', () => mirror.hasReflectee);
bool hasReflectee = visit(
mirror,
'hasReflectee',
() => mirror.hasReflectee,
);
if (hasReflectee) {
visit(mirror, 'reflectee', () => mirror.reflectee);
}
@@ -203,12 +217,18 @@ class MirrorsReader extends MirrorsVisitor {
visit(mirror, 'isConstConstructor', () => mirror.isConstConstructor);
visit(mirror, 'isConstructor', () => mirror.isConstructor);
visit(mirror, 'isFactoryConstructor', () => mirror.isFactoryConstructor);
visit(mirror, 'isGenerativeConstructor',
() => mirror.isGenerativeConstructor);
visit(
mirror,
'isGenerativeConstructor',
() => mirror.isGenerativeConstructor,
);
visit(mirror, 'isGetter', () => mirror.isGetter);
visit(mirror, 'isOperator', () => mirror.isOperator);
visit(mirror, 'isRedirectingConstructor',
() => mirror.isRedirectingConstructor);
visit(
mirror,
'isRedirectingConstructor',
() => mirror.isRedirectingConstructor,
);
visit(mirror, 'isRegularMethod', () => mirror.isRegularMethod);
visit(mirror, 'isSetter', () => mirror.isSetter);
visit(mirror, 'isStatic', () => mirror.isStatic);
@@ -220,8 +240,11 @@ class MirrorsReader extends MirrorsVisitor {
visitParameterMirror(ParameterMirror mirror) {
super.visitParameterMirror(mirror);
bool hasDefaultValue =
visit(mirror, 'hasDefaultValue', () => mirror.hasDefaultValue);
bool hasDefaultValue = visit(
mirror,
'hasDefaultValue',
() => mirror.hasDefaultValue,
);
if (hasDefaultValue) {
visit(mirror, 'defaultValue', () => mirror.defaultValue);
}
+16 -9
View File
@@ -14,11 +14,13 @@ class RuntimeMirrorsReader extends MirrorsReader {
final MirrorSystem mirrorSystem;
final String mirrorSystemType;
RuntimeMirrorsReader(MirrorSystem mirrorSystem,
{bool verbose = false, bool includeStackTrace = false})
: this.mirrorSystem = mirrorSystem,
this.mirrorSystemType = '${mirrorSystem.runtimeType}',
super(verbose: verbose, includeStackTrace: includeStackTrace);
RuntimeMirrorsReader(
MirrorSystem mirrorSystem, {
bool verbose = false,
bool includeStackTrace = false,
}) : this.mirrorSystem = mirrorSystem,
this.mirrorSystemType = '${mirrorSystem.runtimeType}',
super(verbose: verbose, includeStackTrace: includeStackTrace);
visitLibraryMirror(LibraryMirror mirror) {
super.visitLibraryMirror(mirror);
@@ -46,7 +48,10 @@ class RuntimeMirrorsReader extends MirrorsReader {
}
bool expectUnsupported(
var receiver, String tag, UnsupportedError? exception) {
var receiver,
String tag,
UnsupportedError? exception,
) {
// [DeclarationMirror.location] is intentionally not supported in runtime
// mirrors.
@@ -64,8 +69,10 @@ class RuntimeMirrorsReader extends MirrorsReader {
void main([List<String> arguments = const <String>[]]) {
MirrorSystem mirrors = currentMirrorSystem();
MirrorsReader reader = new RuntimeMirrorsReader(mirrors,
verbose: arguments.contains('-v'),
includeStackTrace: arguments.contains('-s'));
MirrorsReader reader = new RuntimeMirrorsReader(
mirrors,
verbose: arguments.contains('-v'),
includeStackTrace: arguments.contains('-s'),
);
reader.checkMirrorSystem(mirrors);
}
+48 -27
View File
@@ -41,20 +41,26 @@ testInvoke(mirrors) {
var instance = new Class();
var instMirror = reflect(instance);
expect(instMirror.invoke(#m, ['A', 'B', instance]).reflectee,
equals({"a": 'A', "b": 'B', "c": instance}));
expect(
instMirror.invoke(#m, ['A', 'B', instance]).reflectee,
equals({"a": 'A', "b": 'B', "c": instance}),
);
expect(instMirror.invoke(#notDefined, []).reflectee, equals("DNU"));
expect(instMirror.invoke(#m, []).reflectee, equals("DNU")); // Wrong arity.
var classMirror = instMirror.type;
expect(classMirror.invoke(#s, ['A', 'B', instance]).reflectee,
equals({"a": 'A', "b": 'B', "c": instance}));
expect(
classMirror.invoke(#s, ['A', 'B', instance]).reflectee,
equals({"a": 'A', "b": 'B', "c": instance}),
);
expect(() => classMirror.invoke(#notDefined, []).reflectee, throws);
expect(() => classMirror.invoke(#s, []).reflectee, throws); // Wrong arity.
var libMirror = classMirror.owner as LibraryMirror;
expect(libMirror.invoke(#u, ['A', 'B', instance]).reflectee,
equals({"a": 'A', "b": 'B', "c": instance}));
expect(
libMirror.invoke(#u, ['A', 'B', instance]).reflectee,
equals({"a": 'A', "b": 'B', "c": instance}),
);
expect(() => libMirror.invoke(#notDefined, []).reflectee, throws);
expect(() => libMirror.invoke(#u, []).reflectee, throws); // Wrong arity.
}
@@ -77,12 +83,15 @@ testIntercepted(mirrors) {
expect(instance.length, equals(44));
expect(
instMirror.invoke(#toString, []).reflectee,
equals('[null, null, null, null, null, null, null, null, null, null,'
' null, null, null, null, null, null, null, null, null, null,'
' null, null, null, null, null, null, null, null, null, null,'
' null, null, null, null, null, null, null, null, null, null,'
' null, null, null, null]'));
instMirror.invoke(#toString, []).reflectee,
equals(
'[null, null, null, null, null, null, null, null, null, null,'
' null, null, null, null, null, null, null, null, null, null,'
' null, null, null, null, null, null, null, null, null, null,'
' null, null, null, null, null, null, null, null, null, null,'
' null, null, null, null]',
),
);
}
testFieldAccess(mirrors) {
@@ -148,8 +157,9 @@ testReflectClass(mirrors) {
var classMirror = reflectClass(Class);
expect(classMirror is ClassMirror, equals(true));
var symbolClassMirror = reflectClass(Symbol);
var symbolMirror =
symbolClassMirror.newInstance(Symbol.empty, ['withInitialValue']);
var symbolMirror = symbolClassMirror.newInstance(Symbol.empty, [
'withInitialValue',
]);
var objectMirror = classMirror.newInstance(symbolMirror.reflectee, [1234]);
expect(objectMirror.reflectee is Class, equals(true));
expect(objectMirror.reflectee.field, equals(1234));
@@ -171,27 +181,37 @@ testNames(mirrors) {
TypeVariableMirror typeVariable = classMirror.typeVariables.single;
expect(typeVariable.simpleName, equals(#T));
expect(
typeVariable.qualifiedName, equals(const Symbol('MirrorsTest.Class.T')));
typeVariable.qualifiedName,
equals(const Symbol('MirrorsTest.Class.T')),
);
if (!isDart2js) {
// TODO(ahe): Implement this in dart2js.
expect(typedefMirror.simpleName, equals(#Typedef));
expect(typedefMirror.qualifiedName,
equals(const Symbol('MirrorsTest.Typedef')));
expect(
typedefMirror.qualifiedName,
equals(const Symbol('MirrorsTest.Typedef')),
);
var typedefMirrorDeNovo = reflectType(Typedef);
expect(typedefMirrorDeNovo.simpleName, equals(#Typedef));
expect(typedefMirrorDeNovo.qualifiedName,
equals(const Symbol('MirrorsTest.Typedef')));
expect(
typedefMirrorDeNovo.qualifiedName,
equals(const Symbol('MirrorsTest.Typedef')),
);
}
expect(methodMirror.simpleName, equals(#testNames));
expect(methodMirror.qualifiedName,
equals(const Symbol('MirrorsTest.testNames')));
expect(
methodMirror.qualifiedName,
equals(const Symbol('MirrorsTest.testNames')),
);
expect(variableMirror.simpleName, equals(#field));
expect(variableMirror.qualifiedName,
equals(const Symbol('MirrorsTest.Class.field')));
expect(
variableMirror.qualifiedName,
equals(const Symbol('MirrorsTest.Class.field')),
);
}
testLibraryUri(var value, bool check(Uri uri)) {
@@ -225,10 +245,11 @@ main() {
});
test("Test current library uri", () {
testLibraryUri(
new Class(),
// TODO(floitsch): change this to "/mirrors_test.dart" when
// dart2js_mirrors_test.dart has been removed.
(Uri uri) => uri.path.endsWith('mirrors_test.dart'));
new Class(),
// TODO(floitsch): change this to "/mirrors_test.dart" when
// dart2js_mirrors_test.dart has been removed.
(Uri uri) => uri.path.endsWith('mirrors_test.dart'),
);
});
test("Test dart library uri", () {
testLibraryUri("test", (Uri uri) {
+2 -1
View File
@@ -36,7 +36,8 @@ abstract class MirrorsVisitor {
visitDeclarationMirror(mirror);
} else {
throw new StateError(
'Unexpected mirror kind ${mirror.runtimeType}: $mirror');
'Unexpected mirror kind ${mirror.runtimeType}: $mirror',
);
}
}
@@ -11,27 +11,19 @@ import 'package:expect/expect.dart';
class A {
var req1, opt1, opt2;
A.a0([opt1]) : this.opt1 = opt1;
A.b0([opt1, opt2])
: this.opt1 = opt1,
this.opt2 = opt2;
A.b0([opt1, opt2]) : this.opt1 = opt1, this.opt2 = opt2;
A.c0([opt1 = 499]) : this.opt1 = opt1;
A.d0([opt1 = 499, opt2 = 42])
: this.opt1 = opt1,
this.opt2 = opt2;
A.a1(req1, [opt1])
: this.req1 = req1,
this.opt1 = opt1;
A.d0([opt1 = 499, opt2 = 42]) : this.opt1 = opt1, this.opt2 = opt2;
A.a1(req1, [opt1]) : this.req1 = req1, this.opt1 = opt1;
A.b1(req1, [opt1, opt2])
: this.req1 = req1,
this.opt1 = opt1,
this.opt2 = opt2;
A.c1(req1, [opt1 = 499])
: this.req1 = req1,
this.opt1 = opt1;
: this.req1 = req1,
this.opt1 = opt1,
this.opt2 = opt2;
A.c1(req1, [opt1 = 499]) : this.req1 = req1, this.opt1 = opt1;
A.d1(req1, [opt1 = 499, opt2 = 42])
: this.req1 = req1,
this.opt1 = opt1,
this.opt2 = opt2;
: this.req1 = req1,
this.opt1 = opt1,
this.opt2 = opt2;
}
main() {
@@ -38,8 +38,9 @@ main() {
Expect.equals(String, c_string.s);
Expect.equals(dynamic, c_dynamic.s);
dynamic reflective_a_int =
cmB.superclass!.newInstance(Symbol.empty, []).reflectee;
dynamic reflective_a_int = cmB.superclass!
.newInstance(Symbol.empty, [])
.reflectee;
dynamic reflective_a_dynamic = cmA.newInstance(Symbol.empty, []).reflectee;
dynamic reflective_b = cmB.newInstance(Symbol.empty, []).reflectee;
dynamic reflective_c_dynamic = cmC.newInstance(Symbol.empty, []).reflectee;
+17 -8
View File
@@ -20,8 +20,10 @@ void test() {
InstanceMirror im1 = reflect(null);
Expect.equals(cm, im1.type);
if (!unsoundNullSafety) {
Expect.throwsTypeError(() => im1.invoke(const Symbol("=="), [null]),
'null not assignable to Object');
Expect.throwsTypeError(
() => im1.invoke(const Symbol("=="), [null]),
'null not assignable to Object',
);
} else {
Expect.isTrue(im1.invoke(const Symbol("=="), [null]).reflectee);
}
@@ -31,8 +33,10 @@ void test() {
InstanceMirror im2 = reflect(obj);
Expect.equals(cm, im2.type);
if (!unsoundNullSafety) {
Expect.throwsTypeError(() => im2.invoke(const Symbol("=="), [null]),
'null not assignable to Object');
Expect.throwsTypeError(
() => im2.invoke(const Symbol("=="), [null]),
'null not assignable to Object',
);
} else {
Expect.isTrue(im2.invoke(const Symbol("=="), [null]).reflectee);
}
@@ -44,14 +48,18 @@ void test() {
Expect.equals('Null', nullMirror.getField(#runtimeType).reflectee.toString());
if (!unsoundNullSafety) {
Expect.throwsTypeError(
() => nullMirror.invoke(#==, [null]), 'null not assignable to Object');
() => nullMirror.invoke(#==, [null]),
'null not assignable to Object',
);
} else {
Expect.isTrue(nullMirror.invoke(#==, [null]).reflectee);
}
Expect.isFalse(nullMirror.invoke(#==, [new Object()]).reflectee);
Expect.equals('null', nullMirror.invoke(#toString, []).reflectee);
Expect.throwsNoSuchMethodError(
() => nullMirror.invoke(#notDefined, []), 'noSuchMethod');
() => nullMirror.invoke(#notDefined, []),
'noSuchMethod',
);
ClassMirror NullMirror = nullMirror.type;
Expect.equals(reflectClass(Null), NullMirror);
@@ -63,8 +71,9 @@ void test() {
LibraryMirror? coreLibrary = libraries[Uri.parse('dart:core')];
if (coreLibrary == null) {
// In minified mode we don't preserve the URIs.
coreLibrary = libraries.values
.firstWhere((LibraryMirror lm) => lm.simpleName == #dart.core);
coreLibrary = libraries.values.firstWhere(
(LibraryMirror lm) => lm.simpleName == #dart.core,
);
Uri uri = coreLibrary.uri;
Expect.equals("https", uri.scheme);
Expect.equals("dartlang.org", uri.host);
+6 -3
View File
@@ -61,7 +61,8 @@ void main() {
expect(RETURN_TYPES, returnTypes);
}
const String OPERATORS = '{'
const String OPERATORS =
'{'
'%: Method(s(%) in s(Foo)), '
'&: Method(s(&) in s(Foo)), '
'*: Method(s(*) in s(Foo)), '
@@ -92,7 +93,8 @@ const String INT = 'Class(s(int) in s(dart.core), top-level)';
const String BOOL = 'Class(s(bool) in s(dart.core), top-level)';
const String PARAMETERS = '{'
const String PARAMETERS =
'{'
'%: [Parameter(s(a) in s(%), type = $FOO)], '
'&: [Parameter(s(a) in s(&), type = $FOO)], '
'*: [Parameter(s(a) in s(*), type = $FOO)], '
@@ -116,7 +118,8 @@ const String PARAMETERS = '{'
'~/: [Parameter(s(a) in s(~/), type = $FOO)]'
'}';
const String RETURN_TYPES = '{'
const String RETURN_TYPES =
'{'
'%: $FOO, '
'&: $FOO, '
'*: $FOO, '
@@ -24,11 +24,17 @@ class C<S, @metadata T> {
// We only check for a suffix of the uri because the test might be run from
// any number of absolute paths.
expectLocation(
DeclarationMirror mirror, String uriSuffix, int line, int column) {
DeclarationMirror mirror,
String uriSuffix,
int line,
int column,
) {
SourceLocation location = mirror.location!;
Uri uri = location.sourceUri;
Expect.isTrue(
uri.toString().endsWith(uriSuffix), "Expected suffix $uriSuffix in $uri");
uri.toString().endsWith(uriSuffix),
"Expected suffix $uriSuffix in $uri",
);
Expect.equals(line, location.line, "line");
Expect.equals(column, location.column, "column");
}
@@ -50,8 +56,16 @@ main() {
// Libraries.
expectLocation(reflectClass(C).owner!, mainSuffix, 5, 1);
expectLocation(reflectClass(ClassInLibraryWithoutDeclaration).owner!,
"library_without_declaration.dart", 1, 1);
expectLocation(reflectClass(ClassInLibraryWithAnnotatedDeclaration).owner!,
"library_with_annotated_declaration.dart", 5, 1);
expectLocation(
reflectClass(ClassInLibraryWithoutDeclaration).owner!,
"library_without_declaration.dart",
1,
1,
);
expectLocation(
reflectClass(ClassInLibraryWithAnnotatedDeclaration).owner!,
"library_with_annotated_declaration.dart",
5,
1,
);
}
@@ -21,12 +21,15 @@ main() {
MethodMirror foo1 = cm.declarations[#foo1] as MethodMirror;
expect('Method(s(foo1) in s(C), abstract)', foo1);
expect(
'Parameter(s(x) in s(foo1), optional, named, type = Class(s(int) in s(dart.core), top-level))',
foo1.parameters[0]);
'Parameter(s(x) in s(foo1), optional, named, type = Class(s(int) in s(dart.core), top-level))',
foo1.parameters[0],
);
expect(
'Parameter(s(y) in s(foo1), optional, named, type = Class(s(int) in s(dart.core), top-level))',
foo1.parameters[1]);
'Parameter(s(y) in s(foo1), optional, named, type = Class(s(int) in s(dart.core), top-level))',
foo1.parameters[1],
);
expect(
'Parameter(s(z) in s(foo1), optional, named, type = Class(s(int) in s(dart.core), top-level))',
foo1.parameters[2]);
'Parameter(s(z) in s(foo1), optional, named, type = Class(s(int) in s(dart.core), top-level))',
foo1.parameters[2],
);
}
@@ -15,7 +15,9 @@ class Foo {
Foo(@ParameterAnnotation("vogel") p) {}
Foo.named(@ParameterAnnotation("hamster") p) {}
Foo.named2(
@ParameterAnnotation("hamster") p, @ParameterAnnotation("wurm") p2) {}
@ParameterAnnotation("hamster") p,
@ParameterAnnotation("wurm") p2,
) {}
f1(@ParameterAnnotation("hest") p) {}
f2(@ParameterAnnotation("hest") @ParameterAnnotation("fisk") p) {}
@@ -28,18 +30,26 @@ class Foo {
}
expectAnnotations(
Type type, Symbol method, int parameterIndex, List<String> expectedValues) {
Type type,
Symbol method,
int parameterIndex,
List<String> expectedValues,
) {
MethodMirror mirror = reflectClass(type).declarations[method] as MethodMirror;
ParameterMirror parameter = mirror.parameters[parameterIndex];
List<InstanceMirror> annotations = parameter.metadata;
Expect.equals(annotations.length, expectedValues.length,
"wrong number of parameter annotations");
Expect.equals(
annotations.length,
expectedValues.length,
"wrong number of parameter annotations",
);
for (int i = 0; i < annotations.length; i++) {
Expect.equals(
expectedValues[i],
annotations[i].reflectee.value,
"annotation #$i of parameter #$parameterIndex "
"of $type.$method.");
expectedValues[i],
annotations[i].reflectee.value,
"annotation #$i of parameter #$parameterIndex "
"of $type.$method.",
);
}
}
@@ -27,38 +27,47 @@ testPositional() {
MethodMirror positional1 = cm.declarations[#positional1] as MethodMirror;
expect('Method(s(positional1) in s(C))', positional1);
expect(
'Parameter(s(x) in s(positional1), optional, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
positional1.parameters[3]);
'Parameter(s(x) in s(positional1), optional, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
positional1.parameters[3],
);
expect(
'Parameter(s(y) in s(positional1), optional, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
positional1.parameters[4]);
'Parameter(s(y) in s(positional1), optional, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
positional1.parameters[4],
);
expect(
'Parameter(s(z) in s(positional1), optional, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
positional1.parameters[5]);
'Parameter(s(z) in s(positional1), optional, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
positional1.parameters[5],
);
MethodMirror positional2 = cm.declarations[#positional2] as MethodMirror;
expect('Method(s(positional2) in s(C))', positional2);
expect(
'Parameter(s(y) in s(positional2), optional, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
positional2.parameters[3]);
'Parameter(s(y) in s(positional2), optional, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
positional2.parameters[3],
);
expect(
'Parameter(s(z) in s(positional2), optional, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
positional2.parameters[4]);
'Parameter(s(z) in s(positional2), optional, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
positional2.parameters[4],
);
expect(
'Parameter(s(x) in s(positional2), optional, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
positional2.parameters[5]);
'Parameter(s(x) in s(positional2), optional, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
positional2.parameters[5],
);
MethodMirror positional3 = cm.declarations[#positional3] as MethodMirror;
expect('Method(s(positional3) in s(C))', positional3);
expect(
'Parameter(s(z) in s(positional3), optional, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
positional3.parameters[3]);
'Parameter(s(z) in s(positional3), optional, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
positional3.parameters[3],
);
expect(
'Parameter(s(x) in s(positional3), optional, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
positional3.parameters[4]);
'Parameter(s(x) in s(positional3), optional, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
positional3.parameters[4],
);
expect(
'Parameter(s(y) in s(positional3), optional, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
positional3.parameters[5]);
'Parameter(s(y) in s(positional3), optional, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
positional3.parameters[5],
);
}
testNamed() {
@@ -67,38 +76,47 @@ testNamed() {
MethodMirror named1 = cm.declarations[#named1] as MethodMirror;
expect('Method(s(named1) in s(C))', named1);
expect(
'Parameter(s(x) in s(named1), optional, named, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
named1.parameters[3]);
'Parameter(s(x) in s(named1), optional, named, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
named1.parameters[3],
);
expect(
'Parameter(s(y) in s(named1), optional, named, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
named1.parameters[4]);
'Parameter(s(y) in s(named1), optional, named, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
named1.parameters[4],
);
expect(
'Parameter(s(z) in s(named1), optional, named, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
named1.parameters[5]);
'Parameter(s(z) in s(named1), optional, named, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
named1.parameters[5],
);
MethodMirror named2 = cm.declarations[#named2] as MethodMirror;
expect('Method(s(named2) in s(C))', named2);
expect(
'Parameter(s(y) in s(named2), optional, named, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
named2.parameters[3]);
'Parameter(s(y) in s(named2), optional, named, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
named2.parameters[3],
);
expect(
'Parameter(s(z) in s(named2), optional, named, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
named2.parameters[4]);
'Parameter(s(z) in s(named2), optional, named, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
named2.parameters[4],
);
expect(
'Parameter(s(x) in s(named2), optional, named, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
named2.parameters[5]);
'Parameter(s(x) in s(named2), optional, named, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
named2.parameters[5],
);
MethodMirror named3 = cm.declarations[#named3] as MethodMirror;
expect('Method(s(named3) in s(C))', named3);
expect(
'Parameter(s(z) in s(named3), optional, named, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
named3.parameters[3]);
'Parameter(s(z) in s(named3), optional, named, value = Instance(value = 1), type = Class(s(int) in s(dart.core), top-level))',
named3.parameters[3],
);
expect(
'Parameter(s(x) in s(named3), optional, named, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
named3.parameters[4]);
'Parameter(s(x) in s(named3), optional, named, value = Instance(value = 2), type = Class(s(int) in s(dart.core), top-level))',
named3.parameters[4],
);
expect(
'Parameter(s(y) in s(named3), optional, named, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
named3.parameters[5]);
'Parameter(s(y) in s(named3), optional, named, value = Instance(value = 3), type = Class(s(int) in s(dart.core), top-level))',
named3.parameters[5],
);
}
main() {
+85 -61
View File
@@ -52,85 +52,105 @@ main() {
#B.foo,
#B.quux,
#B.qux,
#B.corge
#B.corge,
];
Expect.setEquals(constructorKeys, constructors.keys);
MethodMirror unnamedConstructor = constructors[#B] as MethodMirror;
expect('Method(s(B) in s(B), constructor)', unnamedConstructor);
expect('[]', unnamedConstructor.parameters);
expect('Class(s(B) in s(test.parameter_test), top-level)',
unnamedConstructor.returnType);
expect(
'Class(s(B) in s(test.parameter_test), top-level)',
unnamedConstructor.returnType,
);
MethodMirror fooConstructor = constructors[#B.foo] as MethodMirror;
expect('Method(s(B.foo) in s(B), constructor)', fooConstructor);
expect(
'[Parameter(s(x) in s(B.foo),'
' type = Class(s(int) in s(dart.core), top-level))]',
fooConstructor.parameters);
expect('Class(s(B) in s(test.parameter_test), top-level)',
fooConstructor.returnType);
'[Parameter(s(x) in s(B.foo),'
' type = Class(s(int) in s(dart.core), top-level))]',
fooConstructor.parameters,
);
expect(
'Class(s(B) in s(test.parameter_test), top-level)',
fooConstructor.returnType,
);
MethodMirror barConstructor = constructors[#B.bar] as MethodMirror;
expect('Method(s(B.bar) in s(B), constructor)', barConstructor);
expect(
'[Parameter(s(z) in s(B.bar),'
' type = Class(s(int) in s(dart.core), top-level)), '
'Parameter(s(x) in s(B.bar),'
' type = Type(s(dynamic), top-level))]',
barConstructor.parameters);
expect('Class(s(B) in s(test.parameter_test), top-level)',
barConstructor.returnType);
'[Parameter(s(z) in s(B.bar),'
' type = Class(s(int) in s(dart.core), top-level)), '
'Parameter(s(x) in s(B.bar),'
' type = Type(s(dynamic), top-level))]',
barConstructor.parameters,
);
expect(
'Class(s(B) in s(test.parameter_test), top-level)',
barConstructor.returnType,
);
MethodMirror bazConstructor = constructors[#B.baz] as MethodMirror;
expect('Method(s(B.baz) in s(B), constructor)', bazConstructor);
expect(
'[Parameter(s(x) in s(B.baz), final,'
' type = Class(s(int) in s(dart.core), top-level)), '
'Parameter(s(y) in s(B.baz),'
' type = Class(s(int) in s(dart.core), top-level)), '
'Parameter(s(z) in s(B.baz), final,'
' type = Class(s(int) in s(dart.core), top-level))]',
bazConstructor.parameters);
expect('Class(s(B) in s(test.parameter_test), top-level)',
bazConstructor.returnType);
'[Parameter(s(x) in s(B.baz), final,'
' type = Class(s(int) in s(dart.core), top-level)), '
'Parameter(s(y) in s(B.baz),'
' type = Class(s(int) in s(dart.core), top-level)), '
'Parameter(s(z) in s(B.baz), final,'
' type = Class(s(int) in s(dart.core), top-level))]',
bazConstructor.parameters,
);
expect(
'Class(s(B) in s(test.parameter_test), top-level)',
bazConstructor.returnType,
);
MethodMirror quxConstructor = constructors[#B.qux] as MethodMirror;
expect('Method(s(B.qux) in s(B), constructor)', quxConstructor);
expect(
'[Parameter(s(x) in s(B.qux),'
' type = Class(s(int) in s(dart.core), top-level)), '
'Parameter(s(y) in s(B.qux), optional,'
' value = Instance(value = 4),'
' type = Class(s(int) in s(dart.core), top-level))]',
quxConstructor.parameters);
expect('Class(s(B) in s(test.parameter_test), top-level)',
quxConstructor.returnType);
'[Parameter(s(x) in s(B.qux),'
' type = Class(s(int) in s(dart.core), top-level)), '
'Parameter(s(y) in s(B.qux), optional,'
' value = Instance(value = 4),'
' type = Class(s(int) in s(dart.core), top-level))]',
quxConstructor.parameters,
);
expect(
'Class(s(B) in s(test.parameter_test), top-level)',
quxConstructor.returnType,
);
MethodMirror quuxConstructor = constructors[#B.quux] as MethodMirror;
expect('Method(s(B.quux) in s(B), constructor)', quuxConstructor);
expect(
'[Parameter(s(x) in s(B.quux),'
' type = Class(s(int) in s(dart.core), top-level)), '
'Parameter(s(str) in s(B.quux), optional, named,'
' value = Instance(value = foo),'
' type = Class(s(String) in s(dart.core), top-level))]',
quuxConstructor.parameters);
expect('Class(s(B) in s(test.parameter_test), top-level)',
quuxConstructor.returnType);
'[Parameter(s(x) in s(B.quux),'
' type = Class(s(int) in s(dart.core), top-level)), '
'Parameter(s(str) in s(B.quux), optional, named,'
' value = Instance(value = foo),'
' type = Class(s(String) in s(dart.core), top-level))]',
quuxConstructor.parameters,
);
expect(
'Class(s(B) in s(test.parameter_test), top-level)',
quuxConstructor.returnType,
);
MethodMirror corgeConstructor = constructors[#B.corge] as MethodMirror;
expect('Method(s(B.corge) in s(B), constructor)', corgeConstructor);
expect(
'[Parameter(s(x) in s(B.corge), optional, named,'
' value = Instance(value = 51),'
' type = Class(s(int) in s(dart.core), top-level)), '
'Parameter(s(str) in s(B.corge), optional, named,'
' value = Instance(value = bar),'
' type = Class(s(String) in s(dart.core), top-level))]',
corgeConstructor.parameters);
expect('Class(s(B) in s(test.parameter_test), top-level)',
corgeConstructor.returnType);
'[Parameter(s(x) in s(B.corge), optional, named,'
' value = Instance(value = 51),'
' type = Class(s(int) in s(dart.core), top-level)), '
'Parameter(s(str) in s(B.corge), optional, named,'
' value = Instance(value = bar),'
' type = Class(s(String) in s(dart.core), top-level))]',
corgeConstructor.parameters,
);
expect(
'Class(s(B) in s(test.parameter_test), top-level)',
corgeConstructor.returnType,
);
MethodMirror xGetter = cm.declarations[#x] as MethodMirror;
expect('Method(s(x) in s(B), getter)', xGetter);
@@ -139,32 +159,36 @@ main() {
MethodMirror xSetter = cm.declarations[const Symbol('x=')] as MethodMirror;
expect('Method(s(x=) in s(B), setter)', xSetter);
expect(
'[Parameter(s(value) in s(x=), final,'
' type = Type(s(dynamic), top-level))]',
xSetter.parameters);
'[Parameter(s(value) in s(x=), final,'
' type = Type(s(dynamic), top-level))]',
xSetter.parameters,
);
MethodMirror grault = cm.declarations[#grault] as MethodMirror;
expect('Method(s(grault) in s(B))', grault);
expect(
'[Parameter(s(x) in s(grault), optional, value = Instance(value = 0),'
' type = Class(s(int) in s(dart.core), top-level))]',
grault.parameters);
'[Parameter(s(x) in s(grault), optional, value = Instance(value = 0),'
' type = Class(s(int) in s(dart.core), top-level))]',
grault.parameters,
);
expect('Instance(value = 0)', grault.parameters[0].defaultValue);
MethodMirror garply = cm.declarations[#garply] as MethodMirror;
expect('Method(s(garply) in s(B))', garply);
expect(
'[Parameter(s(y) in s(garply), optional, named, value = Instance(value = 0),'
' type = Class(s(int) in s(dart.core), top-level))]',
garply.parameters);
'[Parameter(s(y) in s(garply), optional, named, value = Instance(value = 0),'
' type = Class(s(int) in s(dart.core), top-level))]',
garply.parameters,
);
expect('Instance(value = 0)', garply.parameters[0].defaultValue);
MethodMirror waldo = cm.declarations[#waldo] as MethodMirror;
expect('Method(s(waldo) in s(B))', waldo);
expect(
'[Parameter(s(z) in s(waldo),'
' type = Class(s(int) in s(dart.core), top-level))]',
waldo.parameters);
'[Parameter(s(z) in s(waldo),'
' type = Class(s(int) in s(dart.core), top-level))]',
waldo.parameters,
);
expect('<null>', waldo.parameters[0].defaultValue);
cm = reflectClass(C);
+9 -6
View File
@@ -56,10 +56,11 @@ class CarolCaretaker implements Carol {
CarolCaretaker(this._carol, this._gate);
foo() {
if (!_gate()) throw new NoSuchMethodError.withInvocation(
this,
Invocation.method(#foo, [], {}),
);
if (!_gate())
throw new NoSuchMethodError.withInvocation(
this,
Invocation.method(#foo, [], {}),
);
return _carol.foo();
}
@@ -73,8 +74,10 @@ main() {
Alice alice2 = new Alice();
alice2.sayFooAttenuated();
Expect.throwsNoSuchMethodError(() => alice2.sayBar(),
'Authority should have been attenuated');
Expect.throwsNoSuchMethodError(
() => alice2.sayBar(),
'Authority should have been attenuated',
);
// At the base level, a caretaker for a Carol masquerades as a Carol.
CarolCaretaker caretaker = new CarolCaretaker(new Carol(), () => true);
@@ -19,6 +19,8 @@ main() {
ClassMirror m = reflectClass(A);
var i = m.newInstance(Symbol.empty, []).reflectee;
var s = i.t.toString();
Expect.isTrue(s == 'A' || s == 'A<dynamic>',
'mirrors should create the correct reified generic type');
Expect.isTrue(
s == 'A' || s == 'A<dynamic>',
'mirrors should create the correct reified generic type',
);
}
+34 -23
View File
@@ -77,44 +77,55 @@ main() {
Expect.equals(89, fieldC);
expect(
'{accessor: Method(s(accessor) in s(A), getter)'
'}',
gettersOf(aClass));
'{accessor: Method(s(accessor) in s(A), getter)'
'}',
gettersOf(aClass),
);
expect(
'{accessor: Method(s(accessor) in s(B), getter)'
', field: Method(s(field) in s(B), getter)}',
gettersOf(bClass));
'{accessor: Method(s(accessor) in s(B), getter)'
', field: Method(s(field) in s(B), getter)}',
gettersOf(bClass),
);
expect('{accessor: Method(s(accessor) in s(C), getter)}', gettersOf(cClass));
expect(
'{accessor=: Method(s(accessor=) in s(A), setter)'
'}',
settersOf(aClass));
'{accessor=: Method(s(accessor=) in s(A), setter)'
'}',
settersOf(aClass),
);
expect(
'{accessor=: Method(s(accessor=) in s(B), setter)}', settersOf(bClass));
'{accessor=: Method(s(accessor=) in s(B), setter)}',
settersOf(bClass),
);
expect(
'{accessor=: Method(s(accessor=) in s(C), setter)'
', field=: Method(s(field=) in s(C), setter)}',
settersOf(cClass));
'{accessor=: Method(s(accessor=) in s(C), setter)'
', field=: Method(s(field=) in s(C), setter)}',
settersOf(cClass),
);
Expect.equals('A:instanceMethod(7)', a.invoke(instanceMethod, [7]).reflectee);
Expect.equals('B:instanceMethod(9)', b.invoke(instanceMethod, [9]).reflectee);
Expect.equals(
'C:instanceMethod(13)', c.invoke(instanceMethod, [13]).reflectee);
'C:instanceMethod(13)',
c.invoke(instanceMethod, [13]).reflectee,
);
expect(
'{aMethod: Method(s(aMethod) in s(A))'
', instanceMethod: Method(s(instanceMethod) in s(A))}',
methodsOf(aClass));
'{aMethod: Method(s(aMethod) in s(A))'
', instanceMethod: Method(s(instanceMethod) in s(A))}',
methodsOf(aClass),
);
expect(
'{bMethod: Method(s(bMethod) in s(B))'
', instanceMethod: Method(s(instanceMethod) in s(B))}',
methodsOf(bClass));
'{bMethod: Method(s(bMethod) in s(B))'
', instanceMethod: Method(s(instanceMethod) in s(B))}',
methodsOf(bClass),
);
expect(
'{cMethod: Method(s(cMethod) in s(C))'
', instanceMethod: Method(s(instanceMethod) in s(C))}',
methodsOf(cClass));
'{cMethod: Method(s(cMethod) in s(C))'
', instanceMethod: Method(s(instanceMethod) in s(C))}',
methodsOf(cClass),
);
Expect.equals('A:get accessor', a.getField(accessor).reflectee);
Expect.equals('B:get accessor', b.getField(accessor).reflectee);
@@ -20,5 +20,6 @@ main() {
print(field);
}
publicFields(ClassMirror mirror) => mirror.declarations.values
.where((x) => x is VariableMirror && !(x.isPrivate || x.isStatic));
publicFields(ClassMirror mirror) => mirror.declarations.values.where(
(x) => x is VariableMirror && !(x.isPrivate || x.isStatic),
);
@@ -20,5 +20,6 @@ main() {
print(field);
}
publicFields(ClassMirror mirror) => mirror.declarations.values
.where((x) => x is VariableMirror && !(x.isPrivate || x.isStatic));
publicFields(ClassMirror mirror) => mirror.declarations.values.where(
(x) => x is VariableMirror && !(x.isPrivate || x.isStatic),
);
+4 -2
View File
@@ -10,8 +10,10 @@ import 'package:expect/expect.dart';
expectReflectedType(TypeMirror typeMirror, Type? expectedType) {
if (expectedType == null) {
Expect.isFalse(typeMirror.hasReflectedType);
Expect.throwsUnsupportedError(() => typeMirror.reflectedType,
"Should not have a reflected type");
Expect.throwsUnsupportedError(
() => typeMirror.reflectedType,
"Should not have a reflected type",
);
} else {
Expect.isTrue(typeMirror.hasReflectedType);
Expect.equals(expectedType, typeMirror.reflectedType);
+6 -2
View File
@@ -23,7 +23,11 @@ main() {
ParameterMirror gParamMirror =
(reflectType(g) as TypedefMirror).referent.parameters[0];
Expect.equals(
'.A', MirrorSystem.getName(fParamMirror.metadata[0].type.qualifiedName));
'.A',
MirrorSystem.getName(fParamMirror.metadata[0].type.qualifiedName),
);
Expect.equals(
'.B', MirrorSystem.getName(gParamMirror.metadata[0].type.qualifiedName));
'.B',
MirrorSystem.getName(gParamMirror.metadata[0].type.qualifiedName),
);
}
+4 -2
View File
@@ -14,6 +14,8 @@ class A {
}
main() {
Expect.equals('([dynamic]) -> dart.core.bool',
MirrorSystem.getName(reflect(A._defaultCheck).type.simpleName));
Expect.equals(
'([dynamic]) -> dart.core.bool',
MirrorSystem.getName(reflect(A._defaultCheck).type.simpleName),
);
}
+6 -5
View File
@@ -31,11 +31,12 @@ main() {
var methods = methodsOf(reflectClass(B));
expect(
'{f: Method(s(f) in s(B)), '
'g: Method(s(g) in s(B)), '
'h: Method(s(h) in s(B)), '
'i: Method(s(i) in s(B))}',
methods);
'{f: Method(s(f) in s(B)), '
'g: Method(s(g) in s(B)), '
'h: Method(s(h) in s(B)), '
'i: Method(s(i) in s(B))}',
methods,
);
var f = methods[#f];
var g = methods[#g];
@@ -80,7 +80,8 @@ main() {
c = new C();
im = reflect(c);
Expect.throwsNoSuchMethodError(
() => im.setField(#finalWithInheritedFinal, 23));
() => im.setField(#finalWithInheritedFinal, 23),
);
Expect.equals(14, c.finalWithInheritedFinal);
Expect.equals(5, c.superFinalWithInheritedFinal);
Expect.equals(0, c.sideEffect);
@@ -26,6 +26,8 @@ main() {
#staticMethod,
], selectKeys(cm.staticMembers, (dm) => true));
Expect.setEquals([#staticVariable, const Symbol('staticVariable=')],
selectKeys(cm.staticMembers, (dynamic dm) => dm.isSynthetic));
Expect.setEquals([
#staticVariable,
const Symbol('staticVariable='),
], selectKeys(cm.staticMembers, (dynamic dm) => dm.isSynthetic));
}
+20 -10
View File
@@ -19,15 +19,25 @@ class Foo {
}
void main() {
expect('Variable(s(aux) in s(Foo))',
reflectClass(Foo).declarations[new Symbol('aux')]);
expect('Method(s(baz) in s(Foo))',
reflectClass(Foo).declarations[new Symbol('baz')]);
expect(
'Variable(s(aux) in s(Foo))',
reflectClass(Foo).declarations[new Symbol('aux')],
);
expect(
'Method(s(baz) in s(Foo))',
reflectClass(Foo).declarations[new Symbol('baz')],
);
expect('<null>', reflectClass(Foo).declarations[new Symbol('aux=')]);
expect('Method(s(foo) in s(Foo), static)',
reflectClass(Foo).declarations[new Symbol('foo')]);
expect('Variable(s(bar) in s(Foo), static)',
reflectClass(Foo).declarations[new Symbol('bar')]);
expect('Variable(s(biz) in s(Foo), static, final, const)',
reflectClass(Foo).declarations[new Symbol('biz')]);
expect(
'Method(s(foo) in s(Foo), static)',
reflectClass(Foo).declarations[new Symbol('foo')],
);
expect(
'Variable(s(bar) in s(Foo), static)',
reflectClass(Foo).declarations[new Symbol('bar')],
);
expect(
'Variable(s(biz) in s(Foo), static, final, const)',
reflectClass(Foo).declarations[new Symbol('biz')],
);
}
+3 -2
View File
@@ -125,8 +125,9 @@ String stringifyDependencies(LibraryMirror l) {
}
return a.prefix == null ? 1 : -1;
}
return n(a.targetLibrary.simpleName)
.compareTo(n(b.targetLibrary.simpleName));
return n(
a.targetLibrary.simpleName,
).compareTo(n(b.targetLibrary.simpleName));
}
int compareCom(a, b) => n(a.identifier).compareTo(n(b.identifier));
+4 -1
View File
@@ -15,6 +15,9 @@ main() {
var superclass = cls.superclass;
Expect.isNotNull(superclass, 'Failed to obtain superclass of MyClass.');
Expect.equals(
reflectClass(Object), superclass, 'Superclass of MyClass is not Object.');
reflectClass(Object),
superclass,
'Superclass of MyClass is not Object.',
);
Expect.isNull(superclass!.superclass, 'Superclass of Object is not null.');
}
@@ -36,9 +36,10 @@ main() {
Expect.equals(reflectClass(String), mm.returnType);
pm = mm.parameters.single;
expect(
'Parameter(s(instanceField) in s(instanceField=), final,'
' type = Class(s(String) in s(dart.core), top-level))',
pm);
'Parameter(s(instanceField) in s(instanceField=), final,'
' type = Class(s(String) in s(dart.core), top-level))',
pm,
);
mm = cm.instanceMembers[#finalInstanceField] as MethodMirror;
expect('Method(s(finalInstanceField) in s(C), synthetic, getter)', mm);
@@ -57,9 +58,10 @@ main() {
Expect.equals(reflectClass(bool), mm.returnType);
pm = mm.parameters.single;
expect(
'Parameter(s(staticField) in s(staticField=), final,'
' type = Class(s(bool) in s(dart.core), top-level))',
pm);
'Parameter(s(staticField) in s(staticField=), final,'
' type = Class(s(bool) in s(dart.core), top-level))',
pm,
);
mm = cm.staticMembers[#finalStaticField] as MethodMirror;
expect('Method(s(finalStaticField) in s(C), synthetic, static, getter)', mm);
+4 -2
View File
@@ -19,8 +19,10 @@ main() {
var mirrors = currentMirrorSystem();
expect("TypeMirror on 'dynamic'", mirrors.dynamicType);
expect("TypeMirror on 'void'", mirrors.voidType);
expect("LibraryMirror on 'test.to_string_test'",
mirrors.findLibrary(#test.to_string_test));
expect(
"LibraryMirror on 'test.to_string_test'",
mirrors.findLibrary(#test.to_string_test),
);
expect("InstanceMirror on 1", reflect(1));
expect("ClassMirror on 'Foo'", reflectClass(Foo));
expect("VariableMirror on 'field'", reflectClass(Foo).declarations[#field]);
@@ -36,39 +36,53 @@ main() {
var cm3 = reflect(new Bar<List<String>, Set<String>>()).type;
expect(
'[Class(s(List) in s(dart.core), top-level),'
' Class(s(Set) in s(dart.core), top-level)]',
cm.typeArguments);
'[Class(s(List) in s(dart.core), top-level),'
' Class(s(Set) in s(dart.core), top-level)]',
cm.typeArguments,
);
expect(
'[Class(s(List) in s(dart.core), top-level),'
' Class(s(Set) in s(dart.core), top-level)]',
cm1.typeArguments);
'[Class(s(List) in s(dart.core), top-level),'
' Class(s(Set) in s(dart.core), top-level)]',
cm1.typeArguments,
);
expect(
'[Class(s(List) in s(dart.core), top-level),'
' Class(s(Set) in s(dart.core), top-level)]',
cm2.typeArguments);
'[Class(s(List) in s(dart.core), top-level),'
' Class(s(Set) in s(dart.core), top-level)]',
cm2.typeArguments,
);
expect(
'[Class(s(List) in s(dart.core), top-level),'
' Class(s(Set) in s(dart.core), top-level)]',
cm3.typeArguments);
'[Class(s(List) in s(dart.core), top-level),'
' Class(s(Set) in s(dart.core), top-level)]',
cm3.typeArguments,
);
expect('[Class(s(String) in s(dart.core), top-level)]',
cm1.typeArguments[1].typeArguments);
expect('[Class(s(String) in s(dart.core), top-level)]',
cm2.typeArguments[0].typeArguments);
expect('[Class(s(String) in s(dart.core), top-level)]',
cm3.typeArguments[0].typeArguments);
expect('[Class(s(String) in s(dart.core), top-level)]',
cm3.typeArguments[1].typeArguments);
expect(
'[Class(s(String) in s(dart.core), top-level)]',
cm1.typeArguments[1].typeArguments,
);
expect(
'[Class(s(String) in s(dart.core), top-level)]',
cm2.typeArguments[0].typeArguments,
);
expect(
'[Class(s(String) in s(dart.core), top-level)]',
cm3.typeArguments[0].typeArguments,
);
expect(
'[Class(s(String) in s(dart.core), top-level)]',
cm3.typeArguments[1].typeArguments,
);
var cm4 = reflect(new Bar<Bar<List, Set>, String>()).type;
expect(
'[Class(s(Bar) in s(lib), top-level),'
' Class(s(String) in s(dart.core), top-level)]',
cm4.typeArguments);
'[Class(s(Bar) in s(lib), top-level),'
' Class(s(String) in s(dart.core), top-level)]',
cm4.typeArguments,
);
expect(
'[Class(s(List) in s(dart.core), top-level), '
'Class(s(Set) in s(dart.core), top-level)]',
cm4.typeArguments[0].typeArguments);
'[Class(s(List) in s(dart.core), top-level), '
'Class(s(Set) in s(dart.core), top-level)]',
cm4.typeArguments[0].typeArguments,
);
}