Skip to main content



      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 06:46 Go to next message
Eclipse UserFriend
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 07:15 Go to previous messageGo to next message
Eclipse UserFriend
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 11:36 Go to previous messageGo to next message
Eclipse UserFriend
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 12:03 Go to previous message
Eclipse UserFriend
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: Thu May 15 10:09:31 EDT 2025

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

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

Back to the top