cppeditorplugin.h 14.5 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

30
31
#ifndef CPPEDITORPLUGIN_H
#define CPPEDITORPLUGIN_H
con's avatar
con committed
32
33
34

#include <coreplugin/editormanager/ieditorfactory.h>

35
36
#include <extensionsystem/iplugin.h>

37
38
#include <QtPlugin>
#include <QAction>
39

con's avatar
con committed
40
41
namespace TextEditor {
class TextEditorActionHandler;
42
class ITextEditor;
con's avatar
con committed
43
44
45
46
47
} // namespace TextEditor

namespace CppEditor {
namespace Internal {

48
class CPPEditorWidget;
49
class CppQuickFixCollector;
Leandro Melo's avatar
Leandro Melo committed
50
class CppQuickFixAssistProvider;
con's avatar
con committed
51

52
class CppEditorPlugin : public ExtensionSystem::IPlugin
con's avatar
con committed
53
54
{
    Q_OBJECT
55
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CppEditor.json")
con's avatar
con committed
56
57

public:
58
59
    CppEditorPlugin();
    ~CppEditorPlugin();
con's avatar
con committed
60

61
    static CppEditorPlugin *instance();
con's avatar
con committed
62

hjk's avatar
hjk committed
63
    bool initialize(const QStringList &arguments, QString *errorMessage = 0);
con's avatar
con committed
64
    void extensionsInitialized();
65
    ShutdownFlag aboutToShutdown();
con's avatar
con committed
66
67

    // Connect editor to settings changed signals.
68
    void initializeEditor(CPPEditorWidget *editor);
con's avatar
con committed
69

Kai Koehne's avatar
Kai Koehne committed
70
    bool sortedOutline() const;
71

Leandro Melo's avatar
Leandro Melo committed
72
    CppQuickFixAssistProvider *quickFixProvider() const;
73

74
signals:
Kai Koehne's avatar
Kai Koehne committed
75
    void outlineSortingChanged(bool sort);
76
    void typeHierarchyRequested();
77
    void includeHierarchyRequested();
78
79

public slots:
80
81
    void openDeclarationDefinitionInNextSplit();
    void openTypeHierarchy();
82
    void openIncludeHierarchy();
83
    void findUsages();
84
    void showPreProcessorDialog();
85
86
87
    void renameSymbolUnderCursor();
    void switchDeclarationDefinition();

Kai Koehne's avatar
Kai Koehne committed
88
    void setSortedOutline(bool sorted);
89

con's avatar
con committed
90
private slots:
91
92
    void onTaskStarted(Core::Id type);
    void onAllTasksFinished(Core::Id type);
93
    void currentEditorChanged(Core::IEditor *editor);
con's avatar
con committed
94

95
#ifdef WITH_TESTS
96
private slots:
97
    // The following tests expect that no projects are loaded on start-up.
Orgad Shaneh's avatar
Orgad Shaneh committed
98
99
100
101
102
103
    void test_SwitchMethodDeclarationDefinition_data();
    void test_SwitchMethodDeclarationDefinition();

    void test_FollowSymbolUnderCursor_data();
    void test_FollowSymbolUnderCursor();

Joerg Bornemann's avatar
Joerg Bornemann committed
104
105
    void test_FollowSymbolUnderCursor_QObject_connect_data();
    void test_FollowSymbolUnderCursor_QObject_connect();
Orgad Shaneh's avatar
Orgad Shaneh committed
106

107
108
    void test_FollowSymbolUnderCursor_classOperator_onOperatorToken_data();
    void test_FollowSymbolUnderCursor_classOperator_onOperatorToken();
Orgad Shaneh's avatar
Orgad Shaneh committed
109

110
111
    void test_FollowSymbolUnderCursor_classOperator_data();
    void test_FollowSymbolUnderCursor_classOperator();
Orgad Shaneh's avatar
Orgad Shaneh committed
112

113
114
    void test_FollowSymbolUnderCursor_classOperator_inOp_data();
    void test_FollowSymbolUnderCursor_classOperator_inOp();
Orgad Shaneh's avatar
Orgad Shaneh committed
115

116
117
118
    void test_FollowSymbolUnderCursor_virtualFunctionCall_data();
    void test_FollowSymbolUnderCursor_virtualFunctionCall();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_multipleDocuments();
119

120
121
    void test_doxygen_comments_data();
    void test_doxygen_comments();
122

123
124
125
    void test_quickfix_CompleteSwitchCaseStatement_basic1();
    void test_quickfix_CompleteSwitchCaseStatement_basic2();
    void test_quickfix_CompleteSwitchCaseStatement_oneValueMissing();
126
127
    void test_quickfix_CompleteSwitchCaseStatement_QTCREATORBUG10366_1();
    void test_quickfix_CompleteSwitchCaseStatement_QTCREATORBUG10366_2();
128

Nikolai Kosjar's avatar
Nikolai Kosjar committed
129
    void test_quickfix_GenerateGetterSetter_basicGetterWithPrefix();
130
131
    void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespace();
    void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespaceToCpp();
Nikolai Kosjar's avatar
Nikolai Kosjar committed
132
133
134
135
136
137
138
139
140
141
142
    void test_quickfix_GenerateGetterSetter_basicGetterWithoutPrefix();
    void test_quickfix_GenerateGetterSetter_customType();
    void test_quickfix_GenerateGetterSetter_constMember();
    void test_quickfix_GenerateGetterSetter_pointerToNonConst();
    void test_quickfix_GenerateGetterSetter_pointerToConst();
    void test_quickfix_GenerateGetterSetter_staticMember();
    void test_quickfix_GenerateGetterSetter_secondDeclarator();
    void test_quickfix_GenerateGetterSetter_triggeringRightAfterPointerSign();
    void test_quickfix_GenerateGetterSetter_notTriggeringOnMemberFunction();
    void test_quickfix_GenerateGetterSetter_notTriggeringOnMemberArray();
    void test_quickfix_GenerateGetterSetter_notTriggeringWhenGetterOrSetterExist();
143

144
    void test_quickfix_ReformatPointerDeclaration();
145
146

    void test_quickfix_InsertDefFromDecl_basic();
147
    void test_quickfix_InsertDefFromDecl_afterClass();
148
149
    void test_quickfix_InsertDefFromDecl_headerSource_basic1();
    void test_quickfix_InsertDefFromDecl_headerSource_basic2();
150
    void test_quickfix_InsertDefFromDecl_headerSource_basic3();
151
152
    void test_quickfix_InsertDefFromDecl_headerSource_namespace1();
    void test_quickfix_InsertDefFromDecl_headerSource_namespace2();
153
    void test_quickfix_InsertDefFromDecl_freeFunction();
154
    void test_quickfix_InsertDefFromDecl_insideClass();
155
    void test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists();
156
    void test_quickfix_InsertDefFromDecl_notTriggeringStatement();
157
    void test_quickfix_InsertDefFromDecl_findRightImplementationFile();
158
    void test_quickfix_InsertDefFromDecl_ignoreSurroundingGeneratedDeclarations();
159
160
    void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames1();
    void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames2();
161
162
163
    void test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile1();
    void test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile2();
    void test_quickfix_InsertDefFromDecl_erroneousStatementAtEndOfFile();
164

165
166
    void test_quickfix_InsertDeclFromDef();

167
168
169
    void test_quickfix_AddIncludeForUndefinedIdentifier_detectIncludeGroupsByNewLines();
    void test_quickfix_AddIncludeForUndefinedIdentifier_detectIncludeGroupsByIncludeDir();
    void test_quickfix_AddIncludeForUndefinedIdentifier_detectIncludeGroupsByIncludeType();
170
    void test_quickfix_AddIncludeForUndefinedIdentifier_normal();
171
172
173
174
    void test_quickfix_AddIncludeForUndefinedIdentifier_ignoremoc();
    void test_quickfix_AddIncludeForUndefinedIdentifier_sortingTop();
    void test_quickfix_AddIncludeForUndefinedIdentifier_sortingMiddle();
    void test_quickfix_AddIncludeForUndefinedIdentifier_sortingBottom();
175
176
177
178
179
180
181
182
183
184
185
    void test_quickfix_AddIncludeForUndefinedIdentifier_appendToUnsorted();
    void test_quickfix_AddIncludeForUndefinedIdentifier_firstLocalIncludeAtFront();
    void test_quickfix_AddIncludeForUndefinedIdentifier_firstGlobalIncludeAtBack();
    void test_quickfix_AddIncludeForUndefinedIdentifier_preferGroupWithLongerMatchingPrefix();
    void test_quickfix_AddIncludeForUndefinedIdentifier_newGroupIfOnlyDifferentIncludeDirs();
    void test_quickfix_AddIncludeForUndefinedIdentifier_mixedDirsSorted();
    void test_quickfix_AddIncludeForUndefinedIdentifier_mixedDirsUnsorted();
    void test_quickfix_AddIncludeForUndefinedIdentifier_mixedIncludeTypes1();
    void test_quickfix_AddIncludeForUndefinedIdentifier_mixedIncludeTypes2();
    void test_quickfix_AddIncludeForUndefinedIdentifier_mixedIncludeTypes3();
    void test_quickfix_AddIncludeForUndefinedIdentifier_mixedIncludeTypes4();
186
    void test_quickfix_AddIncludeForUndefinedIdentifier_noinclude();
187
188
    void test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIncludeCppStyleCommentOnTop();
    void test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIncludeCStyleCommentOnTop();
189
    void test_quickfix_AddIncludeForUndefinedIdentifier_checkQSomethingInQtIncludePaths();
190

191
    void test_quickfix_MoveFuncDefOutside_MemberFuncToCpp();
192
    void test_quickfix_MoveFuncDefOutside_MemberFuncToCppInsideNS();
193
194
    void test_quickfix_MoveFuncDefOutside_MemberFuncOutside1();
    void test_quickfix_MoveFuncDefOutside_MemberFuncOutside2();
195
196
197
198
199
    void test_quickfix_MoveFuncDefOutside_MemberFuncToCppNS();
    void test_quickfix_MoveFuncDefOutside_MemberFuncToCppNSUsing();
    void test_quickfix_MoveFuncDefOutside_MemberFuncOutsideWithNs();
    void test_quickfix_MoveFuncDefOutside_FreeFuncToCpp();
    void test_quickfix_MoveFuncDefOutside_FreeFuncToCppNS();
200
201
    void test_quickfix_MoveFuncDefOutside_CtorWithInitialization1();
    void test_quickfix_MoveFuncDefOutside_CtorWithInitialization2();
202
    void test_quickfix_MoveFuncDefOutside_afterClass();
203
204
    void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames1();
    void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2();
205
206
207
208
209
210
211
212

    void test_quickfix_MoveFuncDefToDecl_MemberFunc();
    void test_quickfix_MoveFuncDefToDecl_MemberFuncOutside();
    void test_quickfix_MoveFuncDefToDecl_MemberFuncToCppNS();
    void test_quickfix_MoveFuncDefToDecl_MemberFuncToCppNSUsing();
    void test_quickfix_MoveFuncDefToDecl_MemberFuncOutsideWithNs();
    void test_quickfix_MoveFuncDefToDecl_FreeFuncToCpp();
    void test_quickfix_MoveFuncDefToDecl_FreeFuncToCppNS();
213
    void test_quickfix_MoveFuncDefToDecl_CtorWithInitialization();
214
    void test_quickfix_MoveFuncDefToDecl_structWithAssignedVariable();
215

216
217
218
219
    void test_quickfix_AssignToLocalVariable_freeFunction();
    void test_quickfix_AssignToLocalVariable_memberFunction();
    void test_quickfix_AssignToLocalVariable_staticMemberFunction();
    void test_quickfix_AssignToLocalVariable_newExpression();
220
    void test_quickfix_AssignToLocalVariable_templates();
221
222
223
224
225
    void test_quickfix_AssignToLocalVariable_noInitializationList();
    void test_quickfix_AssignToLocalVariable_noVoidFunction();
    void test_quickfix_AssignToLocalVariable_noVoidMemberFunction();
    void test_quickfix_AssignToLocalVariable_noVoidStaticMemberFunction();
    void test_quickfix_AssignToLocalVariable_noFunctionInExpression();
226
    void test_quickfix_AssignToLocalVariable_noFunctionInFunction();
227
228
229
230
    void test_quickfix_AssignToLocalVariable_noReturnClass1();
    void test_quickfix_AssignToLocalVariable_noReturnClass2();
    void test_quickfix_AssignToLocalVariable_noReturnFunc1();
    void test_quickfix_AssignToLocalVariable_noReturnFunc2();
231
    void test_quickfix_AssignToLocalVariable_noSignatureMatch();
232

233
234
235
236
237
238
239
240
    void test_quickfix_ExtractLiteralAsParameter_typeDeduction_data();
    void test_quickfix_ExtractLiteralAsParameter_typeDeduction();
    void test_quickfix_ExtractLiteralAsParameter_freeFunction();
    void test_quickfix_ExtractLiteralAsParameter_freeFunction_separateFiles();
    void test_quickfix_ExtractLiteralAsParameter_memberFunction();
    void test_quickfix_ExtractLiteralAsParameter_memberFunction_separateFiles();
    void test_quickfix_ExtractLiteralAsParameter_memberFunctionInline();

241
242
243
244
245
246
247
248
249
250
251
    void test_quickfix_InsertVirtualMethods_onlyDecl();
    void test_quickfix_InsertVirtualMethods_onlyDeclWithoutVirtual();
    void test_quickfix_InsertVirtualMethods_Access();
    void test_quickfix_InsertVirtualMethods_Superclass();
    void test_quickfix_InsertVirtualMethods_SuperclassOverride();
    void test_quickfix_InsertVirtualMethods_PureVirtualOnlyDecl();
    void test_quickfix_InsertVirtualMethods_PureVirtualInside();
    void test_quickfix_InsertVirtualMethods_inside();
    void test_quickfix_InsertVirtualMethods_outside();
    void test_quickfix_InsertVirtualMethods_implementationFile();
    void test_quickfix_InsertVirtualMethods_notrigger_allImplemented();
252
    void test_quickfix_InsertVirtualMethods_BaseClassInNamespace();
253

254
255
256
257
258
259
260
261
262
263
    void test_quickfix_OptimizeForLoop_postcrement();
    void test_quickfix_OptimizeForLoop_condition();
    void test_quickfix_OptimizeForLoop_flipedCondition();
    void test_quickfix_OptimizeForLoop_alterVariableName();
    void test_quickfix_OptimizeForLoop_optimizeBoth();
    void test_quickfix_OptimizeForLoop_emptyInitializer();
    void test_quickfix_OptimizeForLoop_wrongInitializer();
    void test_quickfix_OptimizeForLoop_noTriggerNumeric1();
    void test_quickfix_OptimizeForLoop_noTriggerNumeric2();

264
265
266
    void test_functionhelper_virtualFunctions();
    void test_functionhelper_virtualFunctions_data();

267
268
269
270
271
    // tests for "Include Hiererchy"
    void test_includeHierarchyModel_simpleIncludes();
    void test_includeHierarchyModel_simpleIncludedBy();
    void test_includeHierarchyModel_simpleIncludesAndIncludedBy();

272
273
274
275
276
277
278
279
280
281
282
283
    // The following tests depend on the projects that are loaded on startup
    // and will be skipped in case no projects are loaded.
    void test_openEachFile();
    void test_switchHeaderSourceOnEachFile();
    void test_moveTokenWiseThroughEveryFile();
    void test_moveTokenWiseThroughEveryFileAndFollowSymbol();
    void test_moveTokenWiseThroughEveryFileAndSwitchDeclarationDefinition();
    void test_moveTokenWiseThroughEveryFileAndFindUsages();
    void test_moveTokenWiseThroughEveryFileAndRenameUsages();
    void test_moveTokenWiseThroughEveryFileAndOpenTypeHierarchy();
    void test_moveTokenWiseThroughEveryFileAndInvokeCompletion();
    void test_moveTokenWiseThroughEveryFileAndTriggerQuickFixes();
284
285
#endif // WITH_TESTS

con's avatar
con committed
286
287
private:
    Core::IEditor *createEditor(QWidget *parent);
288
289
    void writeSettings();
    void readSettings();
con's avatar
con committed
290

291
    static CppEditorPlugin *m_instance;
con's avatar
con committed
292

293
    TextEditor::TextEditorActionHandler *m_actionHandler;
Kai Koehne's avatar
Kai Koehne committed
294
    bool m_sortedOutline;
295
296
    QAction *m_renameSymbolUnderCursorAction;
    QAction *m_findUsagesAction;
297
    QAction *m_reparseExternallyChangedFiles;
298
    QAction *m_openTypeHierarchyAction;
299
    QAction *m_openIncludeHierarchyAction;
300

Leandro Melo's avatar
Leandro Melo committed
301
    CppQuickFixAssistProvider *m_quickFixProvider;
302

303
    QPointer<TextEditor::ITextEditor> m_currentEditor;
con's avatar
con committed
304
305
};

306
class CppEditorFactory : public Core::IEditorFactory
con's avatar
con committed
307
308
309
310
{
    Q_OBJECT

public:
311
    CppEditorFactory(CppEditorPlugin *owner);
con's avatar
con committed
312
313
314
315

    Core::IEditor *createEditor(QWidget *parent);

private:
316
    CppEditorPlugin *m_owner;
con's avatar
con committed
317
318
319
320
321
};

} // namespace Internal
} // namespace CppEditor

322
#endif // CPPEDITORPLUGIN_H