Thomas E Enebo wrote:
> In the above code snippet to find Dir class AST we would need two
> references. So I think this task is problematic. If you consider
> that builtin classes do not have an AST at all (they are implemented
> entirely in Java) then there may not even be an AST for a class.
> Also think of the scenario where I re-define initialize in Dir later
> on. Getting a reference to all Dir ClassNodes to find initialize
> would then also require know which order those AST were evaluated.
>
> So the problem to be solved is wanting to go to a super class
> and go to the source where a method is and do some refactoring? Something
> like that? Using the live instances of the classes is probably the
> only way to do this completely accurately. So as an oversimplification
> (and this is semi-incomplete pseudocode):
>
Actually (at least for the moment) I only need to know the Signature
(method name and number of Params) of the Built-in Classes. To solve
this I think the RubyClasses will provide what I need.
I personally don't like to write some Stub Files in Ruby to get the Ast
from them. First point, it's a lot of work and second it's some kind of
Duplicated Code ( <- is evil ;) ).
I tried the code bellow. I'm able to find the method I seek. But I still
have a little Problem with the number of Arguments. The methods provide
an Arity. As I understand it, thats where I should get the number of
Arguments. If a method provides a fixed number of Args the Arity gives
me the value I expect (a positive one). But if the Metod provides
optional Args then the value is negative and I got no idea how I should
interpret that value.
A good example is the Class "Range" (Method "initialize"). It has 2
fixed Args and an optional one. However the Arity contains the value -1.
I understand that the minus means that there is something with options Args.
But I have no idea how to interpret the -1.
Can anyone tell me how I can retreive the minimal requred and the
maximal possible number of params from the Arity?
> 1. cls = IRuby.getClass("X")
> 2. cls = cls.getSuperClass() // More involved with classes
> which include modules.
> 3. method = cls.findMethod("initialize")
> 4. if method.isUndefined() goto 2
> 5. if method (is anything but AliasMethod or Defaultmethod) then no source
> access [native java code impl]
> 6. method.getBodyNode() [Contains location of method impl]
> getBodyNode does not currently exist....
>
> The problem with my solution is it requires the jruby interpreter to
> parse and load these files which could have all sorts of unintended
> conqequences.
>
> My only other thought is you could create a visitor which walks all the
> ASTs you want to potentially refactor and then build your own set of
> references so you can ask a question like getAstNode(ClassName, MethodName)
> or getAstNode(ClassName) and get back what you want. My first example
> shows that this may not give back exactly what you want since you may
> have multiple versions of intialize for a particular class (as an example).
>
> -Tom
>
>
>
Thanks a lot.
Lukas
_______________________________________________
Jruby-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jruby-devel