summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcodecompletion.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2010-05-12 14:52:24 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2010-05-14 13:55:21 +0200
commitf9a05d9cedf5596e72f65f635fc0fd42dd01c358 (patch)
treecd788db44d805d7c0fc615f0e4bb14d6c1fc0ae7 /src/plugins/cpptools/cppcodecompletion.cpp
parentc739119c2a41832fc7dbb99163dd79f3842c6eaf (diff)
downloadqt-creator-f9a05d9cedf5596e72f65f635fc0fd42dd01c358.tar.gz
Reimplemented resolve base expression.
Diffstat (limited to 'src/plugins/cpptools/cppcodecompletion.cpp')
-rw-r--r--src/plugins/cpptools/cppcodecompletion.cpp66
1 files changed, 30 insertions, 36 deletions
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index bd2c4f87a1..84492fec2b 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -79,6 +79,11 @@
#include <QtGui/QToolButton>
#include <QtGui/QVBoxLayout>
+
+namespace {
+ const bool debug = ! qgetenv("CPLUSPLUS_DEBUG").isEmpty();
+}
+
using namespace CPlusPlus;
namespace CppTools {
@@ -757,7 +762,14 @@ int CppCodeCompletion::startCompletionInternal(TextEditor::BaseTextEditor *edit,
Scope *scope = thisDocument->scopeAt(line, column);
Q_ASSERT(scope != 0);
+ if (debug)
+ qDebug() << "scope:" << scope->owner()->fileName() << scope->owner()->line() << scope->owner()->column();
+
QList<LookupItem> results = typeOfExpression(expression, scope, TypeOfExpression::Preprocess);
+
+ if (debug)
+ qDebug() << "got:" << results.size() << "results";
+
LookupContext context = typeOfExpression.lookupContext();
if (results.isEmpty()) {
@@ -1053,54 +1065,36 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &r
bool CppCodeCompletion::completeMember(const QList<LookupItem> &baseResults,
const LookupContext &context)
{
+ if (debug)
+ qDebug() << Q_FUNC_INFO << __LINE__;
+
if (baseResults.isEmpty())
return false;
ResolveExpression resolveExpression(context);
bool replacedDotOperator = false;
- const QList<LookupItem> classObjectResults =
- resolveExpression.resolveBaseExpression(baseResults,
- m_completionOperator,
- &replacedDotOperator);
-
- ClassOrNamespace *classOrNamespace = 0;
-
- foreach (const LookupItem &r, classObjectResults) {
- FullySpecifiedType ty = r.type().simplified();
- if (Class *klass = ty->asClassType()) {
- if (ClassOrNamespace *b = context.classOrNamespace(klass)) {
- classOrNamespace = b;
- break;
- }
+ if (ClassOrNamespace *binding = resolveExpression.baseExpression(baseResults,
+ m_completionOperator,
+ &replacedDotOperator)) {
+ if (debug)
+ qDebug() << "cool we got a binding for the base expression";
+
+ if (replacedDotOperator && binding) {
+ // Replace . with ->
+ int length = m_editor->position() - m_startPosition + 1;
+ m_editor->setCurPos(m_startPosition - 1);
+ m_editor->replace(length, QLatin1String("->"));
+ ++m_startPosition;
}
- else if (NamedType *namedTy = ty->asNamedType()) {
- if (ClassOrNamespace *b = context.classOrNamespace(namedTy->name(), r.scope())) {
- classOrNamespace = b;
- break;
- } else {
- Overview oo;
- qDebug() << "*** no class for" << oo(namedTy->name());
- }
- }
- }
+ if (binding)
+ completeClass(binding, context, /*static lookup = */ false);
- if (replacedDotOperator && classOrNamespace) {
- // Replace . with ->
- int length = m_editor->position() - m_startPosition + 1;
- m_editor->setCurPos(m_startPosition - 1);
- m_editor->replace(length, QLatin1String("->"));
- ++m_startPosition;
+ return ! m_completions.isEmpty();
}
- if (classOrNamespace)
- completeClass(classOrNamespace, context, /*static lookup = */ false);
-
- if (! m_completions.isEmpty())
- return true;
-
return false;
}