| How to handle a Statement from the user's code? [message #194109] | 
Mon, 24 January 2005 14:30  | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: pimenta.inatel.br 
 
Hi.  
In the plugin I am developping, it is necessary to handle java code.  
That is, code from the final user's files. Nowadays, I have already gotten  
handled several things (methods, instance variables) by reading it  
directly from the user's code. I'm using the AST (Abstract Syntax Tree)  
provided with Eclipse 2.1.2. However, I'm getting some difficuties today  
to do the following:  
 
 
The user wrote into a class:  
........................................................  
  
  
  
1 private void createForm(){  
2  
3    form = new Form("Tilte");  
4    form.append(textItem);  
5  
6 }  
  
  
  
...................................................  
 
 
At runtime, my plugin must know what is the name of the instance variable  
used  
in lines 3 and 4. This I got correctly analyzing the class by some way.  
But, the most diffcult to me, is to discover if the user really wrote the  
line 4. That is, my plugin must know if the user appended something to the  
form. I need know about it because it is necessary to draw a graphical  
representation of the code. Then I did:  
 
 
MethodDeclaration mthdDec = ...//received the declaration of the user's  
createForm method correctly. 
 
Block bloco = mthdDec.getBody(); // Get the block of the method. 
List instructions = bloco.statements(); //Get all statements from the  
block of the method. 
 
Iterator it = instructions.iterator(); 
Statement sttmnt = null; 
ExpressionStatement expSttmnt = null; 
while (it.hasNext()){ // While exists java statement 
  sttmnt = (Statement)it.next();  
  // verify if this statement is ExpressionStatemet 
  if (sttmnt instanceof ExpressionStatement){ 
     expSttmnt = (ExpressionStatement)sttmnt; 
     // in this point I should discover all information I need... :-( 
  } 
} 
 
 
But, unhappily, the code above doesn't show me a way to know about the  
user's line 4 at runtime. What can I do, to handle the user's code and  
handle a determined expression like I'm needing today?? Any help will be  
very helpful.  
 
Thanks  
Rodrigo Pimenta Carvalho.
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.23562 seconds