cppeditorplugin.h 14.2 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
39
#include <QtPlugin>
#include <QStringList>
#include <QAction>
40

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

namespace CppEditor {
namespace Internal {

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

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

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

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

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

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

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

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

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

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

Kai Koehne's avatar
Kai Koehne committed
86
    void setSortedOutline(bool sorted);
87

con's avatar
con committed
88
private slots:
89
90
    void onTaskStarted(const QString &type);
    void onAllTasksFinished(const QString &type);
91
    void currentEditorChanged(Core::IEditor *editor);
con's avatar
con committed
92

93
#ifdef WITH_TESTS
94
private slots:
95
    // The following tests expect that no projects are loaded on start-up.
96
97
98
    void test_SwitchMethodDeclarationDefinition_fromFunctionDeclarationSymbol();
    void test_SwitchMethodDeclarationDefinition_fromFunctionDefinitionSymbol();
    void test_SwitchMethodDeclarationDefinition_fromFunctionBody();
99
    void test_SwitchMethodDeclarationDefinition_fromReturnType();
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
    void test_FollowSymbolUnderCursor_globalVarFromFunction();
    void test_FollowSymbolUnderCursor_funLocalVarHidesClassMember();
    void test_FollowSymbolUnderCursor_funLocalVarHidesNamespaceMemberIntroducedByUsingDirective();
    void test_FollowSymbolUnderCursor_loopLocalVarHidesOuterScopeVariable1();
    void test_FollowSymbolUnderCursor_loopLocalVarHidesOuterScopeVariable2();
    void test_FollowSymbolUnderCursor_subsequentDefinedClassMember();
    void test_FollowSymbolUnderCursor_classMemberHidesOuterTypeDef();
    void test_FollowSymbolUnderCursor_globalVarFromEnum();
    void test_FollowSymbolUnderCursor_selfInitialization();
    void test_FollowSymbolUnderCursor_pointerToClassInClassDefinition();
    void test_FollowSymbolUnderCursor_previouslyDefinedMemberFromArrayDefinition();
    void test_FollowSymbolUnderCursor_outerStaticMemberVariableFromInsideSubclass();
    void test_FollowSymbolUnderCursor_memberVariableFollowingDotOperator();
    void test_FollowSymbolUnderCursor_memberVariableFollowingArrowOperator();
    void test_FollowSymbolUnderCursor_staticMemberVariableFollowingScopeOperator();
    void test_FollowSymbolUnderCursor_staticMemberVariableFollowingDotOperator();
    void test_FollowSymbolUnderCursor_staticMemberVariableFollowingArrowOperator();
    void test_FollowSymbolUnderCursor_previouslyDefinedEnumValueFromInsideEnum();
    void test_FollowSymbolUnderCursor_nsMemberHidesNsMemberIntroducedByUsingDirective();
    void test_FollowSymbolUnderCursor_baseClassFunctionIntroducedByUsingDeclaration();
    void test_FollowSymbolUnderCursor_funWithSameNameAsBaseClassFunIntroducedByUsingDeclaration();
    void test_FollowSymbolUnderCursor_funLocalVarHidesOuterClass();
123
124
125
    void test_FollowSymbolUnderCursor_using_QTCREATORBUG7903_globalNamespace();
    void test_FollowSymbolUnderCursor_using_QTCREATORBUG7903_namespace();
    void test_FollowSymbolUnderCursor_using_QTCREATORBUG7903_insideFunction();
126

127
128
129
130
    void test_doxygen_comments_qt_style();
    void test_doxygen_comments_qt_style_continuation();
    void test_doxygen_comments_java_style();
    void test_doxygen_comments_java_style_continuation();
131
132
133
134
135
136
    void test_doxygen_comments_cpp_styleA();
    void test_doxygen_comments_cpp_styleB();
    void test_doxygen_comments_cpp_styleA_indented();
    void test_doxygen_comments_cpp_styleA_continuation();
    void test_doxygen_comments_cpp_styleA_indented_continuation();
    void test_doxygen_comments_cpp_styleA_corner_case();
137

Nikolai Kosjar's avatar
Nikolai Kosjar committed
138
    void test_quickfix_GenerateGetterSetter_basicGetterWithPrefix();
139
140
    void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespace();
    void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespaceToCpp();
Nikolai Kosjar's avatar
Nikolai Kosjar committed
141
142
143
144
145
146
147
148
149
150
151
    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();
152

153
    void test_quickfix_ReformatPointerDeclaration();
154
155

    void test_quickfix_InsertDefFromDecl_basic();
156
    void test_quickfix_InsertDefFromDecl_afterClass();
157
158
159
160
    void test_quickfix_InsertDefFromDecl_headerSource_basic1();
    void test_quickfix_InsertDefFromDecl_headerSource_basic2();
    void test_quickfix_InsertDefFromDecl_headerSource_namespace1();
    void test_quickfix_InsertDefFromDecl_headerSource_namespace2();
161
    void test_quickfix_InsertDefFromDecl_freeFunction();
162
    void test_quickfix_InsertDefFromDecl_insideClass();
163
    void test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists();
164
    void test_quickfix_InsertDefFromDecl_notTriggeringStatement();
165
    void test_quickfix_InsertDefFromDecl_findRightImplementationFile();
166
167
    void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames1();
    void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames2();
168

169
170
    void test_quickfix_InsertDeclFromDef();

171
172
173
    void test_quickfix_AddIncludeForUndefinedIdentifier_detectIncludeGroupsByNewLines();
    void test_quickfix_AddIncludeForUndefinedIdentifier_detectIncludeGroupsByIncludeDir();
    void test_quickfix_AddIncludeForUndefinedIdentifier_detectIncludeGroupsByIncludeType();
174
    void test_quickfix_AddIncludeForUndefinedIdentifier_normal();
175
176
177
178
    void test_quickfix_AddIncludeForUndefinedIdentifier_ignoremoc();
    void test_quickfix_AddIncludeForUndefinedIdentifier_sortingTop();
    void test_quickfix_AddIncludeForUndefinedIdentifier_sortingMiddle();
    void test_quickfix_AddIncludeForUndefinedIdentifier_sortingBottom();
179
180
181
182
183
184
185
186
187
188
189
    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();
190
    void test_quickfix_AddIncludeForUndefinedIdentifier_noinclude();
191
192
    void test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIncludeCppStyleCommentOnTop();
    void test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIncludeCStyleCommentOnTop();
193
    void test_quickfix_AddIncludeForUndefinedIdentifier_checkQSomethingInQtIncludePaths();
194

195
    void test_quickfix_MoveFuncDefOutside_MemberFuncToCpp();
196
    void test_quickfix_MoveFuncDefOutside_MemberFuncToCppInsideNS();
197
198
    void test_quickfix_MoveFuncDefOutside_MemberFuncOutside1();
    void test_quickfix_MoveFuncDefOutside_MemberFuncOutside2();
199
200
201
202
203
    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();
204
205
    void test_quickfix_MoveFuncDefOutside_CtorWithInitialization1();
    void test_quickfix_MoveFuncDefOutside_CtorWithInitialization2();
206
    void test_quickfix_MoveFuncDefOutside_afterClass();
207
208
    void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames1();
    void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2();
209
210
211
212
213
214
215
216

    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();
217
    void test_quickfix_MoveFuncDefToDecl_CtorWithInitialization();
218

219
220
221
222
    void test_quickfix_AssignToLocalVariable_freeFunction();
    void test_quickfix_AssignToLocalVariable_memberFunction();
    void test_quickfix_AssignToLocalVariable_staticMemberFunction();
    void test_quickfix_AssignToLocalVariable_newExpression();
223
    void test_quickfix_AssignToLocalVariable_templates();
224
225
226
227
228
    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();
229
    void test_quickfix_AssignToLocalVariable_noFunctionInFunction();
230
231
232
233
    void test_quickfix_AssignToLocalVariable_noReturnClass1();
    void test_quickfix_AssignToLocalVariable_noReturnClass2();
    void test_quickfix_AssignToLocalVariable_noReturnFunc1();
    void test_quickfix_AssignToLocalVariable_noReturnFunc2();
234
    void test_quickfix_AssignToLocalVariable_noSignatureMatch();
235

236
237
238
239
240
241
242
243
244
245
246
    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();
247
    void test_quickfix_InsertVirtualMethods_BaseClassInNamespace();
248

249
250
251
252
253
254
255
256
257
258
259
260
    // 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();
261
262
#endif // WITH_TESTS

con's avatar
con committed
263
264
private:
    Core::IEditor *createEditor(QWidget *parent);
265
266
    void writeSettings();
    void readSettings();
con's avatar
con committed
267

268
    static CppEditorPlugin *m_instance;
con's avatar
con committed
269

270
    TextEditor::TextEditorActionHandler *m_actionHandler;
Kai Koehne's avatar
Kai Koehne committed
271
    bool m_sortedOutline;
272
273
    QAction *m_renameSymbolUnderCursorAction;
    QAction *m_findUsagesAction;
274
    QAction *m_updateCodeModelAction;
275
    QAction *m_openTypeHierarchyAction;
276

Leandro Melo's avatar
Leandro Melo committed
277
    CppQuickFixAssistProvider *m_quickFixProvider;
278

279
    QPointer<TextEditor::ITextEditor> m_currentEditor;
con's avatar
con committed
280
281
};

282
class CppEditorFactory : public Core::IEditorFactory
con's avatar
con committed
283
284
285
286
{
    Q_OBJECT

public:
287
    CppEditorFactory(CppEditorPlugin *owner);
con's avatar
con committed
288

hjk's avatar
hjk committed
289
290
    // IEditorFactory
    QStringList mimeTypes() const;
con's avatar
con committed
291
    Core::IEditor *createEditor(QWidget *parent);
hjk's avatar
hjk committed
292
293
    Core::Id id() const;
    QString displayName() const;
con's avatar
con committed
294
295

private:
296
    CppEditorPlugin *m_owner;
con's avatar
con committed
297
298
299
300
301
302
    QStringList m_mimeTypes;
};

} // namespace Internal
} // namespace CppEditor

303
#endif // CPPEDITORPLUGIN_H