blob: b636923981473d3939b8bd33f7d72bb786098aac [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.e4.languages.internal.javascript.debug.ui.launching;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.IPersistableSourceLocator;
import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.e4.languages.javascript.debug.model.JSDIStackFrame;
import org.eclipse.e4.languages.javascript.jsdi.ScriptReference;
import org.eclipse.e4.languages.javascript.jsdi.StackFrame;
/**
*
*/
public class JavascriptSourceLocator implements IPersistableSourceLocator {
private Map files = new HashMap();
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
*/
public String getMemento() throws CoreException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(org.eclipse.debug.core.ILaunchConfiguration)
*/
public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(java.lang.String)
*/
public void initializeFromMemento(String memento) throws CoreException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(org.eclipse.debug.core.model.IStackFrame)
*/
public Object getSourceElement(IStackFrame stackFrame) {
JSDIStackFrame jsdiStackFrame = (JSDIStackFrame) stackFrame;
StackFrame underlyingStackFrame = jsdiStackFrame.getUnderlyingStackFrame();
ScriptReference scriptReference = underlyingStackFrame.location().scriptReference();
String source = scriptReference.source();
File file = (File) files.get(scriptReference);
if (file != null)
return file;
try {
file = File.createTempFile("" + scriptReference.hashCode(), "js");
FileWriter writer = new FileWriter(file);
writer.write(source);
writer.close();
files.put(scriptReference, file);
return file;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}