From 2d262bd3b7cf3b833dfe69a2541ad979f9aa6ad5 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 21 Feb 2012 10:00:32 +0100 Subject: [C++] Added object pool handling for CompletionAssistProvider. Change-Id: I89634989a7f360a30f7ed1bde4e67c93551ddfe4 Reviewed-by: Eike Ziller --- .../cpptools/cppcompletionassistprovider.cpp | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/plugins/cpptools/cppcompletionassistprovider.cpp (limited to 'src/plugins/cpptools/cppcompletionassistprovider.cpp') diff --git a/src/plugins/cpptools/cppcompletionassistprovider.cpp b/src/plugins/cpptools/cppcompletionassistprovider.cpp new file mode 100644 index 0000000000..04d1e17012 --- /dev/null +++ b/src/plugins/cpptools/cppcompletionassistprovider.cpp @@ -0,0 +1,108 @@ +#include "cppcompletionassistprovider.h" + +#include + +#include + +using namespace CPlusPlus; +using namespace CppTools; + +// --------------------------- +// CppCompletionAssistProvider +// --------------------------- +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; +} + +int CppCompletionAssistProvider::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; +} -- cgit v1.2.1