Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » Obtain source code from ASTNode(Having an ASTNode, how can I retrieve the source code "behind" it and print it in a text-box?)
Obtain source code from ASTNode [message #831147] Wed, 28 March 2012 14:32 Go to next message
Francesco Spegni is currently offline Francesco Spegni
Messages: 1
Registered: March 2012
Location: Italy
Junior Member
Hello all,

I'm exploring the PDT SDK in order to exploit the PHP plugin functionality for a plugin I'm writing that should show (portions of) PHP files (specific functions, methods, and so on ...).

The problem I'm having is this: with a class that extends org.eclipse.php.internal.core.ast.visitor.AbstractVisitor, I can find a function with a given name. This returns me an object of type FunctionDeclaration.

Is there any way from a FunctionDeclaration (or FunctionDeclaration.getAST()) to have back the source code that is behind the AST?

Using FunctionDeclaration.toString() I can only obtain an XML-like representation of the tree.

Many thanks in advance, this problem is driving me crazy Smile
Re: Obtain source code from ASTNode [message #831513 is a reply to message #831147] Thu, 29 March 2012 01:37 Go to previous message
Toshihiro Izumi is currently offline Toshihiro Izumi
Messages: 348
Registered: July 2009
Location: Japan
Senior Member
For latecomers, it has been answered here.
Eclipse PDT : obtaining the source code behind an ASTNode - Stack Overflow

And this is my answer for instance.
String source = functionDeclaration.getProgramRoot().getSourceModule().getSource();
int offset = functionDeclaration.getStart();
int length = functionDeclaration.getLength();
String functionSource = source.substring(offset, offset + length);
System.out.println(functionSource);
Previous Topic:xdebug on apache 2.2 with PHP 5.3
Next Topic:Tasks view not showing all tasks
Goto Forum:
  


Current Time: Wed Oct 01 22:25:17 GMT 2014

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

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