summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcompletionassistprovider.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@nokia.com>2012-02-21 10:00:32 +0100
committerErik Verbruggen <erik.verbruggen@nokia.com>2012-02-23 10:33:50 +0100
commit2d262bd3b7cf3b833dfe69a2541ad979f9aa6ad5 (patch)
tree00f18eb4a987e8b29fd50719e276cf02518f779c /src/plugins/cpptools/cppcompletionassistprovider.cpp
parentf3a3bf78c05a639afb84190b6283977d11ee7461 (diff)
downloadqt-creator-2d262bd3b7cf3b833dfe69a2541ad979f9aa6ad5.tar.gz
[C++] Added object pool handling for CompletionAssistProvider.
Change-Id: I89634989a7f360a30f7ed1bde4e67c93551ddfe4 Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
Diffstat (limited to 'src/plugins/cpptools/cppcompletionassistprovider.cpp')
-rw-r--r--src/plugins/cpptools/cppcompletionassistprovider.cpp108
1 files changed, 108 insertions, 0 deletions
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 <cppeditor/cppeditorconstants.h>
+
+#include <Token.h>
+
+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;
+}