Bug 19300

Summary: ObjectContributions call toString()
Product: [Eclipse Project] Platform Reporter: Erich Gamma <erich_gamma>
Component: UIAssignee: Nick Edgar <n.a.edgar>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P2 CC: akiezun
Version: 2.0Keywords: performance
Target Milestone: 2.0 F3   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Erich Gamma CLA 2002-06-05 09:05:59 EDT
The name filter of the object contributions calls toString on the selection. 
This is problematic since toString should be used for debug purposes only. In 
particular the IJavaElement serializes the object hierarchy. This is expensive. 
Changing the toString implementation of the IJavaElements is not an option 
since the test suites depend on the current implementation.

see 19115 for a trace.
Comment 1 Erich Gamma CLA 2002-06-05 09:10:20 EDT
problem looks like an oversight. toString is always called first even when the 
element implements the WorkbenchAdapter.

private boolean testName(Object object) {
	String nameFilter = config.getAttribute(ATT_NAME_FILTER);
	if (nameFilter == null)
		return true;
	String objectName = object.toString();
	if (object instanceof IAdaptable) {
Comment 2 Nick Edgar CLA 2002-06-05 09:15:13 EDT
We'll fix it.
Comment 3 Kai-Uwe Maetzel CLA 2002-06-05 12:26:10 EDT
*** Bug 19115 has been marked as a duplicate of this bug. ***
Comment 4 Nick Edgar CLA 2002-06-06 22:01:46 EDT
Made the following change.
Old code:
private boolean testName(Object object) {
	String nameFilter = config.getAttribute(ATT_NAME_FILTER);
	if (nameFilter == null)
		return true;
	String objectName = object.toString();
	if (object instanceof IAdaptable) {
		IAdaptable element = (IAdaptable) object;
		IWorkbenchAdapter de = (IWorkbenchAdapter)element.getAdapter
(IWorkbenchAdapter.class);
		if (de != null)
			objectName = de.getLabel(element);
	}
	return SelectionEnabler.verifyNameMatch(objectName, nameFilter);
}

New code:
private boolean testName(Object object) {
	String nameFilter = config.getAttribute(ATT_NAME_FILTER);
	if (nameFilter == null)
		return true;
	String objectName = null;
	if (object instanceof IAdaptable) {
		IAdaptable element = (IAdaptable) object;
		IWorkbenchAdapter de = (IWorkbenchAdapter)element.getAdapter
(IWorkbenchAdapter.class);
		if (de != null)
			objectName = de.getLabel(element);
	}
	if (objectName == null) {
		objectName = object.toString();
	}
	return SelectionEnabler.verifyNameMatch(objectName, nameFilter);
}
Comment 5 Nick Edgar CLA 2002-06-06 22:14:25 EDT
Fixed in I-20020607.