Bug 515405 - document MenuHelper.getId() implementation details

Change-Id: I92a451da4ca5a728961465082c77bf4e0a2f82a2
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java
index 6be1323..8b93bf9 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java
@@ -280,8 +280,13 @@
 		return (expectedType.isInstance(rawValue)) ? expectedType.cast(rawValue) : null;
 	}
 
-	/*
-	 * Support Utilities
+	/**
+	 * Returns id attribute of the element or unique string computed from the
+	 * element registry handle
+	 *
+	 * @param element
+	 *            non null
+	 * @return non null id
 	 */
 	public static String getId(IConfigurationElement element) {
 		String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
@@ -293,12 +298,26 @@
 			id = getCommandId(element);
 		}
 		if (id == null || id.length() == 0) {
-			id = element.toString();
+			id = getConfigurationHandleId(element);
 		}
-
 		return id;
 	}
 
+	/**
+	 * @return unique string computed from the element registry handle
+	 */
+	private static String getConfigurationHandleId(IConfigurationElement element) {
+		// Note: the line below depends on internal details of
+		// ConfigurationElementHandle implementation, see bug 515405 and 515587.
+
+		// ConfigurationElementHandle.hashCode() is implemented in the way that
+		// it returns same number for different element instances with the same
+		// registry handle id (see org.eclipse.core.internal.registry.Handle).
+
+		// Once the bug 515587 provides new API, we should use that
+		return element.toString();
+	}
+
 	static String getName(IConfigurationElement element) {
 		return element.getAttribute(IWorkbenchRegistryConstants.ATT_NAME);
 	}