diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2009-10-08 15:59:43 +0200 |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2009-10-08 16:00:46 +0200 |
commit | 510f8ccc3d53c2955004a6ba3291c321f33ddcfb (patch) | |
tree | d1d35ed8b06391dc080ba7e1624c473e9d57aab0 /src/plugins/cpptools/cppcodecompletion.cpp | |
parent | b4a17a03c0d397d77131f266270c8d082ec35071 (diff) | |
download | qt-creator-510f8ccc3d53c2955004a6ba3291c321f33ddcfb.tar.gz |
Improved the detection of #include-like directives.
Diffstat (limited to 'src/plugins/cpptools/cppcodecompletion.cpp')
-rw-r--r-- | src/plugins/cpptools/cppcodecompletion.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index 5e8df20ac0..0a30af6f78 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -690,21 +690,16 @@ static int startOfOperator(TextEditor::ITextEditable *editor, } // Check for include preprocessor directive else if (k == T_STRING_LITERAL || k == T_ANGLE_STRING_LITERAL || k == T_SLASH) { - const QList<SimpleToken> &tokens = tokenUnderCursor.tokens(); - int i = 0; bool include = false; - for (; i < tokens.size(); ++i) { - const SimpleToken &token = tokens.at(i); - if (token.position() == tk.position()) { - if (i == 0) // no token on the left, but might be on a previous line - break; - const SimpleToken &previousToken = tokens.at(i - 1); - if (previousToken.is(T_IDENTIFIER)) { - if (previousToken.text() == QLatin1String("include") || - previousToken.text() == QLatin1String("import")) { - include = true; - break; - } + const QList<SimpleToken> &tokens = tokenUnderCursor.tokens(); + if (tokens.size() >= 3) { + if (tokens.at(0).is(T_POUND) && tokens.at(1).is(T_IDENTIFIER) && (tokens.at(2).is(T_STRING_LITERAL) || + tokens.at(2).is(T_ANGLE_STRING_LITERAL))) { + QStringRef directive = tokens.at(1).text(); + if (directive == QLatin1String("include") || + directive == QLatin1String("include_next") || + directive == QLatin1String("import")) { + include = true; } } } |