Files
qt-creator/src/plugins/cppeditor/cppquickfix.h

130 lines
3.8 KiB
C
Raw Normal View History

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>
#include <texteditor/quickfix.h>
2009-11-13 16:14:26 +01:00
#include <cplusplus/CppDocument.h>
#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-13 16:14:26 +01:00
#include <QtCore/QSharedPointer>
#include <QtGui/QTextCursor>
#include "cpprefactoringchanges.h"
2009-11-13 16:14:26 +01:00
namespace CppTools {
class CppModelManagerInterface;
} // end of namespace CppTools
namespace CppEditor {
namespace Internal {
class CppQuickFixOperation: public TextEditor::QuickFixOperation
2009-11-13 16:14:26 +01:00
{
Q_DISABLE_COPY(CppQuickFixOperation)
2009-11-13 16:14:26 +01:00
public:
CppQuickFixOperation(TextEditor::BaseTextEditor *editor);
virtual ~CppQuickFixOperation();
2009-11-13 16:14:26 +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;
const CPlusPlus::Snapshot &snapshot() const;
2009-11-25 12:22:55 +01: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;
QString fileName() const;
virtual void apply();
virtual CppRefactoringChanges *refactoringChanges() const;
2009-11-13 16:14:26 +01:00
const CPlusPlus::Token &tokenAt(unsigned index) const;
int startOf(unsigned index) const;
int startOf(const CPlusPlus::AST *ast) const;
int endOf(unsigned index) const;
int endOf(const CPlusPlus::AST *ast) const;
void startAndEndOf(unsigned index, int *start, int *end) const;
bool isCursorOn(unsigned tokenIndex) const;
bool isCursorOn(const CPlusPlus::AST *ast) const;
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:
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