Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Ccontents of wrong file displayed in CContentOutlinePage, if two editors with the same name are opened

Hi Jonah,

You're absolutely right. It has nothing to do with the hash, it has to be
the equals method.

This is the code from CElement's equals method. The key point here is the
check for lhs.getParent() == rhs.getParent()

    public static boolean equals(ICElement lhs, ICElement rhs) {
		if (lhs == rhs) {
			return true;
		}
		if (lhs.getElementType() != rhs.getElementType()) {
			return false;
		}
		String lhsName = lhs.getElementName();
		String rhsName = rhs.getElementName();
		if (lhsName == null || rhsName == null || lhsName.length() !=
rhsName.length() || !lhsName.equals(rhsName)) {
			return false;
		}

		if (lhs instanceof ISourceReference && rhs instanceof ISourceReference) {
			if (((ISourceReference) lhs).getIndex() != ((ISourceReference)
rhs).getIndex()) {
				return false;
			}
		}

		ICElement lhsParent = lhs.getParent();
		ICElement rhsParent = rhs.getParent();
		if (lhsParent == rhsParent) {
			return true;
		}

		return lhsParent != null && lhsParent.equals(rhsParent);
	}


Since lhs.getElementName() and rhs.getElementName() return the same name,
the method doesn't return false before checking the parent. The parent
folder is different for the two files, but getParent() returns the project,
which is the same. I can reproduce that this problem doesn't occur with two
files from different projects.

I would expect a check like lhs.getResource().equals(rhs.getResource())
before the parent check.

Jonah, sadly I don't know how and where to fill a bug report.



--
Sent from: http://eclipse.1072660.n5.nabble.com/Eclipse-CDT-Development-f46177.html


Back to the top