dart-sdk/tests/lib/mirrors/method_mirror_extension_test.dart
Lasse R.H. Nielsen 2360783808 Expire experiments released in earlier stable versions.
Remove messages referring to expired `non-nullable` experiment.
Remove occurrences of --enable-experiment with expired experiments.

TEST=Flags were expired. If existing tests still run, it's a success.

Change-Id: Id66d78eb0a3191ec5e31375faf0effd9ea7b768f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/219789
Auto-Submit: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2021-11-11 08:28:31 +00:00

125 lines
2.7 KiB
Dart

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library lib;
import "dart:mirrors";
import "package:expect/expect.dart";
class C<T> {
static int tracefunc() {
try {
throw "producing a stack trace";
} catch (e, s) {
print(s);
}
return 10;
}
}
extension ext<T> on C<T> {
func() {
try {
throw "producing a stack trace";
} catch (e, s) {
print(s);
}
}
get prop {
try {
throw "producing a stack trace";
} catch (e, s) {
print(s);
}
}
set prop(value) {
try {
throw "producing a stack trace";
} catch (e, s) {
print(s);
}
}
operator +(val) {
try {
throw "producing a stack trace";
} catch (e, s) {
print(s);
}
}
operator -(val) {
try {
throw "producing a stack trace";
} catch (e, s) {
print(s);
}
}
static int sfld = C.tracefunc();
static sfunc() {
try {
throw "producing a stack trace";
} catch (e, s) {
print(s);
}
}
static get sprop {
try {
throw "producing a stack trace";
} catch (e, s) {
print(s);
}
}
static set sprop(value) {
try {
throw "producing a stack trace";
} catch (e, s) {
print(s);
}
}
}
checkExtensionKind(closure, kind, name) {
var closureMirror = reflect(closure) as ClosureMirror;
var methodMirror = closureMirror.function;
Expect.isTrue(methodMirror.simpleName.toString().contains(name));
Expect.equals(kind, methodMirror.isExtensionMember, "isExtension");
}
void testExtension(sym, mirror) {
if (mirror is MethodMirror) {
var methodMirror = mirror as MethodMirror;
if (MirrorSystem.getName(sym).startsWith('ext', 0)) {
Expect.equals(true, methodMirror.isExtensionMember, "isExtension");
Expect.isTrue(methodMirror.simpleName.toString().contains('ext.'));
} else {
Expect.equals(false, methodMirror.isExtensionMember, "isExtension");
}
} else if (mirror is VariableMirror) {
var variableMirror = mirror as VariableMirror;
if (MirrorSystem.getName(sym).startsWith('ext', 0)) {
Expect.equals(true, variableMirror.isExtensionMember, "isExtension");
} else {
Expect.equals(false, variableMirror.isExtensionMember, "isExtension");
}
}
}
main() {
checkExtensionKind(C.tracefunc, false, 'tracefunc');
C c = new C();
checkExtensionKind(c.func, true, 'ext.func');
checkExtensionKind(ext.sfunc, true, 'ext.sfunc');
var libraryMirror = reflectClass(C).owner as LibraryMirror;
libraryMirror.declarations.forEach(testExtension);
}