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
|
|
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
#include "cpprefactoringchanges.h"
|
|
|
|
|
#include "cppsemanticinfo.h"
|
2009-11-13 16:14:26 +01:00
|
|
|
|
2009-11-16 16:18:08 +01:00
|
|
|
#include <ASTfwd.h>
|
2010-07-26 13:06:33 +02:00
|
|
|
#include <cplusplus/CppDocument.h>
|
|
|
|
|
#include <texteditor/icompletioncollector.h>
|
|
|
|
|
#include <texteditor/quickfix.h>
|
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>
|
|
|
|
|
|
|
|
|
|
namespace CppTools {
|
|
|
|
|
class CppModelManagerInterface;
|
|
|
|
|
} // end of namespace CppTools
|
|
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
namespace ExtensionSystem {
|
|
|
|
|
class IPlugin;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-13 16:14:26 +01:00
|
|
|
namespace CppEditor {
|
2010-07-26 13:06:33 +02:00
|
|
|
|
2009-11-13 16:14:26 +01:00
|
|
|
namespace Internal {
|
2010-07-26 13:06:33 +02:00
|
|
|
class CppQuickFixCollector;
|
|
|
|
|
} // end of namespace Internal
|
2009-11-13 16:14:26 +01:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
class CPPEDITOR_EXPORT CppQuickFixState: public TextEditor::QuickFixState
|
2009-11-13 16:14:26 +01:00
|
|
|
{
|
2010-07-26 13:06:33 +02:00
|
|
|
friend class Internal::CppQuickFixCollector;
|
2009-11-13 16:14:26 +01:00
|
|
|
|
|
|
|
|
public:
|
2010-07-26 13:06:33 +02:00
|
|
|
CppQuickFixState(TextEditor::BaseTextEditor *editor);
|
|
|
|
|
typedef Utils::ChangeSet::Range Range;
|
2009-11-13 16:14:26 +01:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
const QList<CPlusPlus::AST *> &path() const;
|
|
|
|
|
CPlusPlus::Snapshot snapshot() const;
|
2009-11-25 12:22:55 +01:00
|
|
|
CPlusPlus::Document::Ptr document() const;
|
2010-07-26 13:06:33 +02:00
|
|
|
CppEditor::Internal::SemanticInfo semanticInfo() const;
|
|
|
|
|
CPlusPlus::LookupContext context() const;
|
2009-11-25 12:22:55 +01:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
using TextEditor::QuickFixState::range;
|
|
|
|
|
using TextEditor::QuickFixState::textOf;
|
|
|
|
|
using TextEditor::QuickFixState::charAt;
|
2009-11-20 13:08:17 +01:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
CPlusPlus::Scope *scopeAt(unsigned index) const;
|
2010-06-22 10:14:06 +02:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
bool isCursorOn(unsigned tokenIndex) const;
|
|
|
|
|
bool isCursorOn(const CPlusPlus::AST *ast) const;
|
2010-06-14 17:15:53 +02:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
Range range(unsigned tokenIndex) const;
|
|
|
|
|
Range range(CPlusPlus::AST *ast) 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-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-07-26 13:06:33 +02:00
|
|
|
QList<CPlusPlus::AST *> _path;
|
|
|
|
|
CPlusPlus::Snapshot _snapshot;
|
|
|
|
|
CppEditor::Internal::SemanticInfo _semanticInfo;
|
|
|
|
|
CPlusPlus::LookupContext _context;
|
2009-11-13 16:14:26 +01:00
|
|
|
};
|
|
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
class CPPEDITOR_EXPORT CppQuickFixOperation: public TextEditor::QuickFixOperation
|
2009-11-13 16:14:26 +01:00
|
|
|
{
|
2010-07-26 13:06:33 +02:00
|
|
|
Q_DISABLE_COPY(CppQuickFixOperation)
|
2009-11-13 16:14:26 +01:00
|
|
|
|
|
|
|
|
public:
|
2010-07-26 13:06:33 +02:00
|
|
|
CppQuickFixOperation(const CppQuickFixState &state, int priority = -1);
|
|
|
|
|
virtual ~CppQuickFixOperation();
|
2009-11-13 16:14:26 +01:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
protected:
|
|
|
|
|
QString fileName() const;
|
|
|
|
|
|
|
|
|
|
CppRefactoringChanges *refactoringChanges() const;
|
|
|
|
|
|
|
|
|
|
const CppQuickFixState &state() const;
|
|
|
|
|
|
|
|
|
|
protected: // Utility functions forwarding to CppQuickFixState
|
|
|
|
|
typedef Utils::ChangeSet::Range Range;
|
|
|
|
|
|
|
|
|
|
bool isCursorOn(unsigned tokenIndex) const { return state().isCursorOn(tokenIndex); }
|
|
|
|
|
bool isCursorOn(const CPlusPlus::AST *ast) const { return state().isCursorOn(ast); }
|
|
|
|
|
|
|
|
|
|
Range range(int start, int end) const { return CppQuickFixState::range(start, end); }
|
|
|
|
|
Range range(unsigned tokenIndex) const { return state().range(tokenIndex); }
|
|
|
|
|
Range range(CPlusPlus::AST *ast) const { return state().range(ast); }
|
|
|
|
|
|
|
|
|
|
int startOf(unsigned index) const { return state().startOf(index); }
|
|
|
|
|
int startOf(const CPlusPlus::AST *ast) const { return state().startOf(ast); }
|
|
|
|
|
int endOf(unsigned index) const { return state().endOf(index); }
|
|
|
|
|
int endOf(const CPlusPlus::AST *ast) const { return state().endOf(ast); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
CppQuickFixState _state;
|
|
|
|
|
QScopedPointer<CppRefactoringChanges> _refactoringChanges;
|
2010-06-22 14:14:22 +02:00
|
|
|
};
|
|
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
class CPPEDITOR_EXPORT CppQuickFixFactory: public TextEditor::QuickFixFactory
|
2010-06-22 14:14:22 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2010-07-26 13:06:33 +02:00
|
|
|
CppQuickFixFactory();
|
2010-06-22 14:14:22 +02:00
|
|
|
virtual ~CppQuickFixFactory();
|
|
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
virtual QList<TextEditor::QuickFixOperation::Ptr> matchingOperations(TextEditor::QuickFixState *state);
|
|
|
|
|
virtual QList<CppQuickFixOperation::Ptr> match(const CppQuickFixState &state) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
static QList<CppQuickFixOperation::Ptr> singleResult(CppQuickFixOperation *operation);
|
|
|
|
|
static QList<CppQuickFixOperation::Ptr> 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<TextEditor::QuickFixFactory *> quickFixFactories() const;
|
|
|
|
|
|
|
|
|
|
static void registerQuickFixes(ExtensionSystem::IPlugin *plugIn);
|
2009-11-13 16:14:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end of namespace Internal
|
|
|
|
|
} // end of namespace CppEditor
|
|
|
|
|
|
|
|
|
|
#endif // CPPQUICKFIX_H
|