Bug 19300 - ObjectContributions call toString()
Summary: ObjectContributions call toString()
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P2 major (vote)
Target Milestone: 2.0 F3   Edit
Assignee: Nick Edgar CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
: 19115 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-06-05 09:05 EDT by Erich Gamma CLA
Modified: 2002-06-06 22:14 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.