Bug 522137: throw IOException instead of Exception when getting code

  when fetching script code, generic errors should be avoided. Instead
  always throw IOExceptions.

Change-Id: I58609e37fc5365de267b937a1522608babc82584
diff --git a/plugins/org.eclipse.ease/src/org/eclipse/ease/ICompletionContext.java b/plugins/org.eclipse.ease/src/org/eclipse/ease/ICompletionContext.java
index 28333bb..a549b61 100644
--- a/plugins/org.eclipse.ease/src/org/eclipse/ease/ICompletionContext.java
+++ b/plugins/org.eclipse.ease/src/org/eclipse/ease/ICompletionContext.java
@@ -18,7 +18,7 @@
 import org.eclipse.ease.modules.ModuleDefinition;
 import org.eclipse.ease.service.ScriptType;
 
-public interface ICompletionContext {
+public interface ICompletionContext extends IScriptEngineProvider {
 
 	List<Object> getTokens();
 
@@ -29,13 +29,6 @@
 	int getReplaceLength();
 
 	/**
-	 * Get active script engine.
-	 *
-	 * @return script engine or <code>null</code>
-	 */
-	IScriptEngine getScriptEngine();
-
-	/**
 	 * Get all loaded modules.
 	 *
 	 * @return loaded modules
@@ -56,4 +49,4 @@
 	ScriptType getScriptType();
 
 	Object getResource();
-}
\ No newline at end of file
+}
diff --git a/plugins/org.eclipse.ease/src/org/eclipse/ease/IScriptable.java b/plugins/org.eclipse.ease/src/org/eclipse/ease/IScriptable.java
index 75ae449..05b0b8c 100644
--- a/plugins/org.eclipse.ease/src/org/eclipse/ease/IScriptable.java
+++ b/plugins/org.eclipse.ease/src/org/eclipse/ease/IScriptable.java
@@ -12,6 +12,7 @@
  *******************************************************************************/
 package org.eclipse.ease;
 
+import java.io.IOException;
 import java.io.InputStream;
 
 /**
@@ -23,8 +24,8 @@
 	 * Get input stream containing source code.
 	 *
 	 * @return source code as {@link InputStream}
-	 * @throws Exception
+	 * @throws IOException
 	 *             when inputStream cannot be created
 	 */
-	InputStream getSourceCode() throws Exception;
+	InputStream getSourceCode() throws IOException;
 }
diff --git a/plugins/org.eclipse.ease/src/org/eclipse/ease/Script.java b/plugins/org.eclipse.ease/src/org/eclipse/ease/Script.java
index 277e806..42fc4bf 100644
--- a/plugins/org.eclipse.ease/src/org/eclipse/ease/Script.java
+++ b/plugins/org.eclipse.ease/src/org/eclipse/ease/Script.java
@@ -89,10 +89,10 @@
 	 * return different streams with the same text content.
 	 *
 	 * @return scriptable data
-	 * @throws Exception
+	 * @throws IOException
 	 *             when stream cannot be established
 	 */
-	public InputStream getCodeStream() throws Exception {
+	public InputStream getCodeStream() throws IOException {
 		return new ByteArrayInputStream(getCode().getBytes());
 	}
 
@@ -100,10 +100,10 @@
 	 * Get the scriptable data as {@link String}.
 	 *
 	 * @return scriptable data
-	 * @throws Exception
+	 * @throws IOException
 	 *             when code cannot be read from source
 	 */
-	public String getCode() throws Exception {
+	public String getCode() throws IOException {
 		if (fCodeBuffer != null)
 			return fCodeBuffer;
 
diff --git a/plugins/org.eclipse.ease/src/org/eclipse/ease/adapters/ScriptableAdapter.java b/plugins/org.eclipse.ease/src/org/eclipse/ease/adapters/ScriptableAdapter.java
index 21a3771..c22a1da 100644
--- a/plugins/org.eclipse.ease/src/org/eclipse/ease/adapters/ScriptableAdapter.java
+++ b/plugins/org.eclipse.ease/src/org/eclipse/ease/adapters/ScriptableAdapter.java
@@ -14,10 +14,12 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.net.URI;
 import java.net.URL;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IAdapterFactory;
 import org.eclipse.ease.IScriptable;
 
@@ -31,7 +33,13 @@
 	public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
 		if (adapterType.equals(IScriptable.class)) {
 			if (adaptableObject instanceof IFile)
-				return (T) (IScriptable) () -> ((IFile) adaptableObject).getContents();
+				return (T) (IScriptable) () -> {
+					try {
+						return ((IFile) adaptableObject).getContents();
+					} catch (final CoreException e) {
+						throw new IOException(e);
+					}
+				};
 
 			if (adaptableObject instanceof File)
 				return (T) (IScriptable) () -> new FileInputStream((File) adaptableObject);
diff --git a/tests/org.eclipse.ease.test/src/org/eclipse/ease/AbstractScriptEngineTest.java b/tests/org.eclipse.ease.test/src/org/eclipse/ease/AbstractScriptEngineTest.java
index ec18145..d1033f1 100644
--- a/tests/org.eclipse.ease.test/src/org/eclipse/ease/AbstractScriptEngineTest.java
+++ b/tests/org.eclipse.ease.test/src/org/eclipse/ease/AbstractScriptEngineTest.java
@@ -412,7 +412,7 @@
 

 		final Script script = new Script(file) {

 			@Override

-			public String getCode() throws Exception {

+			public String getCode() {

 				return "code";

 			}

 		};

diff --git a/tests/org.eclipse.ease.test/src/org/eclipse/ease/ScriptTest.java b/tests/org.eclipse.ease.test/src/org/eclipse/ease/ScriptTest.java
index 3ae7956..44beed8 100644
--- a/tests/org.eclipse.ease.test/src/org/eclipse/ease/ScriptTest.java
+++ b/tests/org.eclipse.ease.test/src/org/eclipse/ease/ScriptTest.java
@@ -53,49 +53,49 @@
 	}
 
 	@Test
-	public void codeFromString() throws Exception {
+	public void codeFromString() throws IOException {
 		final Script script = new Script(SAMPLE_CODE);
 		assertEquals(SAMPLE_CODE, script.getCode());
 	}
 
 	@Test
-	public void codeFromInputStream() throws Exception {
+	public void codeFromInputStream() throws IOException {
 		final Script script = new Script(new ByteArrayInputStream(SAMPLE_CODE.getBytes()));
 		assertEquals(SAMPLE_CODE, script.getCode());
 	}
 
 	@Test
-	public void codeFromReader() throws Exception {
+	public void codeFromReader() throws IOException {
 		final Script script = new Script(new StringReader(SAMPLE_CODE));
 		assertEquals(SAMPLE_CODE, script.getCode());
 	}
 
 	@Test
-	public void codeFromScriptable() throws Exception {
+	public void codeFromScriptable() throws IOException {
 		final Script script = new Script((IScriptable) () -> new ByteArrayInputStream(SAMPLE_CODE.getBytes()));
 		assertEquals(SAMPLE_CODE, script.getCode());
 	}
 
 	@Test
-	public void codeFromWorkspaceFile() throws Exception {
+	public void codeFromWorkspaceFile() throws IOException {
 		final Script script = new Script(fFile);
 		assertEquals(SAMPLE_CODE, script.getCode());
 	}
 
 	@Test
-	public void codeFromFilesystemFile() throws Exception {
+	public void codeFromFilesystemFile() throws IOException {
 		final Script script = new Script(fFile.getLocation().toFile());
 		assertEquals(SAMPLE_CODE, script.getCode());
 	}
 
 	@Test
-	public void codeFromStringBuilder() throws Exception {
+	public void codeFromStringBuilder() throws IOException {
 		final Script script = new Script(new StringBuilder(SAMPLE_CODE));
 		assertEquals(SAMPLE_CODE, script.getCode());
 	}
 
 	@Test
-	public void getCodeStream() throws IOException, Exception {
+	public void getCodeStream() throws IOException {
 		final Script script = new Script(new ByteArrayInputStream(SAMPLE_CODE.getBytes()));
 		assertEquals(SAMPLE_CODE, ResourceTools.toString(script.getCodeStream()));