summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2009-06-09 15:39:50 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2009-06-09 15:39:50 +0200
commit31522c55994cf738ba2f8f152b349ff2ae149270 (patch)
tree4816833e2f8d19dadb33a5f1f86f1e3526602a6d /src
parent769d6282bd6e333bde599699eef68c2df3025fc5 (diff)
downloadqt-creator-31522c55994cf738ba2f8f152b349ff2ae149270.tar.gz
Improved the semantic search for class declarations.
Diffstat (limited to 'src')
-rw-r--r--src/plugins/cpptools/cppsemanticsearch.cpp57
-rw-r--r--src/plugins/cpptools/cppsemanticsearch.h2
2 files changed, 42 insertions, 17 deletions
diff --git a/src/plugins/cpptools/cppsemanticsearch.cpp b/src/plugins/cpptools/cppsemanticsearch.cpp
index 68fb581a34..526b5b2e46 100644
--- a/src/plugins/cpptools/cppsemanticsearch.cpp
+++ b/src/plugins/cpptools/cppsemanticsearch.cpp
@@ -31,6 +31,7 @@
#include "cppmodelmanager.h"
#include <AST.h>
+#include <Literals.h>
#include <TranslationUnit.h>
#include <QtCore/QDir>
@@ -44,13 +45,14 @@ using namespace CPlusPlus;
namespace {
-class FindClass: public SemanticSearch
+class SearchClass: public SemanticSearch
{
QString _text;
QTextDocument::FindFlags _findFlags;
public:
- FindClass(QFutureInterface<Core::Utils::FileSearchResult> &future, Document::Ptr doc, Snapshot snapshot)
+ SearchClass(QFutureInterface<Core::Utils::FileSearchResult> &future,
+ Document::Ptr doc, Snapshot snapshot)
: SemanticSearch(future, doc, snapshot)
{ }
@@ -66,25 +68,48 @@ public:
protected:
using ASTVisitor::visit;
- virtual bool visit(ClassSpecifierAST *ast)
+ bool match(NameAST *name)
{
- if (ast->name) {
- Qt::CaseSensitivity cs = Qt::CaseInsensitive;
+ if (! name)
+ return false;
+
+ else if (SimpleNameAST *simpleName = name->asSimpleName()) {
+ if (Identifier *id = identifier(simpleName->identifier_token)) {
+ Qt::CaseSensitivity cs = Qt::CaseInsensitive;
+
+ if (_findFlags & QTextDocument::FindCaseSensitively)
+ cs = Qt::CaseSensitive;
+
+ QString s = QString::fromUtf8(id->chars(), id->size());
+ int index = s.indexOf(_text, 0, cs);
+ if (index != -1) {
+ reportResult(simpleName->identifier_token, index, _text.length());
+ return true;
+ }
+ }
+ }
- if (_findFlags & QTextDocument::FindCaseSensitively)
- cs = Qt::CaseSensitive;
+ else if (QualifiedNameAST *q = name->asQualifiedName()) {
+ return match(q->unqualified_name);
+ }
- Token start = tokenAt(ast->name->firstToken());
- Token end = tokenAt(ast->name->lastToken() - 1);
- const QString className = QString::fromUtf8(source().constData() + start.begin(),
- end.end() - start.begin());
+ return false;
+ }
- if (className.contains(_text, cs))
- reportResult(ast->name->firstToken());
+ virtual bool visit(ElaboratedTypeSpecifierAST *ast)
+ {
+ if (tokenKind(ast->classkey_token) != T_ENUM) {
+ match(ast->name);
}
return true;
}
+
+ virtual bool visit(ClassSpecifierAST *ast)
+ {
+ match(ast->name);
+ return true;
+ }
};
} // end of anonymous namespace
@@ -130,7 +155,7 @@ QString SemanticSearch::matchingLine(const Token &tk) const
return matchingLine;
}
-void SemanticSearch::reportResult(unsigned tokenIndex)
+void SemanticSearch::reportResult(unsigned tokenIndex, int offset, int len)
{
const Token &tk = tokenAt(tokenIndex);
const QString lineText = matchingLine(tk);
@@ -142,14 +167,14 @@ void SemanticSearch::reportResult(unsigned tokenIndex)
--col; // adjust the column position.
_future.reportResult(Core::Utils::FileSearchResult(QDir::toNativeSeparators(_doc->fileName()),
- line, lineText, col, tk.length));
+ line, lineText, col + offset, len));
}
SemanticSearch *SearchClassDeclarationsFactory::create(QFutureInterface<Core::Utils::FileSearchResult> &future,
Document::Ptr doc,
Snapshot snapshot)
{
- FindClass *findClass = new FindClass(future, doc, snapshot);
+ SearchClass *findClass = new SearchClass(future, doc, snapshot);
findClass->setText(_text);
findClass->setFindFlags(_findFlags);
return findClass;
diff --git a/src/plugins/cpptools/cppsemanticsearch.h b/src/plugins/cpptools/cppsemanticsearch.h
index 68c233c847..7bd10b5cc3 100644
--- a/src/plugins/cpptools/cppsemanticsearch.h
+++ b/src/plugins/cpptools/cppsemanticsearch.h
@@ -68,7 +68,7 @@ public:
protected:
QString matchingLine(const CPlusPlus::Token &tk) const;
- void reportResult(unsigned tokenIndex);
+ void reportResult(unsigned tokenIndex, int offset, int len);
};
class SemanticSearchFactory