[C++] Added object pool handling for CompletionAssistProvider.

Change-Id: I89634989a7f360a30f7ed1bde4e67c93551ddfe4
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
Erik Verbruggen
2012-02-21 10:00:32 +01:00
parent f3a3bf78c0
commit 2d262bd3b7
13 changed files with 212 additions and 286 deletions

View File

@@ -82,87 +82,6 @@ using namespace CppTools;
using namespace Internal;
using namespace TextEditor;
namespace {
int activationSequenceChar(const QChar &ch,
const QChar &ch2,
const QChar &ch3,
unsigned *kind,
bool wantFunctionCall)
{
int referencePosition = 0;
int completionKind = T_EOF_SYMBOL;
switch (ch.toLatin1()) {
case '.':
if (ch2 != QLatin1Char('.')) {
completionKind = T_DOT;
referencePosition = 1;
}
break;
case ',':
completionKind = T_COMMA;
referencePosition = 1;
break;
case '(':
if (wantFunctionCall) {
completionKind = T_LPAREN;
referencePosition = 1;
}
break;
case ':':
if (ch3 != QLatin1Char(':') && ch2 == QLatin1Char(':')) {
completionKind = T_COLON_COLON;
referencePosition = 2;
}
break;
case '>':
if (ch2 == QLatin1Char('-')) {
completionKind = T_ARROW;
referencePosition = 2;
}
break;
case '*':
if (ch2 == QLatin1Char('.')) {
completionKind = T_DOT_STAR;
referencePosition = 2;
} else if (ch3 == QLatin1Char('-') && ch2 == QLatin1Char('>')) {
completionKind = T_ARROW_STAR;
referencePosition = 3;
}
break;
case '\\':
case '@':
if (ch2.isNull() || ch2.isSpace()) {
completionKind = T_DOXY_COMMENT;
referencePosition = 1;
}
break;
case '<':
completionKind = T_ANGLE_STRING_LITERAL;
referencePosition = 1;
break;
case '"':
completionKind = T_STRING_LITERAL;
referencePosition = 1;
break;
case '/':
completionKind = T_SLASH;
referencePosition = 1;
break;
case '#':
completionKind = T_POUND;
referencePosition = 1;
break;
}
if (kind)
*kind = completionKind;
return referencePosition;
}
} // Anonymous
namespace CppTools {
namespace Internal {
@@ -500,33 +419,54 @@ int CppFunctionHintModel::activeArgument(const QString &prefix) const
}
// ---------------------------
// CppCompletionAssistProvider
// InternalCompletionAssistProvider
// ---------------------------
bool CppCompletionAssistProvider::supportsEditor(const Core::Id &editorId) const
{
return editorId == Core::Id(CppEditor::Constants::CPPEDITOR_ID);
}
int CppCompletionAssistProvider::activationCharSequenceLength() const
{
return 3;
}
bool CppCompletionAssistProvider::isActivationCharSequence(const QString &sequence) const
{
const QChar &ch = sequence.at(2);
const QChar &ch2 = sequence.at(1);
const QChar &ch3 = sequence.at(0);
if (activationSequenceChar(ch, ch2, ch3, 0, true) != 0)
return true;
return false;
}
IAssistProcessor *CppCompletionAssistProvider::createProcessor() const
IAssistProcessor *InternalCompletionAssistProvider::createProcessor() const
{
return new CppCompletionAssistProcessor;
}
namespace {
class CppCompletionSupportInternal: public CppCompletionSupport
{
public:
CppCompletionSupportInternal(TextEditor::ITextEditor *editor)
: CppCompletionSupport(editor)
{}
virtual ~CppCompletionSupportInternal()
{}
virtual TextEditor::IAssistInterface *createAssistInterface(ProjectExplorer::Project *project,
QTextDocument *document,
int position,
TextEditor::AssistReason reason) const
{
CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
QStringList includePaths;
QStringList frameworkPaths;
if (project) {
includePaths = modelManager->projectInfo(project).includePaths();
frameworkPaths = modelManager->projectInfo(project).frameworkPaths();
}
return new CppTools::Internal::CppCompletionAssistInterface(
document,
position,
editor()->document(),
reason,
modelManager->snapshot(),
includePaths,
frameworkPaths);
}
};
}
CppCompletionSupport *InternalCompletionAssistProvider::completionSupport(ITextEditor *editor)
{
return new CppCompletionSupportInternal(editor);
}
// -----------------
// CppAssistProposal
// -----------------
@@ -816,7 +756,7 @@ int CppCompletionAssistProcessor::startOfOperator(int pos,
const QChar ch2 = pos > 0 ? m_interface->characterAt(pos - 2) : QChar();
const QChar ch3 = pos > 1 ? m_interface->characterAt(pos - 3) : QChar();
int start = pos - activationSequenceChar(ch, ch2, ch3, kind, wantFunctionCall);
int start = pos - CppCompletionAssistProvider::activationSequenceChar(ch, ch2, ch3, kind, wantFunctionCall);
if (start != pos) {
QTextCursor tc(m_interface->textDocument());
tc.setPosition(pos);