Bug 507882: Recorded JS scripts do not store keywords in comments

  seems we removed comment creation during some refactoring

Change-Id: If025e82e99238961821b7caeeab69183638eb9ad
diff --git a/plugins/org.eclipse.ease.lang.javascript/src/org/eclipse/ease/lang/javascript/JavaScriptCodeFactory.java b/plugins/org.eclipse.ease.lang.javascript/src/org/eclipse/ease/lang/javascript/JavaScriptCodeFactory.java
index 57c0ee6..f778ef9 100644
--- a/plugins/org.eclipse.ease.lang.javascript/src/org/eclipse/ease/lang/javascript/JavaScriptCodeFactory.java
+++ b/plugins/org.eclipse.ease.lang.javascript/src/org/eclipse/ease/lang/javascript/JavaScriptCodeFactory.java
@@ -15,17 +15,17 @@
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 import org.eclipse.ease.AbstractCodeFactory;
 import org.eclipse.ease.Logger;
 import org.eclipse.ease.modules.IEnvironment;
 import org.eclipse.ease.modules.IScriptFunctionModifier;
 import org.eclipse.ease.modules.ModuleHelper;
+import org.eclipse.ease.tools.StringTools;
 
 public class JavaScriptCodeFactory extends AbstractCodeFactory {
 
-	public static List<String> RESERVED_KEYWORDS = new ArrayList<String>();
+	public static List<String> RESERVED_KEYWORDS = new ArrayList<>();
 
 	static {
 		RESERVED_KEYWORDS.add("abstract");
@@ -203,4 +203,20 @@
 
 		return data;
 	}
+
+	@Override
+	public String createCommentedString(String comment, boolean addBlockComment) {
+		if (addBlockComment) {
+			final StringBuilder builder = new StringBuilder();
+			builder.append("/**").append(StringTools.LINE_DELIMITER);
+			for (final String line : comment.split("\\r?\\n"))
+				builder.append(" * ").append(line).append(StringTools.LINE_DELIMITER);
+
+			builder.append(" */").append(StringTools.LINE_DELIMITER);
+
+			return builder.toString();
+
+		} else
+			return super.createCommentedString(comment, addBlockComment);
+	}
 }
diff --git a/plugins/org.eclipse.ease.ui.scripts/src/org/eclipse/ease/ui/scripts/handler/ToggleScriptRecording.java b/plugins/org.eclipse.ease.ui.scripts/src/org/eclipse/ease/ui/scripts/handler/ToggleScriptRecording.java
index dc700ac..28e2465 100644
--- a/plugins/org.eclipse.ease.ui.scripts/src/org/eclipse/ease/ui/scripts/handler/ToggleScriptRecording.java
+++ b/plugins/org.eclipse.ease.ui.scripts/src/org/eclipse/ease/ui/scripts/handler/ToggleScriptRecording.java
@@ -60,7 +60,7 @@
 
 	private boolean fChecked = false;
 
-	private static final Map<IScriptEngine, StringBuffer> fRecordings = new HashMap<IScriptEngine, StringBuffer>();
+	private static final Map<IScriptEngine, StringBuffer> fRecordings = new HashMap<>();
 
 	@Override
 	protected final void executeToggle(final ExecutionEvent event, final boolean checked) {
@@ -103,21 +103,22 @@
 								name = dialog.getValue();
 						}
 
-						EngineDescription description = engine.getDescription();
-						ScriptType scriptType = description.getSupportedScriptTypes().iterator().next();
+						final EngineDescription description = engine.getDescription();
+						final ScriptType scriptType = description.getSupportedScriptTypes().iterator().next();
 
-						String fileName = name + "." + scriptType.getDefaultExtension();
+						final String fileName = name + "." + scriptType.getDefaultExtension();
 
 						// write script header
-						Map<String, String> keywords = new HashMap<String, String>();
+						final Map<String, String> keywords = new HashMap<>();
 						keywords.put("name", new Path(name).makeRelative().toString());
 						keywords.put("description", "Script recorded by user.");
 						keywords.put("script-type", scriptType.getName());
 						keywords.put("author", System.getProperty("user.name"));
 						keywords.put("date-recorded", new SimpleDateFormat("yyyy-MM-dd, HH:mm").format(new Date()));
 
-						buffer.insert(0, "\n");
-						buffer.insert(0, scriptType.getCodeFactory().createKeywordHeader(keywords, null));
+						buffer.insert(0, StringTools.LINE_DELIMITER);
+						final String keywordBlock = scriptType.getCodeFactory().createKeywordHeader(keywords, null);
+						buffer.insert(0, scriptType.getCodeFactory().createCommentedString(keywordBlock, true));
 
 						if (storage != null) {
 							// store script
@@ -130,16 +131,16 @@
 						} else {
 							// we do not have a storage, open script in editor
 							// and let user decide, what to do
-							IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+							final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
 							try {
-								IEditorDescriptor editor = IDE.getDefaultEditor(
+								final IEditorDescriptor editor = IDE.getDefaultEditor(
 										ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/sample/foo." + scriptType.getDefaultExtension())));
-								IEditorPart openEditor = IDE.openEditor(page, new ScriptEditorInput(name, buffer.toString()), editor.getId());
+								final IEditorPart openEditor = IDE.openEditor(page, new ScriptEditorInput(name, buffer.toString()), editor.getId());
 								// the editor starts indicating it is not dirty,
 								// so ask the user to perform a save as action
 								openEditor.doSaveAs();
 
-							} catch (PartInitException e) {
+							} catch (final PartInitException e) {
 								Logger.error(Activator.PLUGIN_ID, "Could not open editor for recorded script.", e);
 							}
 						}
@@ -157,7 +158,7 @@
 		if (PreferencesHelper.getUserScriptStorageLocation() == null) {
 
 			// user did not select a storage yet, ask for location
-			SelectScriptStorageDialog dialog = new SelectScriptStorageDialog(Display.getDefault().getActiveShell());
+			final SelectScriptStorageDialog dialog = new SelectScriptStorageDialog(Display.getDefault().getActiveShell());
 			if (dialog.open() == Window.OK) {
 				final IRepositoryService repositoryService = (IRepositoryService) PlatformUI.getWorkbench().getService(IRepositoryService.class);
 				repositoryService.addLocation(dialog.getLocation(), true, true);
diff --git a/tests/org.eclipse.ease.lang.javascript.test/src/org/eclipse/ease/lang/javascript/JavaScriptCodeFactoryTest.java b/tests/org.eclipse.ease.lang.javascript.test/src/org/eclipse/ease/lang/javascript/JavaScriptCodeFactoryTest.java
index 28dce0d..7f7117c 100644
--- a/tests/org.eclipse.ease.lang.javascript.test/src/org/eclipse/ease/lang/javascript/JavaScriptCodeFactoryTest.java
+++ b/tests/org.eclipse.ease.lang.javascript.test/src/org/eclipse/ease/lang/javascript/JavaScriptCodeFactoryTest.java
@@ -28,7 +28,6 @@
 	public void testCommentCreator() {
 		assertEquals("// Comment", fFactory.createCommentedString("Comment"));
 		assertEquals(String.format("// Multi%n// Line%n// Comment"), fFactory.createCommentedString("Multi\nLine\nComment"));
-		assertEquals(String.format("/*Multi%nLine%nComment*/"), fFactory.createCommentedString("Multi\nLine\nComment", true));
+		assertEquals(String.format("/**%n * Multi%n * Line%n * Comment%n */%n"), fFactory.createCommentedString("Multi\nLine\nComment", true));
 	}
-
 }