Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » How to get Get JavaScript" type resolution" in script blocks of HTML/JSP files
How to get Get JavaScript" type resolution" in script blocks of HTML/JSP files [message #512667] Fri, 05 February 2010 17:53 Go to next message
Eclipse User
Originally posted by: adataylo.cisco.com

I'm trying to workaround this bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=298751


I'm using the "org.eclipse.wst.sse.ui.editorConfiguration" extension pt.
with a
target of "org.eclipse.wst.html.SCRIPT" to get JavaScript completions into
script blocks of the HTML and JSP editors. However when this approach
is used
I don't have access to any of the "type resolution" information that I
do when
using the
"org.eclipse.wst.jsdt.ui.javaCompletionProposalComputer" extension pt.

Is there any way to get this information? Perhaps in the example below
there is
a better way of getting the IJavaScriptUnit?

More details:

JavaScript:
var x = new MyFancyObject();
x. <-- Ctrl + Space

In the JavaScript editor using the
"org.eclipse.wst.jsdt.ui.javaCompletionProposalComputer" extension I can
do the
following:

JavaContentAssistInvocationContext javaContext =
(JavaContentAssistInvocationContext) context;

IJavaScriptUnit unit = javaContext.getCompilationUnit();
SourceField field = (SourceField)unit.getField("x");
SourceFieldElementInfo info =
(SourceFieldElementInfo)field.getElementInfo();
char[] name = info.getTypeName();
String type = new String(name);

<-- type is now equal to "MyFancyObject" -->


In the HTML editor using the "org.eclipse.wst.sse.ui.editorConfiguration" I
first need to find a way of getting an IJavaScriptUnit:

IDOMModel xmlModel = (IDOMModel) StructuredModelManager.getModelManager()
.getExistingModelForRead(viewer.getDocument());
IDOMDocument xmlDoc = xmlModel.getDocument();

JsTranslationAdapter fTranslationAdapter = (JsTranslationAdapter) xmlDoc
.getAdapterFor(IJsTranslation.class);
IJsTranslation translation = fTranslationAdapter.getJsTranslation(true);
IJavaScriptUnit unit = translation.getCompilationUnit();

SourceField field = (SourceField)unit.getField("x");
SourceFieldElementInfo info =
(SourceFieldElementInfo)field.getElementInfo();
char[] name = info.getTypeName();

<-- name is now equal to null -->
Re: How to get Get JavaScript" type resolution" in script blocks of HTML/JSP files [message #512819 is a reply to message #512667] Sun, 07 February 2010 21:17 Go to previous message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2235
Registered: July 2009
Senior Member
On 2/5/2010 5:53 PM, adam taylor wrote:
> I'm trying to workaround this bug:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=298751
>
>
> I'm using the "org.eclipse.wst.sse.ui.editorConfiguration" extension pt.
> with a
> target of "org.eclipse.wst.html.SCRIPT" to get JavaScript completions into
> script blocks of the HTML and JSP editors. However when this approach is
> used
> I don't have access to any of the "type resolution" information that I
> do when
> using the
> "org.eclipse.wst.jsdt.ui.javaCompletionProposalComputer" extension pt.
>
> Is there any way to get this information? Perhaps in the example below
> there is
> a better way of getting the IJavaScriptUnit?

It's going to require fixing a limitation in the way content assist is
contributed to the HTML editor,
https://bugs.eclipse.org/bugs/show_bug.cgi?id=258999 .

--
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational


---
Nitin Dahyabhai
Eclipse WTP, IBM
Previous Topic:XML Catalog User entries ignored by embedded tomcat
Next Topic:Customize publishing to the server
Goto Forum:
  


Current Time: Fri Jul 25 19:22:44 EDT 2014

Powered by FUDForum. Page generated in 0.02180 seconds