Getting dependency information about classes programatically

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting dependency information about classes programatically

Jordo Odroj
Hi Haxe,

Does anyone know of a way for me (either at build time, run time,
compile time - I really don't care how) to provide a class name, and
have a list of all of the packages, classes and enums that the class
depends on?
My use case is, I'd like to provide metadata information at each class
that describes file system dependencies.
So given a top level class, I can traverse the tree of dependencies in
order to discover the entire set of file system files that will be
required in order to use that top level classes.

I was thinking something like:
//MyClass.hx

import yourclass.YourClass;        // <--- I use your class
@metadata("requires:/tmp/file/someFile.txt")
class MyClass {
...
}

//YourClass.hx
@metadata("requires:/tmp/file/SomeOtherFile.txt")
class YourClass {

}

Then I can run a script to generate the following conceptual mapping:
"YourClass" => "/tmp/file/SomeOtherFile.txt"
"MyClass" => "/tmp/fil/someFile.txt", "/tmp/file/SomeOtherFile.txt"


Jordo

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dependency information about classes programatically

Dion Whitehead Amago
This will get you started:

http://haxe.org/doc/advanced/rtti

Jordo Odroj wrote:

> Hi Haxe,
>
> Does anyone know of a way for me (either at build time, run time,
> compile time - I really don't care how) to provide a class name, and
> have a list of all of the packages, classes and enums that the class
> depends on?
> My use case is, I'd like to provide metadata information at each class
> that describes file system dependencies.
> So given a top level class, I can traverse the tree of dependencies in
> order to discover the entire set of file system files that will be
> required in order to use that top level classes.
>
> I was thinking something like:
> //MyClass.hx
>
> import yourclass.YourClass;        // <--- I use your class
> @metadata("requires:/tmp/file/someFile.txt")
> class MyClass {
> ...
> }
>
> //YourClass.hx
> @metadata("requires:/tmp/file/SomeOtherFile.txt")
> class YourClass {
>
> }
>
> Then I can run a script to generate the following conceptual mapping:
> "YourClass" => "/tmp/file/SomeOtherFile.txt"
> "MyClass" => "/tmp/fil/someFile.txt", "/tmp/file/SomeOtherFile.txt"
>
>
> Jordo
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dependency information about classes programatically

Cauê W.
you can use macros to do it:

you just need to call a macro somewhere that will call 

Context.onGenerate(function(allTypes)
{
...
});


onGenerate will register a callback that will get called when all types are generated. Then you can access each types' metadata. You won't be able to generate any new class by then, but you can still store all compiled classes' metadatas inside a "master class" metadata, or something like that

Cheers!
Cauê

2011/3/14 Dion Amago <[hidden email]>
This will get you started:

http://haxe.org/doc/advanced/rtti

Jordo Odroj wrote:
> Hi Haxe,
>
> Does anyone know of a way for me (either at build time, run time,
> compile time - I really don't care how) to provide a class name, and
> have a list of all of the packages, classes and enums that the class
> depends on?
> My use case is, I'd like to provide metadata information at each class
> that describes file system dependencies.
> So given a top level class, I can traverse the tree of dependencies in
> order to discover the entire set of file system files that will be
> required in order to use that top level classes.
>
> I was thinking something like:
> //MyClass.hx
>
> import yourclass.YourClass;        // <--- I use your class
> @metadata("requires:/tmp/file/someFile.txt")
> class MyClass {
> ...
> }
>
> //YourClass.hx
> @metadata("requires:/tmp/file/SomeOtherFile.txt")
> class YourClass {
>
> }
>
> Then I can run a script to generate the following conceptual mapping:
> "YourClass" => "/tmp/file/SomeOtherFile.txt"
> "MyClass" => "/tmp/fil/someFile.txt", "/tmp/file/SomeOtherFile.txt"
>
>
> Jordo
>

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dependency information about classes programatically

Jordo Odroj
This seems promising, but in the onGenerate handler, how can I query
for any given type's entire set of dependencies?
Given at least the immediate dependencies, I could construct the
entire tree. Is either of these things possible with that handler?

Jordo

On Sun, Mar 13, 2011 at 8:27 PM, Cauê Waneck <[hidden email]> wrote:

> you can use macros to do it:
> you just need to call a macro somewhere that will call
> Context.onGenerate(function(allTypes)
> {
> ...
> });
>
> onGenerate will register a callback that will get called when all types are
> generated. Then you can access each types' metadata. You won't be able to
> generate any new class by then, but you can still store all compiled
> classes' metadatas inside a "master class" metadata, or something like that
> Cheers!
> Cauê
>
> 2011/3/14 Dion Amago <[hidden email]>
>>
>> This will get you started:
>>
>> http://haxe.org/doc/advanced/rtti
>>
>> Jordo Odroj wrote:
>> > Hi Haxe,
>> >
>> > Does anyone know of a way for me (either at build time, run time,
>> > compile time - I really don't care how) to provide a class name, and
>> > have a list of all of the packages, classes and enums that the class
>> > depends on?
>> > My use case is, I'd like to provide metadata information at each class
>> > that describes file system dependencies.
>> > So given a top level class, I can traverse the tree of dependencies in
>> > order to discover the entire set of file system files that will be
>> > required in order to use that top level classes.
>> >
>> > I was thinking something like:
>> > //MyClass.hx
>> >
>> > import yourclass.YourClass;        // <--- I use your class
>> > @metadata("requires:/tmp/file/someFile.txt")
>> > class MyClass {
>> > ...
>> > }
>> >
>> > //YourClass.hx
>> > @metadata("requires:/tmp/file/SomeOtherFile.txt")
>> > class YourClass {
>> >
>> > }
>> >
>> > Then I can run a script to generate the following conceptual mapping:
>> > "YourClass" => "/tmp/file/SomeOtherFile.txt"
>> > "MyClass" => "/tmp/fil/someFile.txt", "/tmp/file/SomeOtherFile.txt"
>> >
>> >
>> > Jordo
>> >
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dependency information about classes programatically

Jordo Odroj
So this was a good path to go down. I was able to get
superclasses/interfaces programatically, but I can't figure out, for a
given ClassType c, how do I get the imports of the package it resides
in, and information about the imports/usings?

Jordo

On Sun, Mar 13, 2011 at 10:36 PM, Jordo Odroj <[hidden email]> wrote:

> This seems promising, but in the onGenerate handler, how can I query
> for any given type's entire set of dependencies?
> Given at least the immediate dependencies, I could construct the
> entire tree. Is either of these things possible with that handler?
>
> Jordo
>
> On Sun, Mar 13, 2011 at 8:27 PM, Cauê Waneck <[hidden email]> wrote:
>> you can use macros to do it:
>> you just need to call a macro somewhere that will call
>> Context.onGenerate(function(allTypes)
>> {
>> ...
>> });
>>
>> onGenerate will register a callback that will get called when all types are
>> generated. Then you can access each types' metadata. You won't be able to
>> generate any new class by then, but you can still store all compiled
>> classes' metadatas inside a "master class" metadata, or something like that
>> Cheers!
>> Cauê
>>
>> 2011/3/14 Dion Amago <[hidden email]>
>>>
>>> This will get you started:
>>>
>>> http://haxe.org/doc/advanced/rtti
>>>
>>> Jordo Odroj wrote:
>>> > Hi Haxe,
>>> >
>>> > Does anyone know of a way for me (either at build time, run time,
>>> > compile time - I really don't care how) to provide a class name, and
>>> > have a list of all of the packages, classes and enums that the class
>>> > depends on?
>>> > My use case is, I'd like to provide metadata information at each class
>>> > that describes file system dependencies.
>>> > So given a top level class, I can traverse the tree of dependencies in
>>> > order to discover the entire set of file system files that will be
>>> > required in order to use that top level classes.
>>> >
>>> > I was thinking something like:
>>> > //MyClass.hx
>>> >
>>> > import yourclass.YourClass;        // <--- I use your class
>>> > @metadata("requires:/tmp/file/someFile.txt")
>>> > class MyClass {
>>> > ...
>>> > }
>>> >
>>> > //YourClass.hx
>>> > @metadata("requires:/tmp/file/SomeOtherFile.txt")
>>> > class YourClass {
>>> >
>>> > }
>>> >
>>> > Then I can run a script to generate the following conceptual mapping:
>>> > "YourClass" => "/tmp/file/SomeOtherFile.txt"
>>> > "MyClass" => "/tmp/fil/someFile.txt", "/tmp/file/SomeOtherFile.txt"
>>> >
>>> >
>>> > Jordo
>>> >
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dependency information about classes programatically

Cauê W.
I don't think it is possible.
What you must be able to do is to go through each member var/ function and look for the variables' types and function types.

2011/3/15 Jordo Odroj <[hidden email]>
So this was a good path to go down. I was able to get
superclasses/interfaces programatically, but I can't figure out, for a
given ClassType c, how do I get the imports of the package it resides
in, and information about the imports/usings?

Jordo

On Sun, Mar 13, 2011 at 10:36 PM, Jordo Odroj <[hidden email]> wrote:
> This seems promising, but in the onGenerate handler, how can I query
> for any given type's entire set of dependencies?
> Given at least the immediate dependencies, I could construct the
> entire tree. Is either of these things possible with that handler?
>
> Jordo
>
> On Sun, Mar 13, 2011 at 8:27 PM, Cauê Waneck <[hidden email]> wrote:
>> you can use macros to do it:
>> you just need to call a macro somewhere that will call
>> Context.onGenerate(function(allTypes)
>> {
>> ...
>> });
>>
>> onGenerate will register a callback that will get called when all types are
>> generated. Then you can access each types' metadata. You won't be able to
>> generate any new class by then, but you can still store all compiled
>> classes' metadatas inside a "master class" metadata, or something like that
>> Cheers!
>> Cauê
>>
>> 2011/3/14 Dion Amago <[hidden email]>
>>>
>>> This will get you started:
>>>
>>> http://haxe.org/doc/advanced/rtti
>>>
>>> Jordo Odroj wrote:
>>> > Hi Haxe,
>>> >
>>> > Does anyone know of a way for me (either at build time, run time,
>>> > compile time - I really don't care how) to provide a class name, and
>>> > have a list of all of the packages, classes and enums that the class
>>> > depends on?
>>> > My use case is, I'd like to provide metadata information at each class
>>> > that describes file system dependencies.
>>> > So given a top level class, I can traverse the tree of dependencies in
>>> > order to discover the entire set of file system files that will be
>>> > required in order to use that top level classes.
>>> >
>>> > I was thinking something like:
>>> > //MyClass.hx
>>> >
>>> > import yourclass.YourClass;        // <--- I use your class
>>> > @metadata("requires:/tmp/file/someFile.txt")
>>> > class MyClass {
>>> > ...
>>> > }
>>> >
>>> > //YourClass.hx
>>> > @metadata("requires:/tmp/file/SomeOtherFile.txt")
>>> > class YourClass {
>>> >
>>> > }
>>> >
>>> > Then I can run a script to generate the following conceptual mapping:
>>> > "YourClass" => "/tmp/file/SomeOtherFile.txt"
>>> > "MyClass" => "/tmp/fil/someFile.txt", "/tmp/file/SomeOtherFile.txt"
>>> >
>>> >
>>> > Jordo
>>> >
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dependency information about classes programatically

Cauê W.
you could also see if you can open the type's path (not sure how to look it up, though) and do a simple regex to look for imports.

2011/3/15 Cauê Waneck <[hidden email]>
I don't think it is possible.
What you must be able to do is to go through each member var/ function and look for the variables' types and function types.


2011/3/15 Jordo Odroj <[hidden email]>
So this was a good path to go down. I was able to get
superclasses/interfaces programatically, but I can't figure out, for a
given ClassType c, how do I get the imports of the package it resides
in, and information about the imports/usings?

Jordo

On Sun, Mar 13, 2011 at 10:36 PM, Jordo Odroj <[hidden email]> wrote:
> This seems promising, but in the onGenerate handler, how can I query
> for any given type's entire set of dependencies?
> Given at least the immediate dependencies, I could construct the
> entire tree. Is either of these things possible with that handler?
>
> Jordo
>
> On Sun, Mar 13, 2011 at 8:27 PM, Cauê Waneck <[hidden email]> wrote:
>> you can use macros to do it:
>> you just need to call a macro somewhere that will call
>> Context.onGenerate(function(allTypes)
>> {
>> ...
>> });
>>
>> onGenerate will register a callback that will get called when all types are
>> generated. Then you can access each types' metadata. You won't be able to
>> generate any new class by then, but you can still store all compiled
>> classes' metadatas inside a "master class" metadata, or something like that
>> Cheers!
>> Cauê
>>
>> 2011/3/14 Dion Amago <[hidden email]>
>>>
>>> This will get you started:
>>>
>>> http://haxe.org/doc/advanced/rtti
>>>
>>> Jordo Odroj wrote:
>>> > Hi Haxe,
>>> >
>>> > Does anyone know of a way for me (either at build time, run time,
>>> > compile time - I really don't care how) to provide a class name, and
>>> > have a list of all of the packages, classes and enums that the class
>>> > depends on?
>>> > My use case is, I'd like to provide metadata information at each class
>>> > that describes file system dependencies.
>>> > So given a top level class, I can traverse the tree of dependencies in
>>> > order to discover the entire set of file system files that will be
>>> > required in order to use that top level classes.
>>> >
>>> > I was thinking something like:
>>> > //MyClass.hx
>>> >
>>> > import yourclass.YourClass;        // <--- I use your class
>>> > @metadata("requires:/tmp/file/someFile.txt")
>>> > class MyClass {
>>> > ...
>>> > }
>>> >
>>> > //YourClass.hx
>>> > @metadata("requires:/tmp/file/SomeOtherFile.txt")
>>> > class YourClass {
>>> >
>>> > }
>>> >
>>> > Then I can run a script to generate the following conceptual mapping:
>>> > "YourClass" => "/tmp/file/SomeOtherFile.txt"
>>> > "MyClass" => "/tmp/fil/someFile.txt", "/tmp/file/SomeOtherFile.txt"
>>> >
>>> >
>>> > Jordo
>>> >
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>

--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Getting dependency information about classes programatically

Jordo Odroj
I can construct the type path.
If I assume that the files are placed according to their type path,
then I can read the files in and look for imports, but it seems a
little more fragile. The only problem is, I also need other classes
inside the same package that aren't imports, and also references to
fully qualified class paths that occur without imports.
I suppose, for the last point, I could grep each file for any
references to what I have previously identified as being fully
qualified class paths, as a final and last step.
It just seems like the haxe compiler would already have this
information somewhere, and we just need to figure out a roundabout way
of getting it. Dead code elimination surely must have this
information?

On Tue, Mar 15, 2011 at 1:38 PM, Cauê Waneck <[hidden email]> wrote:

> you could also see if you can open the type's path (not sure how to look it
> up, though) and do a simple regex to look for imports.
>
> 2011/3/15 Cauê Waneck <[hidden email]>
>>
>> I don't think it is possible.
>> What you must be able to do is to go through each member var/ function and
>> look for the variables' types and function types.
>>
>> 2011/3/15 Jordo Odroj <[hidden email]>
>>>
>>> So this was a good path to go down. I was able to get
>>> superclasses/interfaces programatically, but I can't figure out, for a
>>> given ClassType c, how do I get the imports of the package it resides
>>> in, and information about the imports/usings?
>>>
>>> Jordo
>>>
>>> On Sun, Mar 13, 2011 at 10:36 PM, Jordo Odroj <[hidden email]> wrote:
>>> > This seems promising, but in the onGenerate handler, how can I query
>>> > for any given type's entire set of dependencies?
>>> > Given at least the immediate dependencies, I could construct the
>>> > entire tree. Is either of these things possible with that handler?
>>> >
>>> > Jordo
>>> >
>>> > On Sun, Mar 13, 2011 at 8:27 PM, Cauê Waneck <[hidden email]> wrote:
>>> >> you can use macros to do it:
>>> >> you just need to call a macro somewhere that will call
>>> >> Context.onGenerate(function(allTypes)
>>> >> {
>>> >> ...
>>> >> });
>>> >>
>>> >> onGenerate will register a callback that will get called when all
>>> >> types are
>>> >> generated. Then you can access each types' metadata. You won't be able
>>> >> to
>>> >> generate any new class by then, but you can still store all compiled
>>> >> classes' metadatas inside a "master class" metadata, or something like
>>> >> that
>>> >> Cheers!
>>> >> Cauê
>>> >>
>>> >> 2011/3/14 Dion Amago <[hidden email]>
>>> >>>
>>> >>> This will get you started:
>>> >>>
>>> >>> http://haxe.org/doc/advanced/rtti
>>> >>>
>>> >>> Jordo Odroj wrote:
>>> >>> > Hi Haxe,
>>> >>> >
>>> >>> > Does anyone know of a way for me (either at build time, run time,
>>> >>> > compile time - I really don't care how) to provide a class name,
>>> >>> > and
>>> >>> > have a list of all of the packages, classes and enums that the
>>> >>> > class
>>> >>> > depends on?
>>> >>> > My use case is, I'd like to provide metadata information at each
>>> >>> > class
>>> >>> > that describes file system dependencies.
>>> >>> > So given a top level class, I can traverse the tree of dependencies
>>> >>> > in
>>> >>> > order to discover the entire set of file system files that will be
>>> >>> > required in order to use that top level classes.
>>> >>> >
>>> >>> > I was thinking something like:
>>> >>> > //MyClass.hx
>>> >>> >
>>> >>> > import yourclass.YourClass;        // <--- I use your class
>>> >>> > @metadata("requires:/tmp/file/someFile.txt")
>>> >>> > class MyClass {
>>> >>> > ...
>>> >>> > }
>>> >>> >
>>> >>> > //YourClass.hx
>>> >>> > @metadata("requires:/tmp/file/SomeOtherFile.txt")
>>> >>> > class YourClass {
>>> >>> >
>>> >>> > }
>>> >>> >
>>> >>> > Then I can run a script to generate the following conceptual
>>> >>> > mapping:
>>> >>> > "YourClass" => "/tmp/file/SomeOtherFile.txt"
>>> >>> > "MyClass" => "/tmp/fil/someFile.txt", "/tmp/file/SomeOtherFile.txt"
>>> >>> >
>>> >>> >
>>> >>> > Jordo
>>> >>> >
>>> >>>
>>> >>> --
>>> >>> haXe - an open source web programming language
>>> >>> http://haxe.org
>>> >>
>>> >>
>>> >> --
>>> >> haXe - an open source web programming language
>>> >> http://haxe.org
>>> >>
>>> >
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org