Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » using ASTParesr to get block of Expression
using ASTParesr to get block of Expression [message #1735315] Fri, 17 June 2016 10:46 Go to next message
ahmed albashir is currently offline ahmed albashirFriend
Messages: 7
Registered: May 2016
Junior Member
hi
i this example :
Thread thread = new Thread("New Thread") {
public void run(){
System.out.println("run by: " + getName());
}
};

thread.start();
System.out.println(thread.getName());

i need to get all method in block
new Thread("New Thread") {
public void run(){
System.out.println("run by: " + getName());
}
};

in my example all method in block of new Thread in run();

i can to get new Thread("New Thread") by Expression using the following code :
Expression expression = node.getExpression();
if (expression != null) {
System.out.println("Expr: " + expression.toString());


ITypeBinding typeBinding = expression.resolveTypeBinding();
if (typeBinding != null) {
System.out.println("Type: " + typeBinding.getName());
}
}

how can to get the block of new Thread("New Thread") { }
Re: using ASTParesr to get block of Expression [message #1735321 is a reply to message #1735315] Fri, 17 June 2016 11:15 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
If you already succeeded to navigate to the expression in question, you probably also noticed that this expression has type ClassInstanceCreation. Please see that this class has a method getAnonymousClassDeclaration(). From there, bodyDeclarations() takes you to the list of declarations between '{' and '}'.

I recommend you install ASTView[1] which let's you inspect the AST corresponding to any source you are editing in the Java editor.

[1] https://www.eclipse.org/jdt/ui/astview/index.php
Re: using ASTParesr to get block of Expression [message #1735358 is a reply to message #1735321] Fri, 17 June 2016 15:36 Go to previous messageGo to next message
ahmed albashir is currently offline ahmed albashirFriend
Messages: 7
Registered: May 2016
Junior Member
soo can you give me source code to do that..
Re: using ASTParesr to get block of Expression [message #1735361 is a reply to message #1735358] Fri, 17 June 2016 16:03 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Quote:
soo can you give me source code to do that..

You may continue asking questions, but I don't have the time to implement your tool.
Previous Topic:AST resolve bindings without dependencies
Next Topic:64-bit Java not writing to Console tab
Goto Forum:
  


Current Time: Sat Apr 27 02:51:05 GMT 2024

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

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

Back to the top