Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'd like to create a java code parser to statically get the objects used as method parameters in a test suite.

Do you have any suggestion on how can I do that?

share|improve this question
2  
Define 'statically get'. State the purpose. Not all parameters are objects. Your question remains unclear. –  EJP May 26 '11 at 8:26
    
The purpose is to get the object instances that the test suite designer choose to provide to the class under test. –  mariosangiorgio May 26 '11 at 8:32
    
That's not a purpose - why do you want these objects, what do you intend to do with them? There's probably a better way to achieve your goal. Also, you mention a parser (which inspects the text of a source file, and generally builds an AST) getting objects (which are build when bytecode evxecutes at runtime) - either you don't mean objects, or you don't mean a parser, since the two concepts are broadly incompatible. –  Andrzej Doyle May 26 '11 at 8:41
    
My final goal is to produce a tool to enhance the test suite, so what I'd like to have is the program slice that generates the instances of the class that are provided to the class under test. –  mariosangiorgio May 26 '11 at 8:50
    
'Enhance the test suite' how? Your question remains unclear. You're trying to test the test suite? Where does this stop? –  EJP May 26 '11 at 10:23

1 Answer 1

It sounds like you want to trace all the arguments passed to a method.

The simplest way is to add code to the method to record this.

If you cannot change the code you can use an Aspect library like AspectJ

share|improve this answer
    
Actually I don't think it is possible to do that dynamically since not all the objects are serializable. What I'd like to get is also a program slice that tells me how to build instances of non serializable objects. –  mariosangiorgio May 26 '11 at 8:37
    
I don't see how whether an object is Serializable make any difference. If you want to serialise objects with out Serializable you can use a custom serialisation like XStream. –  Peter Lawrey May 26 '11 at 8:43
    
Is XStream really able to manage every kind of object? For example, how does it deal with I/O streams that may be passed as parameters to the class? –  mariosangiorgio May 26 '11 at 8:51
    
No, for that you need to dump the information about the object, but you can't reconstruct the original for I/O, Thread etc. –  Peter Lawrey May 26 '11 at 8:53
    
That's the reason why I'd like to have a program slice that tells me how to build the object –  mariosangiorgio May 26 '11 at 9:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.