cppeditorplugin.h 10.9 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);
con's avatar
con committed
93

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

100 101 102
    void test_FollowSymbolUnderCursor_multipleDocuments_data();
    void test_FollowSymbolUnderCursor_multipleDocuments();

Orgad Shaneh's avatar
Orgad Shaneh committed
103 104 105
    void test_FollowSymbolUnderCursor_data();
    void test_FollowSymbolUnderCursor();

Joerg Bornemann's avatar
Joerg Bornemann committed
106 107
    void test_FollowSymbolUnderCursor_QObject_connect_data();
    void test_FollowSymbolUnderCursor_QObject_connect();
Orgad Shaneh's avatar
Orgad Shaneh committed
108

109 110
    void test_FollowSymbolUnderCursor_classOperator_onOperatorToken_data();
    void test_FollowSymbolUnderCursor_classOperator_onOperatorToken();
Orgad Shaneh's avatar
Orgad Shaneh committed
111

112 113
    void test_FollowSymbolUnderCursor_classOperator_data();
    void test_FollowSymbolUnderCursor_classOperator();
Orgad Shaneh's avatar
Orgad Shaneh committed
114

115 116
    void test_FollowSymbolUnderCursor_classOperator_inOp_data();
    void test_FollowSymbolUnderCursor_classOperator_inOp();
Orgad Shaneh's avatar
Orgad Shaneh committed
117

118 119 120
    void test_FollowSymbolUnderCursor_virtualFunctionCall_data();
    void test_FollowSymbolUnderCursor_virtualFunctionCall();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_multipleDocuments();
121

122 123
    void test_doxygen_comments_data();
    void test_doxygen_comments();
124

125 126
    void test_quickfix_data();
    void test_quickfix();
127

128
    void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespaceToCpp();
129

130
    void test_quickfix_InsertDefFromDecl_afterClass();
131 132
    void test_quickfix_InsertDefFromDecl_headerSource_basic1();
    void test_quickfix_InsertDefFromDecl_headerSource_basic2();
133
    void test_quickfix_InsertDefFromDecl_headerSource_basic3();
134 135
    void test_quickfix_InsertDefFromDecl_headerSource_namespace1();
    void test_quickfix_InsertDefFromDecl_headerSource_namespace2();
136
    void test_quickfix_InsertDefFromDecl_insideClass();
137
    void test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists();
138
    void test_quickfix_InsertDefFromDecl_findRightImplementationFile();
139
    void test_quickfix_InsertDefFromDecl_ignoreSurroundingGeneratedDeclarations();
140 141
    void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames1();
    void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames2();
142 143 144
    void test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile1();
    void test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile2();
    void test_quickfix_InsertDefFromDecl_erroneousStatementAtEndOfFile();
145

146 147
    void test_quickfix_InsertDeclFromDef();

148 149 150
    void test_quickfix_AddIncludeForUndefinedIdentifier_detectIncludeGroupsByNewLines();
    void test_quickfix_AddIncludeForUndefinedIdentifier_detectIncludeGroupsByIncludeDir();
    void test_quickfix_AddIncludeForUndefinedIdentifier_detectIncludeGroupsByIncludeType();
151
    void test_quickfix_AddIncludeForUndefinedIdentifier_normal();
152 153 154 155
    void test_quickfix_AddIncludeForUndefinedIdentifier_ignoremoc();
    void test_quickfix_AddIncludeForUndefinedIdentifier_sortingTop();
    void test_quickfix_AddIncludeForUndefinedIdentifier_sortingMiddle();
    void test_quickfix_AddIncludeForUndefinedIdentifier_sortingBottom();
156 157 158 159 160 161 162 163 164 165 166
    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();
167
    void test_quickfix_AddIncludeForUndefinedIdentifier_noinclude();
168 169
    void test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIncludeCppStyleCommentOnTop();
    void test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIncludeCStyleCommentOnTop();
170
    void test_quickfix_AddIncludeForUndefinedIdentifier_checkQSomethingInQtIncludePaths();
171

172
    void test_quickfix_MoveFuncDefOutside_MemberFuncToCpp();
173
    void test_quickfix_MoveFuncDefOutside_MemberFuncToCppInsideNS();
174 175
    void test_quickfix_MoveFuncDefOutside_MemberFuncOutside1();
    void test_quickfix_MoveFuncDefOutside_MemberFuncOutside2();
176 177 178 179 180
    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();
181 182
    void test_quickfix_MoveFuncDefOutside_CtorWithInitialization1();
    void test_quickfix_MoveFuncDefOutside_CtorWithInitialization2();
183
    void test_quickfix_MoveFuncDefOutside_afterClass();
184 185
    void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames1();
    void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2();
186 187 188 189 190 191 192 193

    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();
194
    void test_quickfix_MoveFuncDefToDecl_CtorWithInitialization();
195
    void test_quickfix_MoveFuncDefToDecl_structWithAssignedVariable();
196

197
    void test_quickfix_AssignToLocalVariable_templates();
198

199 200 201 202 203
    void test_quickfix_ExtractLiteralAsParameter_typeDeduction_data();
    void test_quickfix_ExtractLiteralAsParameter_typeDeduction();
    void test_quickfix_ExtractLiteralAsParameter_freeFunction_separateFiles();
    void test_quickfix_ExtractLiteralAsParameter_memberFunction_separateFiles();

204 205
    void test_quickfix_InsertVirtualMethods_data();
    void test_quickfix_InsertVirtualMethods();
206
    void test_quickfix_InsertVirtualMethods_implementationFile();
207
    void test_quickfix_InsertVirtualMethods_BaseClassInNamespace();
208

209 210 211 212 213
    // tests for "Include Hiererchy"
    void test_includeHierarchyModel_simpleIncludes();
    void test_includeHierarchyModel_simpleIncludedBy();
    void test_includeHierarchyModel_simpleIncludesAndIncludedBy();

214 215 216 217 218 219 220 221 222 223 224 225
    // 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();
226 227
#endif // WITH_TESTS

con's avatar
con committed
228 229
private:
    Core::IEditor *createEditor(QWidget *parent);
230 231
    void writeSettings();
    void readSettings();
con's avatar
con committed
232

233
    static CppEditorPlugin *m_instance;
con's avatar
con committed
234

235
    TextEditor::TextEditorActionHandler *m_actionHandler;
Kai Koehne's avatar
Kai Koehne committed
236
    bool m_sortedOutline;
237 238
    QAction *m_renameSymbolUnderCursorAction;
    QAction *m_findUsagesAction;
239
    QAction *m_reparseExternallyChangedFiles;
240
    QAction *m_openTypeHierarchyAction;
241
    QAction *m_openIncludeHierarchyAction;
242

Leandro Melo's avatar
Leandro Melo committed
243
    CppQuickFixAssistProvider *m_quickFixProvider;
244

245
    QPointer<TextEditor::ITextEditor> m_currentEditor;
con's avatar
con committed
246 247
};

248
class CppEditorFactory : public Core::IEditorFactory
con's avatar
con committed
249 250 251 252
{
    Q_OBJECT

public:
253
    CppEditorFactory(CppEditorPlugin *owner);
con's avatar
con committed
254 255 256 257

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

private:
258
    CppEditorPlugin *m_owner;
con's avatar
con committed
259 260 261 262 263
};

} // namespace Internal
} // namespace CppEditor

264
#endif // CPPEDITORPLUGIN_H