Hi,

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 <excepti...@hotmail.com> <excepti...@hotmail.com>
Reply: PDT Developers <pdt-dev@eclipse.org> <pdt-dev@eclipse.org>
Date: 10 August 2016 at 13:42:38
To: pdt-dev <pdt-dev@eclipse.org> <pdt-dev@eclipse.org>
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
org.eclipse.wst.sse.ui.internal.text.StructuredAutoEditStrategy.

>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
pdt-dev@eclipse.org
To change your delivery options, retrieve your password, or unsubscribe
from this list, visit
https://dev.eclipse.org/mailman/listinfo/pdt-dev
_______________________________________________
pdt-dev mailing list
pdt-dev@eclipse.org
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/pdt-dev

Reply via email to