diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 8f37ac5e53a..861305945fa 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -34,6 +34,7 @@ #include "cppchecksymbols.h" #include "cppquickfix.h" #include "cpplocalsymbols.h" +#include "cppquickfixcollector.h" #include #include diff --git a/src/plugins/cppeditor/cppeditor.pro b/src/plugins/cppeditor/cppeditor.pro index 57767721ec4..78db8ed3119 100644 --- a/src/plugins/cppeditor/cppeditor.pro +++ b/src/plugins/cppeditor/cppeditor.pro @@ -21,7 +21,8 @@ HEADERS += cppplugin.h \ cppinsertdecldef.h \ cpplocalsymbols.h \ cpptypehierarchy.h \ - cppelementevaluator.h + cppelementevaluator.h \ + cppquickfixcollector.h SOURCES += cppplugin.cpp \ cppeditor.cpp \ cpphighlighter.cpp \ @@ -36,7 +37,8 @@ SOURCES += cppplugin.cpp \ cppinsertdecldef.cpp \ cpplocalsymbols.cpp \ cpptypehierarchy.cpp \ - cppelementevaluator.cpp + cppelementevaluator.cpp \ + cppquickfixcollector.cpp RESOURCES += cppeditor.qrc OTHER_FILES += CppEditor.pluginspec \ CppEditor.mimetypes.xml diff --git a/src/plugins/cppeditor/cppinsertdecldef.cpp b/src/plugins/cppeditor/cppinsertdecldef.cpp index c0becdf2a46..3fbe7e6bf24 100644 --- a/src/plugins/cppeditor/cppinsertdecldef.cpp +++ b/src/plugins/cppeditor/cppinsertdecldef.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include diff --git a/src/plugins/cppeditor/cppplugin.cpp b/src/plugins/cppeditor/cppplugin.cpp index d5ab7774773..369f9ae4a54 100644 --- a/src/plugins/cppeditor/cppplugin.cpp +++ b/src/plugins/cppeditor/cppplugin.cpp @@ -36,6 +36,7 @@ #include "cpphoverhandler.h" #include "cppquickfix.h" #include "cppoutline.h" +#include "cppquickfixcollector.h" #include "cpptypehierarchy.h" #include diff --git a/src/plugins/cppeditor/cppquickfix.cpp b/src/plugins/cppeditor/cppquickfix.cpp index a0ce66a1ce9..c66333f860d 100644 --- a/src/plugins/cppeditor/cppquickfix.cpp +++ b/src/plugins/cppeditor/cppquickfix.cpp @@ -29,6 +29,7 @@ #include "cppquickfix.h" #include "cppeditor.h" +#include "cppquickfixcollector.h" #include #include @@ -42,11 +43,7 @@ #include #include -#include #include -#include -#include -#include #include @@ -91,6 +88,15 @@ const CppRefactoringFile CppQuickFixState::currentFile() const return CppRefactoringFile(editor(), document()); } +bool CppQuickFixState::isCursorOn(unsigned tokenIndex) const +{ + return currentFile().isCursorOn(tokenIndex); +} + +bool CppQuickFixState::isCursorOn(const CPlusPlus::AST *ast) const +{ + return currentFile().isCursorOn(ast); +} CppQuickFixOperation::CppQuickFixOperation(const CppQuickFixState &state, int priority) : QuickFixOperation(priority) @@ -143,54 +149,3 @@ QList CppQuickFixFactory::noResult() { return QList(); } - -CppQuickFixCollector::CppQuickFixCollector() -{ -} - -CppQuickFixCollector::~CppQuickFixCollector() -{ -} - -bool CppQuickFixCollector::supportsEditor(TextEditor::ITextEditable *editor) -{ - return CppTools::CppModelManagerInterface::instance()->isCppEditor(editor); -} - -TextEditor::QuickFixState *CppQuickFixCollector::initializeCompletion(TextEditor::BaseTextEditor *editor) -{ - if (CPPEditor *cppEditor = qobject_cast(editor)) { - const SemanticInfo info = cppEditor->semanticInfo(); - - if (info.revision != cppEditor->editorRevision()) { - // outdated - qWarning() << "TODO: outdated semantic info, force a reparse."; - return 0; - } - - if (info.doc) { - ASTPath astPath(info.doc); - - const QList path = astPath(cppEditor->textCursor()); - if (! path.isEmpty()) { - CppQuickFixState *state = new CppQuickFixState(editor); - state->_path = path; - state->_semanticInfo = info; - state->_snapshot = CppTools::CppModelManagerInterface::instance()->snapshot(); - state->_context = LookupContext(info.doc, state->snapshot()); - return state; - } - } - } - - return 0; -} - -QList CppQuickFixCollector::quickFixFactories() const -{ - QList results; - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - foreach (CppQuickFixFactory *f, pm->getObjects()) - results.append(f); - return results; -} diff --git a/src/plugins/cppeditor/cppquickfix.h b/src/plugins/cppeditor/cppquickfix.h index a261297f5be..9e7e16ef240 100644 --- a/src/plugins/cppeditor/cppquickfix.h +++ b/src/plugins/cppeditor/cppquickfix.h @@ -35,16 +35,12 @@ #include #include -#include -#include #include -#include - -#include -#include namespace CppTools { class CppModelManagerInterface; + class CppRefactoringFile; + class CppRefactoringChanges; } // end of namespace CppTools namespace ExtensionSystem { @@ -72,10 +68,8 @@ public: const CppTools::CppRefactoringFile currentFile() const; - bool isCursorOn(unsigned tokenIndex) const - { return currentFile().isCursorOn(tokenIndex); } - bool isCursorOn(const CPlusPlus::AST *ast) const - { return currentFile().isCursorOn(ast); } + bool isCursorOn(unsigned tokenIndex) const; + bool isCursorOn(const CPlusPlus::AST *ast) const; private: QList _path; @@ -102,9 +96,6 @@ protected: const CppQuickFixState &state() const; -protected: // Utility functions forwarding to CppQuickFixState - typedef Utils::ChangeSet::Range Range; - private: CppQuickFixState _state; }; @@ -136,26 +127,6 @@ protected: static QList noResult(); }; -namespace Internal { - -class CppQuickFixCollector: public TextEditor::QuickFixCollector -{ - Q_OBJECT - -public: - CppQuickFixCollector(); - virtual ~CppQuickFixCollector(); - - virtual bool supportsEditor(TextEditor::ITextEditable *editor); - virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::BaseTextEditor *editor); - - virtual QList quickFixFactories() const; - - /// Registers all quick-fixes in this plug-in as auto-released objects. - static void registerQuickFixes(ExtensionSystem::IPlugin *plugIn); -}; - -} // end of namespace Internal -} // end of namespace CppEditor +} // namespace CppEditor #endif // CPPQUICKFIX_H diff --git a/src/plugins/cppeditor/cppquickfixcollector.cpp b/src/plugins/cppeditor/cppquickfixcollector.cpp new file mode 100644 index 00000000000..5f360a429ca --- /dev/null +++ b/src/plugins/cppeditor/cppquickfixcollector.cpp @@ -0,0 +1,97 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "cppquickfixcollector.h" +#include "cppeditor.h" + +#include + +#include +#include +#include + +#include +#include + +namespace CppEditor { +namespace Internal { + +CppQuickFixCollector::CppQuickFixCollector() +{ +} + +CppQuickFixCollector::~CppQuickFixCollector() +{ +} + +bool CppQuickFixCollector::supportsEditor(TextEditor::ITextEditable *editor) +{ + return CppTools::CppModelManagerInterface::instance()->isCppEditor(editor); +} + +TextEditor::QuickFixState *CppQuickFixCollector::initializeCompletion(TextEditor::BaseTextEditor *editor) +{ + if (CPPEditor *cppEditor = qobject_cast(editor)) { + const SemanticInfo info = cppEditor->semanticInfo(); + + if (info.revision != cppEditor->editorRevision()) { + // outdated + qWarning() << "TODO: outdated semantic info, force a reparse."; + return 0; + } + + if (info.doc) { + CPlusPlus::ASTPath astPath(info.doc); + + const QList path = astPath(cppEditor->textCursor()); + if (! path.isEmpty()) { + CppQuickFixState *state = new CppQuickFixState(editor); + state->_path = path; + state->_semanticInfo = info; + state->_snapshot = CppTools::CppModelManagerInterface::instance()->snapshot(); + state->_context = CPlusPlus::LookupContext(info.doc, state->snapshot()); + return state; + } + } + } + + return 0; +} + +QList CppQuickFixCollector::quickFixFactories() const +{ + QList results; + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + foreach (CppQuickFixFactory *f, pm->getObjects()) + results.append(f); + return results; +} + +} // namespace Internal +} // namespace CppEditor diff --git a/src/plugins/cppeditor/cppquickfixcollector.h b/src/plugins/cppeditor/cppquickfixcollector.h new file mode 100644 index 00000000000..afc2342fb70 --- /dev/null +++ b/src/plugins/cppeditor/cppquickfixcollector.h @@ -0,0 +1,65 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef QUICKFIXCOLLECTOR_H +#define QUICKFIXCOLLECTOR_H + +#include + +namespace ExtensionSystem { +class IPlugin; +} + +namespace TextEditor { +class QuickFixState; +} + +namespace CppEditor { +namespace Internal { + +class CppQuickFixCollector: public TextEditor::QuickFixCollector +{ + Q_OBJECT +public: + CppQuickFixCollector(); + virtual ~CppQuickFixCollector(); + + virtual bool supportsEditor(TextEditor::ITextEditable *editor); + virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::BaseTextEditor *editor); + + virtual QList quickFixFactories() const; + + /// Registers all quick-fixes in this plug-in as auto-released objects. + static void registerQuickFixes(ExtensionSystem::IPlugin *plugIn); +}; + +} // namespace Internal +} // namespace CppEditor + +#endif // QUICKFIXCOLLECTOR_H diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index c86cacf6dc9..503150e1c96 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -30,6 +30,7 @@ #include "cppeditor.h" #include "cppquickfix.h" #include "cppinsertdecldef.h" +#include "cppquickfixcollector.h" #include #include @@ -50,6 +51,7 @@ #include #include #include +#include #include #include @@ -521,7 +523,7 @@ private: changes.insert(end, "\n}"); currentFile->change(changes); - currentFile->indent(Range(start, end)); + currentFile->indent(Utils::ChangeSet::Range(start, end)); } private: