Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How to handle a Statement from the user's code?
How to handle a Statement from the user's code? [message #194109] Mon, 24 January 2005 14:30
Eclipse UserFriend
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.
Previous Topic:How to detect the close of a JDT Editor?
Next Topic:A strange problem on JDialog pop up
Goto Forum:
  


Current Time: Mon Nov 03 12:52:19 EST 2025

Powered by FUDForum. Page generated in 0.04152 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top