mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 00:36:16 +02:00
Correct hashCode and equals for special nodes in call hierarchy, bug 244987.
This commit is contained in:
parent
db8b15aacf
commit
f39d829c21
3 changed files with 74 additions and 4 deletions
|
@ -279,4 +279,62 @@ public class CallHierarchyBugs extends CallHierarchyBaseTest {
|
|||
TreeItem item= checkTreeNode(chTree, 0, 0, "test()");
|
||||
checkTreeNode(chTree, 0, 1, null);
|
||||
}
|
||||
|
||||
// class Base {
|
||||
// public:
|
||||
// virtual void First() {}
|
||||
// virtual void Second() {}
|
||||
// };
|
||||
//
|
||||
// class Derived: public Base {
|
||||
// public:
|
||||
// virtual void First() {}
|
||||
// virtual void Second() {}
|
||||
// };
|
||||
//
|
||||
// void func(Base *base) {
|
||||
// base->First();
|
||||
// base->Second();
|
||||
// }
|
||||
//
|
||||
// int main() {
|
||||
// Derived derived;
|
||||
// func(&derived);
|
||||
// return 0;
|
||||
// }
|
||||
public void testMultiplePolyMorphicMethodCalls_244987() throws Exception {
|
||||
String content= getContentsForTest(1)[0].toString();
|
||||
IFile file= createFile(getProject(), "SomeClass244987.cpp", content);
|
||||
waitForIndexer(fIndex, file, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||
|
||||
final CHViewPart ch= (CHViewPart) activateView(CUIPlugin.ID_CALL_HIERARCHY);
|
||||
final IWorkbenchWindow workbenchWindow = ch.getSite().getWorkbenchWindow();
|
||||
|
||||
// open editor, check outline
|
||||
CEditor editor= openEditor(file);
|
||||
int idx = content.indexOf("main");
|
||||
editor.selectAndReveal(idx, 0);
|
||||
openCallHierarchy(editor, false);
|
||||
|
||||
Tree chTree= checkTreeNode(ch, 0, "main()").getParent();
|
||||
TreeItem ti= checkTreeNode(chTree, 0, 0, "func(Base *)");
|
||||
expandTreeItem(ti);
|
||||
checkTreeNode(chTree, 0, 1, null);
|
||||
|
||||
TreeItem ti1= checkTreeNode(ti, 0, "Base::First()");
|
||||
expandTreeItem(ti1);
|
||||
TreeItem ti2= checkTreeNode(ti, 1, "Base::Second()");
|
||||
expandTreeItem(ti2);
|
||||
checkTreeNode(ti, 2, null);
|
||||
|
||||
checkTreeNode(ti1, 0, "Base::First()");
|
||||
checkTreeNode(ti1, 1, "Derived::First()");
|
||||
checkTreeNode(ti1, 2, null);
|
||||
|
||||
checkTreeNode(ti2, 0, "Base::Second()");
|
||||
checkTreeNode(ti2, 1, "Derived::Second()");
|
||||
checkTreeNode(ti2, 2, null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -8,12 +8,13 @@
|
|||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.callhierarchy;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.util.CoreUtility;
|
||||
|
||||
public class CHMultiDefNode extends CHNode {
|
||||
|
||||
private CHNode[] fChildren;
|
||||
|
@ -23,6 +24,7 @@ public class CHMultiDefNode extends CHNode {
|
|||
if (elements.length == 0) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
fHashCode+= elements[0].hashCode();
|
||||
fChildren= new CHNode[elements.length];
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
ICElement element = elements[i];
|
||||
|
@ -54,4 +56,14 @@ public class CHMultiDefNode extends CHNode {
|
|||
public boolean isMultiDef() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!super.equals(o) || !(o instanceof CHMultiDefNode))
|
||||
return false;
|
||||
|
||||
final CHMultiDefNode rhs = (CHMultiDefNode) o;
|
||||
return CoreUtility.safeEquals(getOneRepresentedDeclaration(), rhs.getOneRepresentedDeclaration());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class CHNode implements IAdaptable {
|
|||
private ITranslationUnit fFileOfReferences;
|
||||
private List<CHReferenceInfo> fReferences;
|
||||
|
||||
private int fHashCode;
|
||||
protected int fHashCode;
|
||||
private long fTimestamp;
|
||||
private boolean fIsRecursive;
|
||||
private boolean fIsInitializer;
|
||||
|
@ -54,7 +54,7 @@ public class CHNode implements IAdaptable {
|
|||
}
|
||||
|
||||
private int computeHashCode() {
|
||||
int hashCode= 0;
|
||||
int hashCode= 1;
|
||||
if (fParent != null) {
|
||||
hashCode= fParent.hashCode() * 31;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue