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 CPPCODECOMPLETION_H
35 #define CPPCODECOMPLETION_H
38 #include <FullySpecifiedType.h>
39 #include <cplusplus/Icons.h>
40 #include <cplusplus/Overview.h>
41 #include <cplusplus/TypeOfExpression.h>
43 #include <texteditor/icompletioncollector.h>
44 #include <texteditor/snippets/snippetcollector.h>
46 #include <QtCore/QObject>
47 #include <QtCore/QPointer>
53 namespace TextEditor {
55 class BaseTextEditorWidget;
60 class ClassOrNamespace;
66 class CppModelManager;
67 class FunctionArgumentWidget;
69 class CppCodeCompletion : public TextEditor::ICompletionCollector
73 explicit CppCodeCompletion(CppModelManager *manager);
75 void setObjcEnabled(bool objcEnabled)
76 { m_objcEnabled = objcEnabled; }
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);
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);
93 QIcon iconForSymbol(CPlusPlus::Symbol *symbol) const;
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);
105 bool completeInclude(const QTextCursor &cursor);
106 void completePreprocessor();
108 void globalCompletion(CPlusPlus::Scope *scope);
110 bool completeConstructorOrFunction(const QList<CPlusPlus::LookupItem> &results,
111 int endOfExpression, bool toolTipOnly);
113 bool completeMember(const QList<CPlusPlus::LookupItem> &results);
114 bool completeScope(const QList<CPlusPlus::LookupItem> &results);
116 void completeNamespace(CPlusPlus::ClassOrNamespace *binding);
118 void completeClass(CPlusPlus::ClassOrNamespace *b,
119 bool staticLookup = true);
121 bool completeConstructors(CPlusPlus::Class *klass);
123 bool completeQtMethod(const QList<CPlusPlus::LookupItem> &results,
126 bool completeSignal(const QList<CPlusPlus::LookupItem> &results)
127 { return completeQtMethod(results, true); }
129 bool completeSlot(const QList<CPlusPlus::LookupItem> &results)
130 { return completeQtMethod(results, false); }
132 int findStartOfName(int pos = -1) const;
134 int startCompletionHelper(TextEditor::ITextEditor *editor);
136 int startCompletionInternal(TextEditor::BaseTextEditorWidget *edit,
137 const QString fileName,
138 unsigned line, unsigned column,
139 const QString &expression,
140 int endOfExpression);
142 QList<TextEditor::CompletionItem> removeDuplicates(const QList<TextEditor::CompletionItem> &items);
145 void completeObjCMsgSend(CPlusPlus::ClassOrNamespace *binding,
146 bool staticClassAccess);
147 bool tryObjCCompletion(TextEditor::BaseTextEditorWidget *edit);
148 bool objcKeywordsWanted() const;
150 static QStringList preprocessorCompletions;
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;
157 bool m_automaticCompletion;
158 unsigned m_completionOperator;
161 TextEditor::SnippetCollector m_snippetProvider;
163 CPlusPlus::Icons m_icons;
164 CPlusPlus::Overview overview;
165 CPlusPlus::TypeOfExpression typeOfExpression;
166 QPointer<FunctionArgumentWidget> m_functionArgumentWidget;
168 QList<TextEditor::CompletionItem> m_completions;
171 } // namespace Internal
172 } // namespace CppTools
174 Q_DECLARE_METATYPE(CPlusPlus::Symbol *)
176 #endif // CPPCODECOMPLETION_H