Code clean up and doc updates

Drop use of `this.` for accessing fields and methods.

Change-Id: I167dc90763959b69182e22ff0d5bd3cd8d1ad735
diff --git a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/EMacroService.java b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/EMacroService.java
index 77338b6..3ca040e 100644
--- a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/EMacroService.java
+++ b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/EMacroService.java
@@ -69,29 +69,27 @@
 	int PRIORITY_HIGH = 10;
 
 	/**
-	 * Adds a macro instruction to be added to the current macro being recorded. The
-	 * difference between this method and
-	 * {@link #addMacroInstruction(IMacroInstruction)} is that it's meant to be used
-	 * when an event may trigger the creation of multiple macro instructions and
-	 * only one of those should be recorded.
+	 * Adds a macro instruction to be added to the current macro being recorded.
+	 * This method should be used when an event may trigger the creation of
+	 * multiple macro instructions but only one of those should be recorded.
 	 *
-	 * For instance, if a given KeyDown event is recorded in a StyledText and later
-	 * an action is triggered by this event, the recorded action should overwrite
-	 * the KeyDown event.
+	 * For instance, if a given {@code KeyDown} event is recorded in a
+	 * {@link StyledText} and later an action is triggered by this event, the
+	 * recorded action should overwrite the {@code KeyDown} event.
 	 *
 	 * @param macroInstruction
 	 *            the macro instruction to be added to the macro currently being
 	 *            recorded.
 	 * @param event
-	 *            the event that triggered the creation of the macro instruction to
-	 *            be added. If there are multiple macro instructions added for the
-	 *            same event, only the one with the highest priority will be kept
-	 *            (if 2 events have the same priority, the last one will replace the
-	 *            previous one).
+	 *            the event that triggered the creation of the macro instruction
+	 *            to be added. If there are multiple macro instructions added
+	 *            for the same event, only the one with the highest priority
+	 *            will be kept (if 2 events have the same priority, the last one
+	 *            will replace the previous one).
 	 * @param priority
-	 *            the priority of the macro instruction being added (to be compared
-	 *            against the priority of other added macro instructions for the
-	 *            same event).
+	 *            the priority of the macro instruction being added (to be
+	 *            compared against the priority of other added macro
+	 *            instructions for the same event).
 	 * @see #addMacroInstruction(IMacroInstruction)
 	 */
 	void addMacroInstruction(IMacroInstruction macroInstruction, Object event, int priority);
diff --git a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/IMacroContext.java b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/IMacroContext.java
index 212ff8b..ef6a318 100644
--- a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/IMacroContext.java
+++ b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/IMacroContext.java
@@ -11,10 +11,10 @@
 package org.eclipse.e4.core.macros;
 
 /**
- * The context bound to the macro record or playback. Macro state listeners
- * (org.eclipse.e4.core.macros.IMacroStateListener) registered in
- * {@link EMacroService} may use it as a simple key-value store to keep
- * macro-specific state during a record or playback.
+ * The context bound to the macro record or playback.
+ * {@link org.eclipse.e4.core.macros.IMacroStateListener Macro state listeners}
+ * registered with a {@link EMacroService} may use it as a simple key-value
+ * store to keep macro-specific state during macro recording and playback.
  */
 public interface IMacroContext {
 
diff --git a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/IMacroInstruction.java b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/IMacroInstruction.java
index 31ca308..6c9b000 100644
--- a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/IMacroInstruction.java
+++ b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/IMacroInstruction.java
@@ -13,18 +13,17 @@
 import java.util.Map;
 
 /**
- * The basic abstraction of a macro instruction (i.e.: a macro may be composed
- * of multiple macro instructions). The macro instruction also can be stored in
- * disk to be reconstructed later on.
+ * A step in a macro. A macro may be composed of multiple macro instructions. A
+ * macro instruction can be stored on disk for later reconstruction.
  */
 public interface IMacroInstruction {
 
 	/**
 	 * @return the id for the macro instruction.
-	 * @note this id may be visible to the user, so, it should ideally be something
-	 *       short and readable (such as KeyDown, or Command), not a dotted name as
-	 *       is usual for Eclipse ids (note that it cannot be changed afterwards as
-	 *       this id may be written to disk).
+	 * @note This id may be visible to the user so it should ideally be
+	 *       something short and readable (such as {@code KeyDown}, or
+	 *       {@code Command}). Note that an id cannot be changed afterwards as
+	 *       this id may be written to disk.
 	 */
 	String getId();
 
@@ -34,7 +33,7 @@
 	 * @param macroPlaybackContext
 	 *            the context used to playback the macro.
 	 * @throws MacroPlaybackException
-	 *             if something didn't work when executing the macro.
+	 *             if an error occurred when executing the macro.
 	 */
 	void execute(IMacroPlaybackContext macroPlaybackContext) throws MacroPlaybackException;
 
diff --git a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/IMacroInstructionsListener.java b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/IMacroInstructionsListener.java
index cefbd8b..e5099ef 100644
--- a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/IMacroInstructionsListener.java
+++ b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/IMacroInstructionsListener.java
@@ -11,7 +11,13 @@
 package org.eclipse.e4.core.macros;
 
 /**
- * A listener for the macro instructions being added.
+ * An instance of this interface can be notified of changes during macro
+ * recording.
+ *
+ * <ul>
+ * <li>FIXME: this seems to be more of an adviser than listener?
+ * <li>FIXME: rename preAddMacroInstruction -> verifyMacroInstruction()?
+ * </ul>
  */
 public interface IMacroInstructionsListener {
 
@@ -27,13 +33,14 @@
 	void preAddMacroInstruction(IMacroInstruction macroInstruction) throws CancelMacroRecordingException;
 
 	/**
-	 * Called after a given macro instruction is added to the macro. Note that it's
-	 * possible that beforeMacroInstructionAdded is called and
-	 * afterMacroInstructionAdded isn't if the macro instruction doesn't have enough
-	 * priority.
+	 * Called after a given macro instruction is added to the macro. Note that
+	 * it is possible that {@link #preAddMacroInstruction(IMacroInstruction)} is
+	 * called without a matching
+	 * {@link #postAddMacroInstruction(IMacroInstruction)) should the macro
+	 * instruction not be of high-enough priority.
 	 *
 	 * @param macroInstruction
-	 *            the macro instruction just added to the current macro.
+	 *            the macro instruction added to the current macro.
 	 */
 	void postAddMacroInstruction(IMacroInstruction macroInstruction);
 }
diff --git a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/ComposableMacro.java b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/ComposableMacro.java
index eedf507..3828e2d 100644
--- a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/ComposableMacro.java
+++ b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/ComposableMacro.java
@@ -44,8 +44,8 @@
 		private final int fPriority;
 
 		private IndexAndPriority(int index, int priority) {
-			this.fIndex = index;
-			this.fPriority = priority;
+			fIndex = index;
+			fPriority = priority;
 		}
 
 	}
@@ -93,40 +93,39 @@
 	}
 
 	/**
-	 * Adds a macro instruction to be added to the current macro being recorded. The
-	 * difference between this method and
-	 * {@link #addMacroInstruction(IMacroInstruction)} is that it's meant to be used
-	 * when an event may trigger the creation of multiple macro instructions and
-	 * only one of those should be recorded.
+	 * Adds a macro instruction to be added to the current macro being recorded.
+	 * This method should be used when an event may trigger the creation of
+	 * multiple macro instructions and only one of those should be recorded.
 	 *
 	 * @param macroInstruction
 	 *            the macro instruction to be added to the macro currently being
 	 *            recorded.
 	 * @param event
-	 *            the event that triggered the creation of the macro instruction to
-	 *            be added. If there are multiple macro instructions added for the
-	 *            same event, only the one with the highest priority will be kept
-	 *            (if 2 events have the same priority, the last one will replace the
-	 *            previous one).
+	 *            the event that triggered the creation of the macro instruction
+	 *            to be added. If there are multiple macro instructions added
+	 *            for the same event, only the one with the highest priority
+	 *            will be kept (if 2 events have the same priority, the last one
+	 *            will replace the previous one).
 	 * @param priority
-	 *            the priority of the macro instruction being added (to be compared
-	 *            against the priority of other added macro instructions for the
-	 *            same event).
-	 * @return true if the macro instruction was actually added and false otherwise.
+	 *            the priority of the macro instruction being added (to be
+	 *            compared against the priority of other added macro
+	 *            instructions for the same event).
+	 * @return true if the macro instruction was actually added and false
+	 *         otherwise.
 	 * @see #addMacroInstruction(IMacroInstruction)
 	 */
 	public boolean addMacroInstruction(IMacroInstruction macroInstruction, Object event, int priority) {
 		Assert.isNotNull(event);
-		IndexAndPriority currentIndexAndPriority = this.fEventToPlacement.get(event);
+		IndexAndPriority currentIndexAndPriority = fEventToPlacement.get(event);
 		if (currentIndexAndPriority == null) {
-			this.addMacroInstruction(macroInstruction);
-			this.fEventToPlacement.put(event, new IndexAndPriority(this.fMacroInstructions.size() - 1, priority));
+			addMacroInstruction(macroInstruction);
+			fEventToPlacement.put(event, new IndexAndPriority(fMacroInstructions.size() - 1, priority));
 			return true;
 		}
 		if (priority >= currentIndexAndPriority.fPriority) {
 			checkMacroInstruction(macroInstruction);
 			fMacroInstructions.set(currentIndexAndPriority.fIndex, macroInstruction);
-			this.fEventToPlacement.put(event, new IndexAndPriority(currentIndexAndPriority.fIndex, priority));
+			fEventToPlacement.put(event, new IndexAndPriority(currentIndexAndPriority.fIndex, priority));
 			return true;
 		}
 		return false;
@@ -137,7 +136,7 @@
 	 * after the macro is properly composed.
 	 */
 	public void clearCachedInfo() {
-		this.fEventToPlacement.clear();
+		fEventToPlacement.clear();
 	}
 
 	@Override
@@ -149,20 +148,21 @@
 	}
 
 	/**
-	 * Actually returns the bytes to be written to the disk to be loaded back later
-	 * on (the actual load and playback is later done by {@link SavedJSMacro}.
+	 * Actually returns the bytes to be written to the disk to be loaded back
+	 * later on (the actual load and playback is later done by
+	 * {@link SavedJSMacro}).
 	 *
-	 * @return an UTF-8 encoded array of bytes which can be used to rerun the macro
-	 *         later on.
+	 * @return an UTF-8 encoded array of bytes which can be used to rerun the
+	 *         macro later on.
 	 */
 	/* default */ byte[] toJSBytes() {
-		final StringBuilder buf = new StringBuilder(this.fMacroInstructions.size() * 60);
+		final StringBuilder buf = new StringBuilder(fMacroInstructions.size() * 60);
 
 		buf.append("// Macro generated by the Eclipse macro record engine.\n"); //$NON-NLS-1$
 		buf.append("// The runMacro() function will be later run by the macro engine.\n"); //$NON-NLS-1$
 		buf.append("function runMacro(){\n"); //$NON-NLS-1$
 
-		for (IMacroInstruction macroInstruction : this.fMacroInstructions) {
+		for (IMacroInstruction macroInstruction : fMacroInstructions) {
 			Map<String, String> map = macroInstruction.toMap();
 			Assert.isNotNull(map);
 
@@ -181,6 +181,6 @@
 	 * @return the number of macro instructions in this macro.
 	 */
 	public int getLength() {
-		return this.fMacroInstructions.size();
+		return fMacroInstructions.size();
 	}
 }
diff --git a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/MacroManager.java b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/MacroManager.java
index 5af2d04..2f095f8 100644
--- a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/MacroManager.java
+++ b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/MacroManager.java
@@ -60,7 +60,7 @@
 	 */
 	public void setMaxNumberOfTemporaryMacros(int maxNumberOfTemporaryMacros) {
 		Assert.isTrue(maxNumberOfTemporaryMacros >= 1);
-		this.fMaxNumberOfTemporaryMacros = maxNumberOfTemporaryMacros;
+		fMaxNumberOfTemporaryMacros = maxNumberOfTemporaryMacros;
 	}
 
 	/**
@@ -128,7 +128,7 @@
 		for (File file : macrosDirectories) {
 			Assert.isNotNull(file);
 		}
-		this.fMacrosDirectories = macrosDirectories;
+		fMacrosDirectories = macrosDirectories;
 		reloadMacros();
 	}
 
@@ -244,7 +244,7 @@
 			// Start recording
 			fMacroRecordContext = new MacroRecordContext();
 			fMacroBeingRecorded = new ComposableMacro(macroInstructionIdToFactory);
-			for (IMacroStateListener listener : this.fStateListeners) {
+			for (IMacroStateListener listener : fStateListeners) {
 				SafeRunner.run(() -> listener.macroRecordContextCreated(fMacroRecordContext));
 			}
 			if (!notifyMacroStateChange(macroService, StateChange.RECORD_STARTED)) {
@@ -287,8 +287,8 @@
 		public final long fLastModified;
 
 		public PathAndTime(Path path, long lastModified) {
-			this.fPath = path;
-			this.fLastModified = lastModified;
+			fPath = path;
+			fLastModified = lastModified;
 		}
 
 	}
@@ -298,12 +298,12 @@
 	 *            the macro to be recorded as a temporary macro.
 	 */
 	private void saveTemporaryMacro(ComposableMacro macro) {
-		if (fMacrosDirectories == null || this.fMacrosDirectories.length == 0) {
+		if (fMacrosDirectories == null || fMacrosDirectories.length == 0) {
 			return;
 		}
 		// The first one is the one we use as a working directory to store
 		// temporary macros.
-		File macroDirectory = this.fMacrosDirectories[0];
+		File macroDirectory = fMacrosDirectories[0];
 		if (!macroDirectory.isDirectory()) {
 			Activator.log(new RuntimeException(
 					String.format("Unable to save macro. Expected: %s to be a directory.", macroDirectory))); //$NON-NLS-1$
@@ -418,7 +418,7 @@
 			fIsPlayingBack = true;
 			try {
 				fMacroPlaybackContext = macroPlaybackContext;
-				for (IMacroStateListener listener : this.fStateListeners) {
+				for (IMacroStateListener listener : fStateListeners) {
 					SafeRunner.run(() -> listener.macroPlaybackContextCreated(macroPlaybackContext));
 				}
 
@@ -471,11 +471,11 @@
 	 * Reloads the macros available from the disk.
 	 */
 	public void reloadMacros() {
-		for (File macroDirectory : this.fMacrosDirectories) {
+		for (File macroDirectory : fMacrosDirectories) {
 			if (macroDirectory.isDirectory()) {
 				List<PathAndTime> listPathsAndTimes = listTemporaryMacrosPathAndTime(macroDirectory);
 				if (listPathsAndTimes.size() > 0) {
-					this.fLastMacro = new SavedJSMacro(listPathsAndTimes.get(0).fPath.toFile());
+					fLastMacro = new SavedJSMacro(listPathsAndTimes.get(0).fPath.toFile());
 					return; // Load the last from the first directory (others aren't used for the last
 							// macro).
 				}
diff --git a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/MacroServiceImplementation.java b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/MacroServiceImplementation.java
index 42894b5..66d390d 100644
--- a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/MacroServiceImplementation.java
+++ b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/MacroServiceImplementation.java
@@ -11,9 +11,11 @@
 package org.eclipse.e4.core.macros.internal;
 
 import java.io.File;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import javax.inject.Inject;
+import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtensionRegistry;
@@ -37,12 +39,40 @@
  * with the eclipse context and extension points).
  */
 public class MacroServiceImplementation implements EMacroService {
+	private static final String MACRO_COMMAND_HANDLING_EXTENSION_POINT = "org.eclipse.e4.core.macros.commandHandling"; //$NON-NLS-1$
+	private static final String MACRO_COMMAND_HANDLING_ELEMENT = "command"; //$NON-NLS-1$
+	private static final String MACRO_COMMAND_HANDLING_ID = "id"; //$NON-NLS-1$
+	private static final String MACRO_COMMAND_HANDLING_RECORDING = "recordMacroInstruction"; //$NON-NLS-1$
+
+	public static final String MACRO_INSTRUCTION_FACTORY_EXTENSION_POINT = "org.eclipse.e4.core.macros.macroInstructionsFactory"; //$NON-NLS-1$
+	public static final String MACRO_INSTRUCTION_ID = "macroInstructionId"; //$NON-NLS-1$
+	public static final String MACRO_INSTRUCTION_FACTORY_CLASS = "class"; //$NON-NLS-1$
+
+	public static final String MACRO_LISTENERS_EXTENSION_POINT = "org.eclipse.e4.core.macros.macroStateListeners"; //$NON-NLS-1$
+	public static final String MACRO_LISTENER_CLASS = "class"; //$NON-NLS-1$
+
+	// id to factory used in instance
+	private Map<String, IMacroInstructionFactory> fMacroInstructionIdToFactory;
+
+	private boolean fLoadedExtensionListeners = false;
+
+	private IEclipseContext fEclipseContext;
+
+	private IExtensionRegistry fExtensionRegistry;
 
 	/**
 	 * The instance of the macro manager.
 	 */
 	private MacroManager fMacroManager;
 
+	@Inject
+	public MacroServiceImplementation(IEclipseContext eclipseContext, IExtensionRegistry extensionRegistry) {
+		Assert.isNotNull(eclipseContext);
+		Assert.isNotNull(extensionRegistry);
+		fEclipseContext = eclipseContext;
+		fExtensionRegistry = extensionRegistry;
+	}
+
 	/**
 	 * Gets the macro manager (lazily creates it if needed).
 	 *
@@ -81,37 +111,11 @@
 		return fMacroManager;
 	}
 
-	public static final String MACRO_INSTRUCTION_FACTORY_EXTENSION_POINT = "org.eclipse.e4.core.macros.macroInstructionsFactory"; //$NON-NLS-1$
-	public static final String MACRO_INSTRUCTION_ID = "macroInstructionId"; //$NON-NLS-1$
-	public static final String MACRO_INSTRUCTION_FACTORY_CLASS = "class"; //$NON-NLS-1$
-
-	// Globally loaded id to factory
-	private static Map<String, IMacroInstructionFactory> fCachedMacroInstructionIdToFactory;
-
-	// id to factory used in instance
-	private Map<String, IMacroInstructionFactory> fMacroInstructionIdToFactory;
-
-	public static final String MACRO_LISTENERS_EXTENSION_POINT = "org.eclipse.e4.core.macros.macroStateListeners"; //$NON-NLS-1$
-	public static final String MACRO_LISTENER_CLASS = "class"; //$NON-NLS-1$
-
-	private boolean fLoadedExtensionListeners = false;
-
-	private IEclipseContext fEclipseContext;
-
-	private IExtensionRegistry fExtensionRegistry;
-
-	@Inject
-	public MacroServiceImplementation(IEclipseContext eclipseContext, IExtensionRegistry extensionRegistry) {
-		this.fEclipseContext = eclipseContext;
-		this.fExtensionRegistry = extensionRegistry;
-	}
-
-
 	/**
 	 * Loads the macro listeners provided through extension points.
 	 */
 	private void loadExtensionPointsmacroStateListeners() {
-		if (!fLoadedExtensionListeners && fExtensionRegistry != null) {
+		if (!fLoadedExtensionListeners) {
 			fLoadedExtensionListeners = true;
 
 			MacroManager macroManager = getMacroManager();
@@ -142,31 +146,28 @@
 	 */
 	private Map<String, IMacroInstructionFactory> getMacroInstructionIdToFactory() {
 		if (fMacroInstructionIdToFactory == null) {
-			if (fCachedMacroInstructionIdToFactory == null && fEclipseContext != null && fExtensionRegistry != null) {
-				Map<String, IMacroInstructionFactory> validMacroInstructionIds = new HashMap<>();
-				for (IConfigurationElement ce : fExtensionRegistry
-						.getConfigurationElementsFor(MACRO_INSTRUCTION_FACTORY_EXTENSION_POINT)) {
-					String macroInstructionId = ce.getAttribute(MACRO_INSTRUCTION_ID);
-					String macroInstructionFactoryClass = ce.getAttribute(MACRO_INSTRUCTION_FACTORY_CLASS);
-					if (macroInstructionId != null && macroInstructionFactoryClass != null) {
-						try {
-							IMacroInstructionFactory macroInstructionFactory = (IMacroInstructionFactory) ce
-									.createExecutableExtension(MACRO_INSTRUCTION_FACTORY_CLASS);
+			Map<String, IMacroInstructionFactory> validMacroInstructionIds = new HashMap<>();
+			for (IConfigurationElement ce : fExtensionRegistry
+					.getConfigurationElementsFor(MACRO_INSTRUCTION_FACTORY_EXTENSION_POINT)) {
+				String macroInstructionId = ce.getAttribute(MACRO_INSTRUCTION_ID);
+				String macroInstructionFactoryClass = ce.getAttribute(MACRO_INSTRUCTION_FACTORY_CLASS);
+				if (macroInstructionId != null && macroInstructionFactoryClass != null) {
+					try {
+						IMacroInstructionFactory macroInstructionFactory = (IMacroInstructionFactory) ce
+								.createExecutableExtension(MACRO_INSTRUCTION_FACTORY_CLASS);
 
-							// Make sure that it has the proper eclipse context.
-							ContextInjectionFactory.inject(macroInstructionFactory, fEclipseContext);
-							validMacroInstructionIds.put(macroInstructionId, macroInstructionFactory);
-						} catch (CoreException e) {
-							Activator.log(e);
-						}
-					} else {
-						Activator.log(new RuntimeException("Wrong definition for extension: " //$NON-NLS-1$
-								+ MACRO_INSTRUCTION_FACTORY_EXTENSION_POINT + ": " + ce)); //$NON-NLS-1$
+						// Make sure that it has the proper eclipse context.
+						ContextInjectionFactory.inject(macroInstructionFactory, fEclipseContext);
+						validMacroInstructionIds.put(macroInstructionId, macroInstructionFactory);
+					} catch (CoreException e) {
+						Activator.log(e);
 					}
+				} else {
+					Activator.log(new RuntimeException("Wrong definition for extension: " //$NON-NLS-1$
+							+ MACRO_INSTRUCTION_FACTORY_EXTENSION_POINT + ": " + ce)); //$NON-NLS-1$
 				}
-				fCachedMacroInstructionIdToFactory = validMacroInstructionIds;
 			}
-			fMacroInstructionIdToFactory = fCachedMacroInstructionIdToFactory;
+			fMacroInstructionIdToFactory = Collections.unmodifiableMap(validMacroInstructionIds);
 		}
 		return fMacroInstructionIdToFactory;
 	}
@@ -191,7 +192,7 @@
 
 	@Override
 	public void addMacroInstruction(IMacroInstruction macroInstruction) {
-		if (this.isRecording()) {
+		if (isRecording()) {
 			try {
 				getMacroManager().addMacroInstruction(macroInstruction);
 			} catch (CancelMacroRecordingException e) {
@@ -202,7 +203,7 @@
 
 	@Override
 	public void addMacroInstruction(IMacroInstruction macroInstruction, Object event, int priority) {
-		if (this.isRecording()) {
+		if (isRecording()) {
 			try {
 				getMacroManager().addMacroInstruction(macroInstruction, event, priority);
 			} catch (CancelMacroRecordingException e) {
@@ -215,8 +216,8 @@
 	 * Stops the macro recording.
 	 */
 	private void stopMacroRecording() {
-		if (this.isRecording()) {
-			this.toggleMacroRecord();
+		if (isRecording()) {
+			toggleMacroRecord();
 		}
 	}
 
@@ -276,20 +277,13 @@
 	private Map<String, Boolean> getInternalcommandHandling() {
 		if (fCustomizedCommandIds == null) {
 			fCustomizedCommandIds = new HashMap<>();
-			if (fEclipseContext != null) {
-				IExtensionRegistry registry = fEclipseContext.get(IExtensionRegistry.class);
-				if (registry != null) {
-					for (IConfigurationElement ce : registry
-							.getConfigurationElementsFor("org.eclipse.e4.core.macros.commandHandling")) { //$NON-NLS-1$
-						if ("command".equals(ce.getName()) && ce.getAttribute("id") != null //$NON-NLS-1$ //$NON-NLS-2$
-								&& ce.getAttribute("recordMacroInstruction") != null) { //$NON-NLS-1$
-							Boolean recordMacroInstruction = Boolean
-									.parseBoolean(ce.getAttribute("recordMacroInstruction")) //$NON-NLS-1$
-											? Boolean.TRUE
-											: Boolean.FALSE;
-							fCustomizedCommandIds.put(ce.getAttribute("id"), recordMacroInstruction); //$NON-NLS-1$
-						}
-					}
+			for (IConfigurationElement ce : fExtensionRegistry
+					.getConfigurationElementsFor(MACRO_COMMAND_HANDLING_EXTENSION_POINT)) {
+				if (MACRO_COMMAND_HANDLING_ELEMENT.equals(ce.getName())
+						&& ce.getAttribute(MACRO_COMMAND_HANDLING_ID) != null
+						&& ce.getAttribute(MACRO_COMMAND_HANDLING_RECORDING) != null) {
+					Boolean recordMacroInstruction = Boolean.parseBoolean(ce.getAttribute(MACRO_COMMAND_HANDLING_RECORDING));
+					fCustomizedCommandIds.put(ce.getAttribute(MACRO_COMMAND_HANDLING_ID), recordMacroInstruction);
 				}
 			}
 		}
@@ -299,11 +293,7 @@
 	@Override
 	public boolean isCommandRecorded(String commandId) {
 		Map<String, Boolean> macrocommandHandling = getInternalcommandHandling();
-		Boolean recordMacro = macrocommandHandling.get(commandId);
-		if (recordMacro == null) {
-			return true;
-		}
-		return recordMacro;
+		return macrocommandHandling.getOrDefault(commandId, true);
 	}
 
 	@Override
diff --git a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/Messages.java b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/Messages.java
index 5734d1d..6fb60b6 100644
--- a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/Messages.java
+++ b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/Messages.java
@@ -18,6 +18,7 @@
 public class Messages extends NLS {
 	private static final String BUNDLE_NAME = "org.eclipse.e4.core.macros.internal.messages"; //$NON-NLS-1$
 	public static String SavedJSMacro_MacrosEvalError;
+	public static String SavedJSMacro_NoJavaScriptEngineFound;
 	static {
 		// initialize resource bundle
 		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/SavedJSMacro.java b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/SavedJSMacro.java
index 89df07f..61ede84 100644
--- a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/SavedJSMacro.java
+++ b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/SavedJSMacro.java
@@ -46,18 +46,18 @@
 	private final File fFile;
 
 	/**
-	 * Creates a macro which is backed up by the contents of a javascript file.
+	 * Creates a macro which is backed by the contents of a javascript file.
 	 *
 	 * @param file
 	 *            the file with the contents of the macro.
 	 */
 	public SavedJSMacro(File file) {
-		this.fFile = file;
+		fFile = file;
 	}
 
 	/**
 	 * Static method to be called when playing back a macro to run a macro
-	 * instruction..
+	 * instruction.
 	 *
 	 * @param macroPlaybackContext
 	 *            the context for the macro playback.
@@ -66,8 +66,8 @@
 	 * @param macroInstructionParameters
 	 *            the parameters to create the macro instruction.
 	 * @param macroInstructionIdToFactory
-	 *            a map pointing from the macro instruction id to the factory used
-	 *            to create the related macro instruction.
+	 *            a map pointing from the macro instruction id to the factory
+	 *            used to create the related macro instruction.
 	 * @throws Exception
 	 *             if something happened when creating the macro instruction or
 	 *             actually executing it.
@@ -87,7 +87,7 @@
 
 		IMacroInstructionFactory macroFactory = macroInstructionIdToFactory.get(macroInstructionId);
 		if (macroFactory == null) {
-			throw new RuntimeException(
+			throw new IllegalStateException(
 					"Unable to find IMacroInstructionFactory for macro instruction: " + macroInstructionId); //$NON-NLS-1$
 		}
 
@@ -99,7 +99,10 @@
 	public void playback(IMacroPlaybackContext macroPlaybackContext,
 			Map<String, IMacroInstructionFactory> macroInstructionIdToFactory) throws MacroPlaybackException {
 		ScriptEngineManager manager = new ScriptEngineManager();
-		ScriptEngine engine = manager.getEngineByName("nashorn"); //$NON-NLS-1$
+		ScriptEngine engine = manager.getEngineByName("JavaScript"); //$NON-NLS-1$
+		if (engine == null) {
+			throw new MacroPlaybackException(Messages.SavedJSMacro_NoJavaScriptEngineFound);
+		}
 		SimpleScriptContext context = new SimpleScriptContext();
 		context.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
 		Bindings engineScope = context.getBindings(ScriptContext.ENGINE_SCOPE);
diff --git a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/messages.properties b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/messages.properties
index 3677ab5..dd8d464 100644
--- a/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/messages.properties
+++ b/bundles/org.eclipse.e4.core.macros/src/org/eclipse/e4/core/macros/internal/messages.properties
@@ -1 +1,2 @@
 SavedJSMacro_MacrosEvalError=Error when evaluating macro:\n\n{0}
+SavedJSMacro_NoJavaScriptEngineFound=No javascript engine available
diff --git a/tests/org.eclipse.e4.ui.macros.tests/src/org/eclipse/e4/ui/macros/tests/MacroTest.java b/tests/org.eclipse.e4.ui.macros.tests/src/org/eclipse/e4/ui/macros/tests/MacroTest.java
index 90e2852..f04311e 100644
--- a/tests/org.eclipse.e4.ui.macros.tests/src/org/eclipse/e4/ui/macros/tests/MacroTest.java
+++ b/tests/org.eclipse.e4.ui.macros.tests/src/org/eclipse/e4/ui/macros/tests/MacroTest.java
@@ -19,7 +19,11 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.RegistryFactory;
+import org.eclipse.core.runtime.spi.RegistryStrategy;
+import org.eclipse.e4.core.contexts.EclipseContextFactory;
+import org.eclipse.e4.core.contexts.IEclipseContext;
 import org.eclipse.e4.core.macros.CancelMacroRecordingException;
 import org.eclipse.e4.core.macros.EMacroService;
 import org.eclipse.e4.core.macros.IMacroInstruction;
@@ -100,7 +104,11 @@
 	@Test
 	public void testRecordingState() throws Exception {
 		Map<String, IMacroInstructionFactory> macroInstructionIdToFactory = makeMacroInstructionIdToFactory();
-		MacroServiceImplementation macroService = new MacroServiceImplementation(null, null);
+		IEclipseContext eclipseContext = EclipseContextFactory.create("testRecordingState");
+		IExtensionRegistry extensionRegistry = RegistryFactory.createRegistry(new RegistryStrategy(null, null), "foo",
+				"bar");
+		MacroServiceImplementation macroService = new MacroServiceImplementation(eclipseContext,
+				extensionRegistry);
 		Field field = macroService.getClass().getDeclaredField("fMacroInstructionIdToFactory");
 		field.setAccessible(true);
 		field.set(macroService, macroInstructionIdToFactory);