OSDN Git Service

0bb4ae765b11c3d0832bf9a742e155603a4e6617
[qt-creator-jp/qt-creator-jp.git] / src / plugins / cpptools / cppcodecompletion.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef CPPCODECOMPLETION_H
35 #define CPPCODECOMPLETION_H
36
37 #include <ASTfwd.h>
38 #include <FullySpecifiedType.h>
39 #include <cplusplus/Icons.h>
40 #include <cplusplus/Overview.h>
41 #include <cplusplus/TypeOfExpression.h>
42
43 #include <texteditor/icompletioncollector.h>
44 #include <texteditor/snippets/snippetcollector.h>
45
46 #include <QtCore/QObject>
47 #include <QtCore/QPointer>
48
49 QT_BEGIN_NAMESPACE
50 class QTextCursor;
51 QT_END_NAMESPACE
52
53 namespace TextEditor {
54 class ITextEditor;
55 class BaseTextEditorWidget;
56 }
57
58 namespace CPlusPlus {
59 class LookupItem;
60 class ClassOrNamespace;
61 }
62
63 namespace CppTools {
64 namespace Internal {
65
66 class CppModelManager;
67 class FunctionArgumentWidget;
68
69 class CppCodeCompletion : public TextEditor::ICompletionCollector
70 {
71     Q_OBJECT
72 public:
73     explicit CppCodeCompletion(CppModelManager *manager);
74
75     void setObjcEnabled(bool objcEnabled)
76     { m_objcEnabled = objcEnabled; }
77
78     TextEditor::ITextEditor *editor() const;
79     int startPosition() const;
80     bool shouldRestartCompletion();
81     QList<TextEditor::CompletionItem> getCompletions();
82     bool supportsEditor(TextEditor::ITextEditor *editor) const;
83     bool supportsPolicy(TextEditor::CompletionPolicy policy) const;
84     bool triggersCompletion(TextEditor::ITextEditor *editor);
85     int startCompletion(TextEditor::ITextEditor *editor);
86     void completions(QList<TextEditor::CompletionItem> *completions);
87
88     bool typedCharCompletes(const TextEditor::CompletionItem &item, QChar typedChar);
89     void complete(const TextEditor::CompletionItem &item, QChar typedChar);
90     bool partiallyComplete(const QList<TextEditor::CompletionItem> &completionItems);
91     void cleanup();
92
93     QIcon iconForSymbol(CPlusPlus::Symbol *symbol) const;
94
95 private:
96     void addSnippets();
97     void addKeywords();
98     void addMacros(const QString &fileName, const CPlusPlus::Snapshot &snapshot);
99     void addMacros_helper(const CPlusPlus::Snapshot &snapshot,
100                           const QString &fileName,
101                           QSet<QString> *processed,
102                           QSet<QString> *definedMacros);
103     void addCompletionItem(CPlusPlus::Symbol *symbol);
104
105     bool completeInclude(const QTextCursor &cursor);
106     void completePreprocessor();
107
108     void globalCompletion(CPlusPlus::Scope *scope);
109
110     bool completeConstructorOrFunction(const QList<CPlusPlus::LookupItem> &results,
111                                        int endOfExpression, bool toolTipOnly);
112
113     bool completeMember(const QList<CPlusPlus::LookupItem> &results);
114     bool completeScope(const QList<CPlusPlus::LookupItem> &results);
115
116     void completeNamespace(CPlusPlus::ClassOrNamespace *binding);
117
118     void completeClass(CPlusPlus::ClassOrNamespace *b,
119                        bool staticLookup = true);
120
121     bool completeConstructors(CPlusPlus::Class *klass);
122
123     bool completeQtMethod(const QList<CPlusPlus::LookupItem> &results,
124                           bool wantSignals);
125
126     bool completeSignal(const QList<CPlusPlus::LookupItem> &results)
127     { return completeQtMethod(results, true); }
128
129     bool completeSlot(const QList<CPlusPlus::LookupItem> &results)
130     { return completeQtMethod(results, false); }
131
132     int findStartOfName(int pos = -1) const;
133
134     int startCompletionHelper(TextEditor::ITextEditor *editor);
135
136     int startCompletionInternal(TextEditor::BaseTextEditorWidget *edit,
137                                 const QString fileName,
138                                 unsigned line, unsigned column,
139                                 const QString &expression,
140                                 int endOfExpression);
141
142     QList<TextEditor::CompletionItem> removeDuplicates(const QList<TextEditor::CompletionItem> &items);
143
144 private:
145     void completeObjCMsgSend(CPlusPlus::ClassOrNamespace *binding,
146                              bool staticClassAccess);
147     bool tryObjCCompletion(TextEditor::BaseTextEditorWidget *edit);
148     bool objcKeywordsWanted() const;
149
150     static QStringList preprocessorCompletions;
151
152     CppModelManager *m_manager;
153     TextEditor::ITextEditor *m_editor;
154     int m_startPosition;     // Position of the cursor from which completion started
155     bool m_shouldRestartCompletion;
156
157     bool m_automaticCompletion;
158     unsigned m_completionOperator;
159     bool m_objcEnabled;
160
161     TextEditor::SnippetCollector m_snippetProvider;
162
163     CPlusPlus::Icons m_icons;
164     CPlusPlus::Overview overview;
165     CPlusPlus::TypeOfExpression typeOfExpression;
166     QPointer<FunctionArgumentWidget> m_functionArgumentWidget;
167
168     QList<TextEditor::CompletionItem> m_completions;
169 };
170
171 } // namespace Internal
172 } // namespace CppTools
173
174 Q_DECLARE_METATYPE(CPlusPlus::Symbol *)
175
176 #endif // CPPCODECOMPLETION_H