2009-11-13 16:14:26 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2009-11-13 16:14:26 +01:00
|
|
|
**
|
|
|
|
|
** 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 CPPQUICKFIX_H
|
|
|
|
|
#define CPPQUICKFIX_H
|
|
|
|
|
|
|
|
|
|
#include <texteditor/icompletioncollector.h>
|
2010-06-03 14:15:56 +02:00
|
|
|
#include <texteditor/quickfix.h>
|
2009-11-13 16:14:26 +01:00
|
|
|
|
|
|
|
|
#include <cplusplus/CppDocument.h>
|
2009-11-16 16:18:08 +01:00
|
|
|
#include <ASTfwd.h>
|
2009-11-13 16:14:26 +01:00
|
|
|
|
2009-11-24 11:29:43 +01:00
|
|
|
#include <utils/changeset.h>
|
2009-11-18 14:53:35 +01:00
|
|
|
|
2009-11-13 16:14:26 +01:00
|
|
|
#include <QtCore/QSharedPointer>
|
|
|
|
|
#include <QtGui/QTextCursor>
|
|
|
|
|
|
2010-06-22 09:29:24 +02:00
|
|
|
#include "cpprefactoringchanges.h"
|
|
|
|
|
|
2009-11-13 16:14:26 +01:00
|
|
|
namespace CppTools {
|
|
|
|
|
class CppModelManagerInterface;
|
|
|
|
|
} // end of namespace CppTools
|
|
|
|
|
|
|
|
|
|
namespace CppEditor {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-06-03 14:15:56 +02:00
|
|
|
class CppQuickFixOperation: public TextEditor::QuickFixOperation
|
2009-11-13 16:14:26 +01:00
|
|
|
{
|
2010-06-03 14:15:56 +02:00
|
|
|
Q_DISABLE_COPY(CppQuickFixOperation)
|
2009-11-13 16:14:26 +01:00
|
|
|
|
|
|
|
|
public:
|
2010-06-03 14:15:56 +02:00
|
|
|
CppQuickFixOperation(TextEditor::BaseTextEditor *editor);
|
|
|
|
|
virtual ~CppQuickFixOperation();
|
2009-11-13 16:14:26 +01:00
|
|
|
|
2009-11-24 11:49:56 +01:00
|
|
|
virtual int match(const QList<CPlusPlus::AST *> &path) = 0;
|
2009-11-13 16:14:26 +01:00
|
|
|
|
2009-11-25 12:22:55 +01:00
|
|
|
CPlusPlus::Document::Ptr document() const;
|
2010-06-03 14:45:55 +02:00
|
|
|
const CPlusPlus::Snapshot &snapshot() const;
|
2010-07-19 18:27:11 +02:00
|
|
|
const CPlusPlus::LookupContext &context() const;
|
2009-11-25 12:22:55 +01:00
|
|
|
|
2010-06-03 14:15:56 +02:00
|
|
|
virtual int match(TextEditor::QuickFixState *state);
|
2009-11-20 13:08:17 +01:00
|
|
|
|
2009-11-25 12:25:53 +01:00
|
|
|
protected:
|
2010-06-22 10:14:06 +02:00
|
|
|
using TextEditor::QuickFixOperation::range;
|
2010-06-22 13:46:26 +02:00
|
|
|
using TextEditor::QuickFixOperation::textOf;
|
|
|
|
|
using TextEditor::QuickFixOperation::charAt;
|
2010-06-22 10:14:06 +02:00
|
|
|
|
|
|
|
|
Utils::ChangeSet::Range range(unsigned tokenIndex) const;
|
|
|
|
|
Utils::ChangeSet::Range range(CPlusPlus::AST *ast) const;
|
|
|
|
|
|
2010-06-14 17:15:53 +02:00
|
|
|
QString fileName() const;
|
|
|
|
|
|
2010-06-14 14:52:43 +02:00
|
|
|
virtual void apply();
|
2010-06-22 09:29:24 +02:00
|
|
|
virtual CppRefactoringChanges *refactoringChanges() const;
|
2010-06-14 14:52:43 +02:00
|
|
|
|
2009-11-13 16:14:26 +01:00
|
|
|
const CPlusPlus::Token &tokenAt(unsigned index) const;
|
|
|
|
|
|
2009-11-18 14:53:35 +01:00
|
|
|
int startOf(unsigned index) const;
|
|
|
|
|
int startOf(const CPlusPlus::AST *ast) const;
|
|
|
|
|
int endOf(unsigned index) const;
|
|
|
|
|
int endOf(const CPlusPlus::AST *ast) const;
|
2009-11-26 15:00:54 +01:00
|
|
|
void startAndEndOf(unsigned index, int *start, int *end) const;
|
2009-11-18 14:53:35 +01:00
|
|
|
|
2009-11-23 16:18:34 +01:00
|
|
|
bool isCursorOn(unsigned tokenIndex) const;
|
|
|
|
|
bool isCursorOn(const CPlusPlus::AST *ast) const;
|
2009-11-19 17:06:44 +01:00
|
|
|
|
2009-12-23 12:55:35 +01:00
|
|
|
QString textOf(const CPlusPlus::AST *ast) const;
|
2009-11-20 13:08:17 +01:00
|
|
|
|
2009-11-13 16:14:26 +01:00
|
|
|
private:
|
2010-06-22 09:27:34 +02:00
|
|
|
CppRefactoringChanges *_refactoringChanges;
|
2009-11-25 12:22:55 +01:00
|
|
|
CPlusPlus::Document::Ptr _document;
|
2009-11-24 12:48:36 +01:00
|
|
|
CPlusPlus::AST *_topLevelNode;
|
2009-11-13 16:14:26 +01:00
|
|
|
};
|
|
|
|
|
|
2010-06-03 15:15:11 +02:00
|
|
|
class CppQuickFixCollector: public TextEditor::QuickFixCollector
|
2009-11-13 16:14:26 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2010-06-03 14:15:56 +02:00
|
|
|
CppQuickFixCollector();
|
|
|
|
|
virtual ~CppQuickFixCollector();
|
2009-11-13 16:14:26 +01:00
|
|
|
|
2010-06-07 12:12:07 +02:00
|
|
|
virtual bool supportsEditor(TextEditor::ITextEditable *editor);
|
2010-06-03 15:15:11 +02:00
|
|
|
virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::ITextEditable *editable);
|
2010-06-22 14:14:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CppQuickFixFactory: public TextEditor::IQuickFixFactory
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
CppQuickFixFactory(QObject *parent = 0);
|
|
|
|
|
virtual ~CppQuickFixFactory();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Returns true if this IQuickFixFactory can be used with the given editor.
|
|
|
|
|
*/
|
|
|
|
|
virtual QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor);
|
2009-11-13 16:14:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end of namespace Internal
|
|
|
|
|
} // end of namespace CppEditor
|
|
|
|
|
|
|
|
|
|
#endif // CPPQUICKFIX_H
|