Alois Napitalai
Alois Napitalai

Reputation: 31

dart function for viewing library functions and classes

Is there a built-in DART function for showing the functions and classes in a specific library like the python dir,doc and help functions?

Upvotes: 2

Views: 93

Answers (1)

JAre
JAre

Reputation: 4756

The closest you can get is listing declarations with mirrors:

library testLib;

import "dart:mirrors";

class Foo {}

bar() => 10;

const baz = "Dart";

void main() {
  MirrorSystem ms = currentMirrorSystem();
  LibraryMirror lm = ms.findLibrary(#testLib);
  Map<Symbol, DeclarationMirror> declarations = lm.declarations;
  print("testLib declarations:");
  declarations.forEach((name, _) {
    print(MirrorSystem.getName(name));
  });

}

output:

testLib declarations:
baz
Foo
main
bar

and you can reflect those declarations and get to their "guts"

Take in mind that mirrors are slow and can bloat dart2js output.

Upvotes: 2

Related Questions