[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [pdt-dev] Access PHP AST from within WTP/WST


sorry for delayed answer.

You shouldnât work on AST in this case. It might be not synced with current edit. For autoedit you schould work with SSE IDocument DOM.

See how work PHP autoedit strategies, for ex. org.eclipse.php.internal.ui.autoEdit.CloseTagAutoEditStrategyPHP.

Anyway, if you still need AST, you should know that autoedit strategies work in UI context, so you can âjustâ ask workbench for current editor (see getActiveTextEditor in mentioned class). PHPStructuredTextEditor have method to return ISourceModule. When you have source module you are able to  ask for AST.

PDT have two AST models:
1. One based on DLTK basic elements (very similar to JDT Compiler model). Itâs used for validation, type inference and code assist.
2. Internal PDT DOM AST, itâs more heavy, and available for current editor only (see SharedASTProvider). Itâs used for code manipulating, highlighting and formatting.
Dawid PakuÅa

From:ÂEenhuis <exceptione@xxxxxxxxxxx>
Reply:ÂPDT Developers <pdt-dev@xxxxxxxxxxx>
Date:Â10 August 2016 at 13:42:38
To:Âpdt-dev <pdt-dev@xxxxxxxxxxx>
Subject:Â [pdt-dev] Access PHP AST from within WTP/WST

I managed to intercept and alter the edits the user makes to the pdt editor via

From there I have acces to:

Â- org.eclipse.jface.text.IDocument
Â- org.eclipse.wst.sse.core.internal.provisional.IStructuredModel
Â- org.eclipse.jface.text.DocumentCommand

Thats al nice and well, but to make intelligent changes I need access to the document's
ÂAST which is constructed by PDT. As far as I understand the AST representation
of the PHP code is modelled with DLTK.

My question: how can I get acces to the AST from within StructuredAutoEditStrategy?
The IDocument is fairly low evel. I can retrieve the current editor as an ITextEditor.

(For question context, see http://dev.eclipse.org/mhonarc/lists/pdt-dev/msg03137.html)

pdt-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit