[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-dev] Ccontents of wrong file displayed in CContentOutlinePage, if two editors with the same name are opened
|
Hi all,
I'm part of a team developing an eclipse plugin. In this plugin, files with
a certain extensions are opened with a CEditor. When opening two different
files with the same name, the Outline View only shows contents from the
first file. Also the highlighting gets wrong.
The following code comes from CEditor and is called from its public
getOutlinePage() method.
private static void setOutlinePageInputIfNotSame(CContentOutlinePage
page, IEditorInput input) {
if (page != null) {
IWorkingCopyManager manager =
CUIPlugin.getDefault().getWorkingCopyManager();
IWorkingCopy workingCopy = manager.getWorkingCopy(input);
if (workingCopy != page.getRoot()) {
page.setInput(workingCopy);
}
}
}
When switching the editor to an editor showing a file with the same file
name, the line IWorkingCopy workingCopy = manager.getWorkingCopy(input);
returns a workingCopy with the wrong resource, although "input" contains the
correct file path.
I think this is due to the implementation of hashCode in CElement, where it
takes a combination of an element's name and its parent's hash code. This
has been made clear in the documentation, where it says: By default, the
hash code for an element is a combination of its name and parent's hash
code. Elements with other requirements override this method.
The problem appears in CModelManager's getSharedWorkingCopy method
public IWorkingCopy getSharedWorkingCopy(IBufferFactory factory,
ITranslationUnit tu, IProblemRequestor requestor,
IProgressMonitor monitor) throws CModelException {
// if factory is null, default factory must be used
if (factory == null)
factory = BufferManager.getDefaultBufferManager();
Map<ITranslationUnit, WorkingCopy> perFactoryWorkingCopies =
sharedWorkingCopies.get(factory);
if (perFactoryWorkingCopies == null) {
perFactoryWorkingCopies = new HashMap<>();
sharedWorkingCopies.put(factory, perFactoryWorkingCopies);
}
WorkingCopy workingCopy = perFactoryWorkingCopies.get(tu);
if (workingCopy != null) {
workingCopy.useCount++;
return workingCopy;
}
CreateWorkingCopyOperation op = new CreateWorkingCopyOperation(tu,
perFactoryWorkingCopies, factory, requestor);
op.runOperation(monitor);
return (IWorkingCopy) op.getResultElements()[0];
}
In the line WorkingCopy workingCopy = perFactoryWorkingCopies.get(tu);. the
wrong object is returned, because both objects have the same hash code.
Now what would be a good way to solve this for me? I'm new to CDT and it
seems to me that I need to extend a lot of classes just to change this
behaviour.
--
Sent from: http://eclipse.1072660.n5.nabble.com/Eclipse-CDT-Development-f46177.html