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 **************************************************************************/
37 #include "cppeditor_global.h"
38 #include "cppsemanticinfo.h"
41 #include <cplusplus/CppDocument.h>
42 #include <texteditor/quickfix.h>
45 class CppModelManagerInterface;
46 class CppRefactoringFile;
47 class CppRefactoringChanges;
48 } // end of namespace CppTools
50 namespace ExtensionSystem {
57 class CppQuickFixCollector;
58 } // end of namespace Internal
60 class CPPEDITOR_EXPORT CppQuickFixState: public TextEditor::QuickFixState
62 friend class Internal::CppQuickFixCollector;
65 CppQuickFixState(TextEditor::BaseTextEditor *editor);
67 const QList<CPlusPlus::AST *> &path() const;
68 CPlusPlus::Snapshot snapshot() const;
69 CPlusPlus::Document::Ptr document() const;
70 CppEditor::Internal::SemanticInfo semanticInfo() const;
71 const CPlusPlus::LookupContext &context() const;
73 const CppTools::CppRefactoringFile currentFile() const;
75 bool isCursorOn(unsigned tokenIndex) const;
76 bool isCursorOn(const CPlusPlus::AST *ast) const;
79 QList<CPlusPlus::AST *> _path;
80 CPlusPlus::Snapshot _snapshot;
81 CppEditor::Internal::SemanticInfo _semanticInfo;
82 CPlusPlus::LookupContext _context;
85 class CPPEDITOR_EXPORT CppQuickFixOperation: public TextEditor::QuickFixOperation
87 Q_DISABLE_COPY(CppQuickFixOperation)
90 explicit CppQuickFixOperation(const CppQuickFixState &state, int priority = -1);
91 virtual ~CppQuickFixOperation();
93 virtual void perform();
96 virtual void performChanges(CppTools::CppRefactoringFile *currentFile,
97 CppTools::CppRefactoringChanges *refactoring) = 0;
99 QString fileName() const;
101 const CppQuickFixState &state() const;
104 CppQuickFixState _state;
107 class CPPEDITOR_EXPORT CppQuickFixFactory: public TextEditor::QuickFixFactory
112 CppQuickFixFactory();
113 virtual ~CppQuickFixFactory();
115 virtual QList<TextEditor::QuickFixOperation::Ptr> matchingOperations(TextEditor::QuickFixState *state);
117 Implement this method to match and create the appropriate
118 CppQuickFixOperation objects.
120 virtual QList<CppQuickFixOperation::Ptr> match(const CppQuickFixState &state) = 0;
124 Creates a list of 1 single element: the shared-pointer to the given
125 operation. This shared-pointer takes over the ownership (meaning the
126 responsibility to delete the operation).
128 static QList<CppQuickFixOperation::Ptr> singleResult(CppQuickFixOperation *operation);
130 /// Utility method which creates an empty list.
131 static QList<CppQuickFixOperation::Ptr> noResult();
134 } // namespace CppEditor
136 #endif // CPPQUICKFIX_H