I can not understand how to interpret the documentation on the Dart SDK mirrors library

181 views Asked by At

In declaration of class "DeclarationMirror" I found these documentation about the "owner" property.

For a `parameter`, `local variable` or `local function` the owner is
the immediately enclosing function.

I cannot understand how interpret this information because I cannot find documentation about how to reflect the following declarations through Dart mirrors library.

  1. Local variable
  2. Local function

How should I interpret these terms applied to practical usage of this library?

  1. Notice about the declarations that must be necessarily implemented in future but, for several reasons, currently not implemented.
  2. Information unreliable and can not be perceived as documentation.

I more interested in item #1.

If this is a real documentation but not a unreliable information then where I can find information on which based these documentation?

That is, where is information about described in documentation local variables and local functions mirrored declarations?

I am about how to reflect them from their owners.

I hope that I quite correctly asked question about the official documentation, given its purpose.

If there exist another way to describe this I'll be glad to hear it.

P.S. This question asked on that reason that there is no other available information found in official documentation.

P.S.

Sample of code:

var clazz = reflectClass(MyClass);
var method = clazz.declarations[#myMethod];
// How to reflect mentioned in documentation local variable?
var localVariable = method.declarations[#myLocalVariable];

The sample of code is just an example, but official documentation is more similar to the law. It must clearly be interpreted.

1

There are 1 answers

7
Günter Zöchbauer On

As I see this:

The immediately enclosing function is indeed the owner of the local variables and local functions. But that doesn't include that you can get hold of them by reflection.

I tried to assign a local function to a field of the class and tried then to get hold of the function using reflection. I got the field but don't know how to get the value the field references to (the local func) Maybe this is possible but I couldn't find how. If this would work the owner would probably be the enclosing function.

AFAIR there was a discussion somewhere that it is currently not possible to access local members using reflection but I'm not very sure about this. I also think I saw somewhere that you can get the source of a function as text if that is of any use...