Help: how to follow Parameters

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Help: how to follow Parameters

Erik Stel
Through a jdt2famix parsed model of an application I'm trying to follow the
usage of a (FAMIX)Parameter. How can this be done?

From a method parameter I can access its enclosing method and from there on
find invocations within that method for example. The problem is that there
does not seem to be a direct way to retrieve the fact that a parameter is
part of a method invocation (both direct or as part of an expression). It
seems I have to parse a piece of the source code (the invocation signature
to be precise). This does not feel okay. Can anyone give some pointers on
how to find parameter usage without resorting to parsing the source code (if
such a solution exists)?

(Googling didn't help so far, or I'm not using the right search parameters
;-)

Example Java source code, for which I want to follow the 'x' parameter:

void startPoint(String x, int y) {

   // Here is first 'simple' parameter usage
   this.doSomething(x, y);

   // Here parameter is part of an expression
   this.that.doAnother("[" + x + "]");

   // Parameter is part of expression again (twice)
   this.doLast(x.substring(0, y) + x.substring(y + 8));
}

Cheers,
Erik




--
Sent from: http://forum.world.st/Moose-f1310756.html
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help: how to follow Parameters

Nicolas Anquetil
very difficult, Famix was not conceived for that usage at the start but
rather to identify dependencies between "higher level entities"
(packages, classes, methods)

You could try to check the source anchors (same line between method
invocation and variable access) but that would ot be 100% correct.

Long time ago, I started a java to FAST parser
https://scm.gforge.inria.fr/svn/verveinej/verveine.extractor.FASTJava
(FAST being a specialization of FAMIX to ASTs) but I don't remember
what its status is ...

nicolas

On Thu, 2018-12-13 at 02:21 -0600, Erik Stel wrote:

> Through a jdt2famix parsed model of an application I'm trying to
> follow the
> usage of a (FAMIX)Parameter. How can this be done?
>
> From a method parameter I can access its enclosing method and from
> there on
> find invocations within that method for example. The problem is that
> there
> does not seem to be a direct way to retrieve the fact that a
> parameter is
> part of a method invocation (both direct or as part of an
> expression). It
> seems I have to parse a piece of the source code (the invocation
> signature
> to be precise). This does not feel okay. Can anyone give some
> pointers on
> how to find parameter usage without resorting to parsing the source
> code (if
> such a solution exists)?
>
> (Googling didn't help so far, or I'm not using the right search
> parameters
> ;-)
>
> Example Java source code, for which I want to follow the 'x'
> parameter:
>
> void startPoint(String x, int y) {
>
>    // Here is first 'simple' parameter usage
>    this.doSomething(x, y);
>
>    // Here parameter is part of an expression
>    this.that.doAnother("[" + x + "]");
>
>    // Parameter is part of expression again (twice)
>    this.doLast(x.substring(0, y) + x.substring(y + 8));
> }
>
> Cheers,
> Erik
>
>
>
>
> --
> Sent from: http://forum.world.st/Moose-f1310756.html
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.list.inf.unibe.ch/listinfo/moose-dev
--
Nicolas Anquetil
RMod team -- Inria Lille

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help: how to follow Parameters

Erik Stel
Hi Nicolas,

Thanks for the quick response. Too bad it is not possible (directly).

The link you provided is behind a login, so I cannot reach it. I might go
for a quick solution, similar to your suggestion. I do not fancy writing a
parser and maintaining it through the (in this case Java) language
evolution.

(Maybe Anquetil is a very common name in France, but as a cyclist I
immediately thought of the famous Jacques Anquetil. Is there a family
relation?)

Kind regards,
Erik (aka ErikOnBike)




--
Sent from: http://forum.world.st/Moose-f1310756.html
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help: how to follow Parameters

Andrei Chis
Hi Erik,

Moose already comes with a full Java parser written in SmaCC. In your case you could use it to get the AST of the method:

JavaParser parse: 'public class Test {

void startPoint(String x, int y) {

   // Here is first ''simple'' parameter usage
   this.doSomething(x, y);

   // Here parameter is part of an expression
   this.that.doAnother("[" + x + "]");

   // Parameter is part of expression again (twice)
   this.doLast(x.substring(0, y) + x.substring(y + 8));
}

}'

Then finding all the places where parameters are used within a method should be doable using a visitor:
ast.png

Cheers,
Andrei

On Fri, Dec 14, 2018 at 11:30 AM Erik Stel <[hidden email]> wrote:
Hi Nicolas,

Thanks for the quick response. Too bad it is not possible (directly).

The link you provided is behind a login, so I cannot reach it. I might go
for a quick solution, similar to your suggestion. I do not fancy writing a
parser and maintaining it through the (in this case Java) language
evolution.

(Maybe Anquetil is a very common name in France, but as a cyclist I
immediately thought of the famous Jacques Anquetil. Is there a family
relation?)

Kind regards,
Erik (aka ErikOnBike)




--
Sent from: http://forum.world.st/Moose-f1310756.html
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help: how to follow Parameters

Erik Stel
Andrei,

Wow?! Because of the external tools like jdt2famix I assumed there wouldn't
be any Java parser present in Moose. I had not even bothered looking for a
Java parser yet. I will check this out (next week).

Thanx!

Cheers,
Erik



--
Sent from: http://forum.world.st/Moose-f1310756.html
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help: how to follow Parameters

Andrei Chis
As Nicolas said in a previous mail, jdt2famix gives you all the high level relations between packages, classes and methods.
The current Java parser that's available in Moose doesn't do name resolution. You only get the AST. So it's complementary to Famix which contains no details about the internals of a method. 

On Fri, Dec 14, 2018 at 11:59 AM Erik Stel <[hidden email]> wrote:
Andrei,

Wow?! Because of the external tools like jdt2famix I assumed there wouldn't
be any Java parser present in Moose. I had not even bothered looking for a
Java parser yet. I will check this out (next week).

Thanx!

Cheers,
Erik



--
Sent from: http://forum.world.st/Moose-f1310756.html
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev