From 85babacb5acc26f28844be44b9275c1be33b144f Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 5 Jan 2009 15:23:44 +0100 Subject: [PATCH] Replace a. with a[0]. when `a' has type array of T. --- src/plugins/cpptools/cppcodecompletion.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index 50e5432f2f8..b1184420bf6 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -662,6 +662,24 @@ bool CppCodeCompletion::completeMember(const QList &re ty = refTy->elementType(); NamedType *namedTy = 0; + + if (ArrayType *arrayTy = ty->asArrayType()) { + // Replace . with [0]. when `ty' is an array type. + FullySpecifiedType elementTy = arrayTy->elementType(); + + if (ReferenceType *refTy = elementTy->asReferenceType()) + elementTy = refTy->elementType(); + + if (elementTy->isNamedType() || elementTy->isPointerType()) { + ty = elementTy; + + const int length = m_editor->position() - m_startPosition + 1; + m_editor->setCurPos(m_startPosition - 1); + m_editor->replace(length, QLatin1String("[0].")); + m_startPosition += 3; + } + } + if (PointerType *ptrTy = ty->asPointerType()) { // Replace . with -> int length = m_editor->position() - m_startPosition + 1;