blob: 959a4f5dd475741897e07f410afd643319988c28 [file] [log] [blame]
// Copyright(c) 2015, 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.
import 'dart:mirrors';
/// Returns the names of the public properties and methods on a class.
/// (Also visits its superclasses, recursively.)
Set<String> findMemberNames(String importName, Symbol classSymbol) {
var lib = currentMirrorSystem().libraries[Uri.parse(importName)]!;
var cls = lib.declarations[classSymbol] as ClassMirror?;
var result = <String>{};
void addNames(ClassMirror cls) {
var prefixToRemove = MirrorSystem.getName(cls.simpleName) + '.';
String chooseName(Symbol sym) {
var name = MirrorSystem.getName(sym);
if (name.startsWith(prefixToRemove)) {
return name.substring(prefixToRemove.length);
}
return name;
}
for (var decl in cls.declarations.values) {
if (!decl.isPrivate &&
decl is! VariableMirror &&
decl is! TypeVariableMirror) {
result.add(chooseName(decl.simpleName));
}
}
}
while (cls != null) {
addNames(cls);
cls = cls.superclass;
}
return result;
}