Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » [jsdt] how to set SourceLocator
[jsdt] how to set SourceLocator [message #673587] Tue, 24 May 2011 08:01
Harald Finster is currently offline Harald FinsterFriend
Messages: 37
Registered: July 2009

what is the correct way to set the SourceLocator of a JavaScript launch configuration, please?
I am currently working on a JavaScript debugger and did not manage to use the built-in
source lookup mechanism of jsdt.

I tried two different approaches:

1) using JavaScriptSourceDirector

I simply set the source locator of my launch as follows:

final JavaScriptSourceDirector loc = new JavaScriptSourceDirector();
loc.initializeDefaults(this.configuration); // configuration is the launch configuration

This results in the following behaviour:

selecting a stack element in the Debug view opens the associated editor window
with a "source not found" message.
If I add the file system folder of the appropriate source code file,
the code is still not found.

I stepped through the AbstractSourceLookupDirector's run() method and found,
that it iterates a list of participants, which has the JavaScriptSourceDirector
as its only member. Unfortunately JavaScriptSourceDirector#findSourceElements
always returns an empty array. (I can't debug into the JavaScriptSourceDirector
because I don't have the source code at hand.)

2) implementing ISourceLocator myself

in this case I simply add my own implementation of ISourceLocator to
the launch as follows:

launch.setSourceLocator(new ISourceLocator() { ... } );

with the following implementation of ISourceLocator#getSourceElement
(source code below simplified):

public Object getSourceElement(final IStackFrame stackFrame) {
final IFile file = JSDebugTarget.this.project.getFile(stackFrame.getName()); // get valid file
final Object artifact = stackFrame;
final String editorId = "org.eclipse.wst.jsdt.ui.CompilationUnitEditor";
final IEditorInput editorInput = new FileEditorInput(file);
return new SourceLookupResult(artifact, null, editorId, editorInput);

I double checked, that 'file' exists.
In order to check the correct "input" of the SourceLookupResult I opened the
editor with the same data within the lookup-method (within a sync exec) and
it worked. So, I am pretty sure, that the values passed to the constructor
of SourceLookupResult are valid.

Still, the editor is not opened on selection of any of the stack elements.

The problem seems to be buried in SourceLookupFacility#lookup
I stepped through this method and found, that it returns a SourceLookupResult
artifact = the strack frame from the SourceLookupResult returned by getSourceElement (above)
editorId = null
editorInput = null
sourceElement = the SourceElement returned by getSourceElement (above)

This SourceLookupResult is then passed to

SourceLookupFacility#openEditor(ISourceLookupResult result, IWorkbenchPage page)

which doeosn't do any work, because editorId and editorInput are both null.
'openEditor' does not seem to take 'sourceElement' into account.

As I am pretty lost at the moment, I kindly ask for your assistance.

Greetings Harald
Previous Topic:Use Sample Java EE Projects
Next Topic:Web service event handler
Goto Forum:

Current Time: Wed Jan 27 17:50:51 GMT 2021

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

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

Back to the top