1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef SEARCHSYMBOLS_H
35 #define SEARCHSYMBOLS_H
37 #include <cplusplus/CppDocument.h>
38 #include <cplusplus/Icons.h>
39 #include <cplusplus/Overview.h>
41 #include <SymbolVisitor.h>
43 #include <QtGui/QIcon>
44 #include <QtCore/QMetaType>
45 #include <QtCore/QString>
46 #include <QtCore/QSet>
47 #include <QtCore/QHash>
56 enum ItemType { Enum, Class, Method, Declaration };
64 ModelItemInfo(const QString &symbolName,
65 const QString &symbolType,
67 QStringList fullyQualifiedName,
68 const QString &fileName,
72 : symbolName(symbolName),
73 symbolType(symbolType),
74 fullyQualifiedName(fullyQualifiedName),
82 ModelItemInfo(const ModelItemInfo &otherInfo)
83 : symbolName(otherInfo.symbolName),
84 symbolType(otherInfo.symbolType),
85 fullyQualifiedName(otherInfo.fullyQualifiedName),
86 fileName(otherInfo.fileName),
90 column(otherInfo.column)
95 QStringList fullyQualifiedName;
103 class SearchSymbols: public std::unary_function<CPlusPlus::Document::Ptr, QList<ModelItemInfo> >,
104 protected CPlusPlus::SymbolVisitor
114 Q_DECLARE_FLAGS(SymbolTypes, SymbolType)
116 static SymbolTypes AllTypes;
120 void setSymbolsToSearchFor(SymbolTypes types);
121 void setSeparateScope(bool separateScope);
123 QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc)
124 { return operator()(doc, QString()); }
126 QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc, const QString &scope);
129 using SymbolVisitor::visit;
131 void accept(CPlusPlus::Symbol *symbol)
132 { CPlusPlus::Symbol::visitSymbol(symbol, this); }
134 QString switchScope(const QString &scope);
136 virtual bool visit(CPlusPlus::UsingNamespaceDirective *);
137 virtual bool visit(CPlusPlus::UsingDeclaration *);
138 virtual bool visit(CPlusPlus::NamespaceAlias *);
139 virtual bool visit(CPlusPlus::Declaration *);
140 virtual bool visit(CPlusPlus::Argument *);
141 virtual bool visit(CPlusPlus::TypenameArgument *);
142 virtual bool visit(CPlusPlus::BaseClass *);
143 virtual bool visit(CPlusPlus::Enum *);
144 virtual bool visit(CPlusPlus::Function *);
145 virtual bool visit(CPlusPlus::Namespace *);
146 virtual bool visit(CPlusPlus::Template *);
147 virtual bool visit(CPlusPlus::Class *);
148 virtual bool visit(CPlusPlus::Block *);
149 virtual bool visit(CPlusPlus::ForwardClassDeclaration *);
152 virtual bool visit(CPlusPlus::ObjCBaseClass *);
153 virtual bool visit(CPlusPlus::ObjCBaseProtocol *);
154 virtual bool visit(CPlusPlus::ObjCClass *);
155 virtual bool visit(CPlusPlus::ObjCForwardClassDeclaration *);
156 virtual bool visit(CPlusPlus::ObjCProtocol *);
157 virtual bool visit(CPlusPlus::ObjCForwardProtocolDeclaration *);
158 virtual bool visit(CPlusPlus::ObjCMethod *);
159 virtual bool visit(CPlusPlus::ObjCPropertyDeclaration *);
161 QString scopedSymbolName(const QString &symbolName) const;
162 QString scopedSymbolName(const CPlusPlus::Symbol *symbol) const;
163 QString symbolName(const CPlusPlus::Symbol *symbol) const;
164 void appendItem(const QString &name,
166 ModelItemInfo::ItemType type,
167 CPlusPlus::Symbol *symbol);
170 QString findOrInsert(const QString &s)
171 { return *strings.insert(s); }
173 QSet<QString> strings; // Used to avoid QString duplication
176 CPlusPlus::Overview overview;
177 CPlusPlus::Icons icons;
178 QList<ModelItemInfo> items;
179 SymbolTypes symbolsToSearchFor;
180 QHash<const CPlusPlus::StringLiteral *, QString> m_paths;
184 } // namespace Internal
185 } // namespace CppTools
187 Q_DECLARE_OPERATORS_FOR_FLAGS(CppTools::Internal::SearchSymbols::SymbolTypes)
188 Q_DECLARE_METATYPE(CppTools::Internal::ModelItemInfo)
190 #endif // SEARCHSYMBOLS_H