diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMDebugModelPresentation.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMDebugModelPresentation.java index 76ff3502f..7365c52b2 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMDebugModelPresentation.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMDebugModelPresentation.java @@ -15,11 +15,7 @@ */ package org.teavm.eclipse.debugger.ui; -import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; -import org.eclipse.core.filesystem.EFS; -import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IStorage; import org.eclipse.debug.core.model.ILineBreakpoint; @@ -30,7 +26,6 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorRegistry; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.FileStoreEditorInput; import org.eclipse.ui.part.FileEditorInput; import org.teavm.debugging.CallFrame; import org.teavm.debugging.javascript.JavaScriptCallFrame; @@ -73,13 +68,7 @@ public class TeaVMDebugModelPresentation extends LabelProvider implements IDebug return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource()); } if (element instanceof URL) { - try { - URI uri = new URI(element.toString()); - IFileStore store = EFS.getLocalFileSystem().getStore(uri); - return new FileStoreEditorInput(store); - } catch (URISyntaxException e) { - return null; - } + return new URLEditorInput((URL)element); } if (element instanceof IStorage) { return new StorageEditorInput((IStorage)element); diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/URLEditorInput.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/URLEditorInput.java new file mode 100644 index 000000000..66515c158 --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/URLEditorInput.java @@ -0,0 +1,79 @@ +package org.teavm.eclipse.debugger.ui; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Objects; +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IPersistableElement; +import org.eclipse.ui.IStorageEditorInput; +import org.eclipse.ui.PlatformUI; + +/** + * + * @author Alexey Andreev + */ +public class URLEditorInput extends PlatformObject implements IStorageEditorInput { + private URL url; + + public URLEditorInput(URL url) { + this.url = url; + } + + @Override + public boolean exists() { + try (InputStream input = url.openStream()) { + return true; + } catch (IOException e) { + return false; + } + } + + @Override + public ImageDescriptor getImageDescriptor() { + return PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(url.getFile()); + } + + @Override + public String getName() { + return url.getFile(); + } + + @Override + public IPersistableElement getPersistable() { + return null; + } + + @Override + public String getToolTipText() { + return url.toString(); + } + + @Override + public IStorage getStorage() throws CoreException { + return new URLStorage(url); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((url == null) ? 0 : url.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof URLEditorInput)) { + return false; + } + URLEditorInput other = (URLEditorInput)obj; + return Objects.equals(url, other.url); + } +} diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/URLStorage.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/URLStorage.java new file mode 100644 index 000000000..a8a19a701 --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/URLStorage.java @@ -0,0 +1,46 @@ +package org.teavm.eclipse.debugger.ui; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.PlatformObject; +import org.teavm.eclipse.TeaVMEclipsePlugin; + +/** + * + * @author Alexey Andreev + */ +public class URLStorage extends PlatformObject implements IStorage { + private URL url; + + public URLStorage(URL url) { + this.url = url; + } + + @Override + public InputStream getContents() throws CoreException { + try { + return url.openStream(); + } catch (IOException e) { + throw new CoreException(TeaVMEclipsePlugin.makeError(e)); + } + } + + @Override + public IPath getFullPath() { + return null; + } + + @Override + public String getName() { + return url.getFile(); + } + + @Override + public boolean isReadOnly() { + return true; + } +}