|
Lines 13-23
Link Here
|
| 13 |
import java.io.File; |
13 |
import java.io.File; |
| 14 |
import java.io.FileWriter; |
14 |
import java.io.FileWriter; |
| 15 |
import java.io.IOException; |
15 |
import java.io.IOException; |
|
|
16 |
import java.net.URI; |
| 16 |
|
17 |
|
| 17 |
import org.eclipse.core.resources.IFile; |
18 |
import org.eclipse.core.resources.IFile; |
|
|
19 |
import org.eclipse.core.resources.IWorkspaceRoot; |
| 18 |
import org.eclipse.core.resources.ResourcesPlugin; |
20 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 19 |
import org.eclipse.core.runtime.CoreException; |
21 |
import org.eclipse.core.runtime.CoreException; |
| 20 |
import org.eclipse.core.runtime.IPath; |
|
|
| 21 |
import org.eclipse.core.runtime.Path; |
22 |
import org.eclipse.core.runtime.Path; |
| 22 |
import org.eclipse.core.runtime.URIUtil; |
23 |
import org.eclipse.core.runtime.URIUtil; |
| 23 |
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant; |
24 |
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant; |
|
Lines 55-74
Link Here
|
| 55 |
* @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant#findSourceElements(java.lang.Object) |
56 |
* @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant#findSourceElements(java.lang.Object) |
| 56 |
*/ |
57 |
*/ |
| 57 |
public Object[] findSourceElements(Object object) throws CoreException { |
58 |
public Object[] findSourceElements(Object object) throws CoreException { |
| 58 |
String path = getSourcePath(object); |
59 |
URI sourceURI = getSourceURI(object); |
| 59 |
if (path != null) { |
60 |
if (sourceURI != null) { |
| 60 |
// TODO not sure if we should do a search for the member if the URI path is a miss |
61 |
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); |
| 61 |
IFile file = (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path), false); |
62 |
URI workspaceURI = workspaceRoot.getRawLocationURI(); |
| 62 |
if (file != null) { |
63 |
URI workspaceRelativeURI = workspaceURI.relativize(sourceURI); |
| 63 |
return new IFile[] { file }; |
64 |
if (! workspaceRelativeURI.isAbsolute()) { |
|
|
65 |
IFile file = (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(workspaceRelativeURI.getPath()), false); |
| 66 |
if (file != null) { |
| 67 |
return new IFile[] { file }; |
| 68 |
} |
| 64 |
} |
69 |
} |
|
|
70 |
|
| 65 |
//try to find it using the source tab infos |
71 |
//try to find it using the source tab infos |
| 66 |
Object[] sources = super.findSourceElements(object); |
72 |
Object[] sources = super.findSourceElements(object); |
| 67 |
if(sources != null && sources.length > 0) { |
73 |
if(sources != null && sources.length > 0) { |
| 68 |
return sources; |
74 |
return sources; |
| 69 |
} |
75 |
} |
| 70 |
//else show the temp source |
76 |
//else show the temp source |
| 71 |
return showExternalSource(getSource(object), path); |
77 |
return showExternalSource(getSource(object), sourceURI); |
| 72 |
} |
78 |
} |
| 73 |
return NO_SOURCE; |
79 |
return NO_SOURCE; |
| 74 |
} |
80 |
} |
|
Lines 78-84
Link Here
|
| 78 |
* @param object |
84 |
* @param object |
| 79 |
* @return the raw source or <code>null</code> |
85 |
* @return the raw source or <code>null</code> |
| 80 |
*/ |
86 |
*/ |
| 81 |
String getSource(Object object) { |
87 |
private String getSource(Object object) { |
| 82 |
if(object instanceof IJavaScriptStackFrame) { |
88 |
if(object instanceof IJavaScriptStackFrame) { |
| 83 |
IJavaScriptStackFrame jframe = (IJavaScriptStackFrame) object; |
89 |
IJavaScriptStackFrame jframe = (IJavaScriptStackFrame) object; |
| 84 |
return jframe.getSource(); |
90 |
return jframe.getSource(); |
|
Lines 91-109
Link Here
|
| 91 |
} |
97 |
} |
| 92 |
|
98 |
|
| 93 |
/** |
99 |
/** |
| 94 |
* Returns the path to use to look up source |
100 |
* Returns the uri to use to look up source |
| 95 |
* @param object |
101 |
* @param object |
| 96 |
* @return the path or <code>null</code> |
102 |
* @return the URI or <code>null</code> |
| 97 |
* @since 1.1 |
103 |
* @since 1.1 |
| 98 |
*/ |
104 |
*/ |
| 99 |
String getSourcePath(Object object) { |
105 |
private URI getSourceURI(Object object) { |
| 100 |
if(object instanceof IJavaScriptStackFrame) { |
106 |
if(object instanceof IJavaScriptStackFrame) { |
| 101 |
IJavaScriptStackFrame jframe = (IJavaScriptStackFrame) object; |
107 |
IJavaScriptStackFrame jframe = (IJavaScriptStackFrame) object; |
| 102 |
return jframe.getSourcePath(); |
108 |
return URI.create(jframe.getSourcePath()); |
| 103 |
} |
109 |
} |
| 104 |
if(object instanceof IScript) { |
110 |
if(object instanceof IScript) { |
| 105 |
IScript script = (IScript) object; |
111 |
IScript script = (IScript) object; |
| 106 |
return script.sourceURI().getPath().toString(); |
112 |
return script.sourceURI(); |
| 107 |
} |
113 |
} |
| 108 |
return null; |
114 |
return null; |
| 109 |
} |
115 |
} |
|
Lines 115-128
Link Here
|
| 115 |
* @param path |
121 |
* @param path |
| 116 |
* @return the collection of files to show in external editors |
122 |
* @return the collection of files to show in external editors |
| 117 |
*/ |
123 |
*/ |
| 118 |
Object[] showExternalSource(String source, String path) { |
124 |
private Object[] showExternalSource(String source, URI uri) { |
| 119 |
try { |
125 |
try { |
| 120 |
File tempdir = new File(System.getProperty("java.io.tmpdir")); //$NON-NLS-1$ |
126 |
File tempdir = new File(System.getProperty("java.io.tmpdir")); //$NON-NLS-1$ |
| 121 |
File file = new File(tempdir, formatExternalName(path)); |
127 |
File jsdt_debug = new File(tempdir, "jsdt_debug"); //$NON-NLS-1$ |
|
|
128 |
jsdt_debug.mkdir(); |
| 129 |
jsdt_debug.deleteOnExit(); |
| 130 |
|
| 131 |
String fileName = URIUtil.lastSegment(uri); |
| 132 |
if (fileName.endsWith(".js")) //$NON-NLS-1$ |
| 133 |
fileName = fileName.substring(0, fileName.length()-3); |
| 134 |
fileName +="(" + Integer.toString(uri.toString().hashCode() + source.hashCode()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ |
| 135 |
fileName += ".js"; //$NON-NLS-1$ |
| 136 |
|
| 137 |
File file = new File(jsdt_debug, fileName); |
| 122 |
file.deleteOnExit(); |
138 |
file.deleteOnExit(); |
| 123 |
FileWriter writer = new FileWriter(file); |
139 |
|
| 124 |
writer.write(source); |
140 |
if (!file.exists()) { |
| 125 |
writer.close(); |
141 |
FileWriter writer = new FileWriter(file); |
|
|
142 |
writer.write(source); |
| 143 |
writer.close(); |
| 144 |
} |
| 145 |
|
| 146 |
if (JavaScriptDebugPlugin.getExternalScriptPath(fileName) == null) |
| 147 |
JavaScriptDebugPlugin.addExternalScriptPath(fileName, uri.toString()); |
| 148 |
|
| 126 |
return new Object[] {file}; |
149 |
return new Object[] {file}; |
| 127 |
|
150 |
|
| 128 |
} catch (IOException e) { |
151 |
} catch (IOException e) { |
|
Lines 130-157
Link Here
|
| 130 |
return NO_SOURCE; |
153 |
return NO_SOURCE; |
| 131 |
} |
154 |
} |
| 132 |
} |
155 |
} |
| 133 |
|
|
|
| 134 |
/** |
| 135 |
* Formats the name of the external source to be: |
| 136 |
* <code>[name]_[counter].js</code>.<br><br> |
| 137 |
* If the given name is <code>null</code> the default |
| 138 |
* name of <code>script_[counter].js</code> will be used |
| 139 |
* @param basename |
| 140 |
* @return the formatted external source name |
| 141 |
*/ |
| 142 |
String formatExternalName(String basename) { |
| 143 |
IPath path = null; |
| 144 |
if(basename == null) { |
| 145 |
path = new Path("script"); //$NON-NLS-1$ |
| 146 |
} |
| 147 |
else { |
| 148 |
path = new Path(basename); |
| 149 |
} |
| 150 |
path = path.removeFileExtension(); |
| 151 |
StringBuffer buffer = new StringBuffer(path.toString()); |
| 152 |
buffer.append(".js"); //$NON-NLS-1$ |
| 153 |
return buffer.toString(); |
| 154 |
} |
| 155 |
|
156 |
|
| 156 |
/* |
157 |
/* |
| 157 |
* (non-Javadoc) |
158 |
* (non-Javadoc) |