cppeditorplugin.h 18.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
#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.
98 99 100
    void test_SwitchMethodDeclarationDefinition_fromFunctionDeclarationSymbol();
    void test_SwitchMethodDeclarationDefinition_fromFunctionDefinitionSymbol();
    void test_SwitchMethodDeclarationDefinition_fromFunctionBody();
101
    void test_SwitchMethodDeclarationDefinition_fromReturnType();
102

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    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();
125 126
    void test_FollowSymbolUnderCursor_classConstructor();
    void test_FollowSymbolUnderCursor_classDestructor();
Joerg Bornemann's avatar
Joerg Bornemann committed
127 128
    void test_FollowSymbolUnderCursor_QObject_connect_data();
    void test_FollowSymbolUnderCursor_QObject_connect();
129 130 131 132 133 134
    void test_FollowSymbolUnderCursor_classOperator_onOperatorToken_data();
    void test_FollowSymbolUnderCursor_classOperator_onOperatorToken();
    void test_FollowSymbolUnderCursor_classOperator_data();
    void test_FollowSymbolUnderCursor_classOperator();
    void test_FollowSymbolUnderCursor_classOperator_inOp_data();
    void test_FollowSymbolUnderCursor_classOperator_inOp();
135 136 137
    void test_FollowSymbolUnderCursor_using_QTCREATORBUG7903_globalNamespace();
    void test_FollowSymbolUnderCursor_using_QTCREATORBUG7903_namespace();
    void test_FollowSymbolUnderCursor_using_QTCREATORBUG7903_insideFunction();
138 139 140
    void test_FollowSymbolUnderCursor_virtualFunctionCall_allOverrides();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_possibleOverrides1();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_possibleOverrides2();
141 142
    void test_FollowSymbolUnderCursor_virtualFunctionCall_fallbackToDeclaration();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_itemOrder();
143
    void test_FollowSymbolUnderCursor_virtualFunctionCall_instantiatedSymbols();
144 145 146 147 148
    void test_FollowSymbolUnderCursor_virtualFunctionCall_QSharedPointer();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_multipeDocuments();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_noSiblings_references();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_noSiblings_pointers();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_noSiblings_noBaseExpression();
149 150
    void test_FollowSymbolUnderCursor_virtualFunctionCall_onDotMemberAccessOfReferenceTypes();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_notOnDotMemberAccessOfNonReferenceType();
151 152 153 154
    void test_FollowSymbolUnderCursor_virtualFunctionCall_notOnQualified();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_notOnDeclaration();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_notOnDefinition();
    void test_FollowSymbolUnderCursor_virtualFunctionCall_notOnNonPointerNonReference();
155

156 157 158 159
    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();
160 161 162 163 164 165
    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();
166

167 168 169
    void test_quickfix_CompleteSwitchCaseStatement_basic1();
    void test_quickfix_CompleteSwitchCaseStatement_basic2();
    void test_quickfix_CompleteSwitchCaseStatement_oneValueMissing();
170 171
    void test_quickfix_CompleteSwitchCaseStatement_QTCREATORBUG10366_1();
    void test_quickfix_CompleteSwitchCaseStatement_QTCREATORBUG10366_2();
172

Nikolai Kosjar's avatar
Nikolai Kosjar committed
173
    void test_quickfix_GenerateGetterSetter_basicGetterWithPrefix();
174 175
    void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespace();
    void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespaceToCpp();
Nikolai Kosjar's avatar
Nikolai Kosjar committed
176 177 178 179 180 181 182 183 184 185 186
    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();
187

188
    void test_quickfix_ReformatPointerDeclaration();
189 190

    void test_quickfix_InsertDefFromDecl_basic();
191
    void test_quickfix_InsertDefFromDecl_afterClass();
192 193
    void test_quickfix_InsertDefFromDecl_headerSource_basic1();
    void test_quickfix_InsertDefFromDecl_headerSource_basic2();
194
    void test_quickfix_InsertDefFromDecl_headerSource_basic3();
195 196
    void test_quickfix_InsertDefFromDecl_headerSource_namespace1();
    void test_quickfix_InsertDefFromDecl_headerSource_namespace2();
197
    void test_quickfix_InsertDefFromDecl_freeFunction();
198
    void test_quickfix_InsertDefFromDecl_insideClass();
199
    void test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists();
200
    void test_quickfix_InsertDefFromDecl_notTriggeringStatement();
201
    void test_quickfix_InsertDefFromDecl_findRightImplementationFile();
202
    void test_quickfix_InsertDefFromDecl_ignoreSurroundingGeneratedDeclarations();
203 204
    void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames1();
    void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames2();
205 206 207
    void test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile1();
    void test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile2();
    void test_quickfix_InsertDefFromDecl_erroneousStatementAtEndOfFile();
208

209 210
    void test_quickfix_InsertDeclFromDef();

211 212 213
    void test_quickfix_AddIncludeForUndefinedIdentifier_detectIncludeGroupsByNewLines();
    void test_quickfix_AddIncludeForUndefinedIdentifier_detectIncludeGroupsByIncludeDir();
    void test_quickfix_AddIncludeForUndefinedIdentifier_detectIncludeGroupsByIncludeType();
214
    void test_quickfix_AddIncludeForUndefinedIdentifier_normal();
215 216 217 218
    void test_quickfix_AddIncludeForUndefinedIdentifier_ignoremoc();
    void test_quickfix_AddIncludeForUndefinedIdentifier_sortingTop();
    void test_quickfix_AddIncludeForUndefinedIdentifier_sortingMiddle();
    void test_quickfix_AddIncludeForUndefinedIdentifier_sortingBottom();
219 220 221 222 223 224 225 226 227 228 229
    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();
230
    void test_quickfix_AddIncludeForUndefinedIdentifier_noinclude();
231 232
    void test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIncludeCppStyleCommentOnTop();
    void test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIncludeCStyleCommentOnTop();
233
    void test_quickfix_AddIncludeForUndefinedIdentifier_checkQSomethingInQtIncludePaths();
234

235
    void test_quickfix_MoveFuncDefOutside_MemberFuncToCpp();
236
    void test_quickfix_MoveFuncDefOutside_MemberFuncToCppInsideNS();
237 238
    void test_quickfix_MoveFuncDefOutside_MemberFuncOutside1();
    void test_quickfix_MoveFuncDefOutside_MemberFuncOutside2();
239 240 241 242 243
    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();
244 245
    void test_quickfix_MoveFuncDefOutside_CtorWithInitialization1();
    void test_quickfix_MoveFuncDefOutside_CtorWithInitialization2();
246
    void test_quickfix_MoveFuncDefOutside_afterClass();
247 248
    void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames1();
    void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2();
249 250 251 252 253 254 255 256

    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();
257
    void test_quickfix_MoveFuncDefToDecl_CtorWithInitialization();
258
    void test_quickfix_MoveFuncDefToDecl_structWithAssignedVariable();
259

260 261 262 263
    void test_quickfix_AssignToLocalVariable_freeFunction();
    void test_quickfix_AssignToLocalVariable_memberFunction();
    void test_quickfix_AssignToLocalVariable_staticMemberFunction();
    void test_quickfix_AssignToLocalVariable_newExpression();
264
    void test_quickfix_AssignToLocalVariable_templates();
265 266 267 268 269
    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();
270
    void test_quickfix_AssignToLocalVariable_noFunctionInFunction();
271 272 273 274
    void test_quickfix_AssignToLocalVariable_noReturnClass1();
    void test_quickfix_AssignToLocalVariable_noReturnClass2();
    void test_quickfix_AssignToLocalVariable_noReturnFunc1();
    void test_quickfix_AssignToLocalVariable_noReturnFunc2();
275
    void test_quickfix_AssignToLocalVariable_noSignatureMatch();
276

277 278 279 280 281 282 283 284
    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();

285 286 287 288 289 290 291 292 293 294 295
    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();
296
    void test_quickfix_InsertVirtualMethods_BaseClassInNamespace();
297

298 299 300 301 302 303 304 305 306 307
    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();

308 309 310
    void test_functionhelper_virtualFunctions();
    void test_functionhelper_virtualFunctions_data();

311 312 313 314 315
    // tests for "Include Hiererchy"
    void test_includeHierarchyModel_simpleIncludes();
    void test_includeHierarchyModel_simpleIncludedBy();
    void test_includeHierarchyModel_simpleIncludesAndIncludedBy();

316 317 318 319 320 321 322 323 324 325 326 327
    // 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();
328 329
#endif // WITH_TESTS

con's avatar
con committed
330 331
private:
    Core::IEditor *createEditor(QWidget *parent);
332 333
    void writeSettings();
    void readSettings();
con's avatar
con committed
334

335
    static CppEditorPlugin *m_instance;
con's avatar
con committed
336

337
    TextEditor::TextEditorActionHandler *m_actionHandler;
Kai Koehne's avatar
Kai Koehne committed
338
    bool m_sortedOutline;
339 340
    QAction *m_renameSymbolUnderCursorAction;
    QAction *m_findUsagesAction;
341
    QAction *m_reparseExternallyChangedFiles;
342
    QAction *m_openTypeHierarchyAction;
343
    QAction *m_openIncludeHierarchyAction;
344

Leandro Melo's avatar
Leandro Melo committed
345
    CppQuickFixAssistProvider *m_quickFixProvider;
346

347
    QPointer<TextEditor::ITextEditor> m_currentEditor;
con's avatar
con committed
348 349
};

350
class CppEditorFactory : public Core::IEditorFactory
con's avatar
con committed
351 352 353 354
{
    Q_OBJECT

public:
355
    CppEditorFactory(CppEditorPlugin *owner);
con's avatar
con committed
356 357 358 359

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

private:
360
    CppEditorPlugin *m_owner;
con's avatar
con committed
361 362 363 364 365
};

} // namespace Internal
} // namespace CppEditor

366
#endif // CPPEDITORPLUGIN_H