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

117 lines
3.4 KiB
C++
Raw Normal View History

2009-11-13 16:14:26 +01:00
/**************************************************************************
**
** This file is part of Qt Creator
**
2011-01-11 16:28:15 +01:00
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
2009-11-13 16:14:26 +01:00
**
2011-04-13 08:42:33 +02:00
** Contact: Nokia Corporation (info@qt.nokia.com)
2009-11-13 16:14:26 +01:00
**
**
** GNU Lesser General Public License Usage
**
2011-04-13 08:42:33 +02:00
** 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.
2009-11-13 16:14:26 +01:00
**
2010-12-17 16:01:08 +01:00
** In addition, as a special exception, Nokia gives you certain additional
2011-04-13 08:42:33 +02:00
** rights. These rights are described in the Nokia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
2011-04-13 08:42:33 +02:00
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
2010-12-17 16:01:08 +01:00
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
2009-11-13 16:14:26 +01:00
**
**************************************************************************/
#include "cppquickfix.h"
#include "cppeditor.h"
#include "cppquickfixassistant.h"
2009-11-13 16:43:26 +01:00
2010-07-26 13:06:33 +02:00
#include <AST.h>
#include <TranslationUnit.h>
#include <Token.h>
#include <cplusplus/ASTPath.h>
2009-11-13 16:43:26 +01:00
#include <cplusplus/CppDocument.h>
#include <cplusplus/ResolveExpression.h>
#include <cplusplus/Overview.h>
#include <cplusplus/TypeOfExpression.h>
2010-07-19 17:40:06 +02:00
#include <cplusplus/DependencyTable.h>
#include <cplusplus/CppRewriter.h>
2009-11-13 16:43:26 +01:00
#include <cpptools/cpprefactoringchanges.h>
#include <QtGui/QTextBlock>
2011-01-20 14:03:07 +01:00
#include <QtCore/QFileInfo>
2009-11-13 16:14:26 +01:00
2010-07-26 13:06:33 +02:00
using namespace CppEditor;
2009-11-13 16:14:26 +01:00
using namespace CppEditor::Internal;
using namespace CppTools;
2010-07-26 13:06:33 +02:00
using namespace TextEditor;
2009-11-13 16:14:26 +01:00
using namespace CPlusPlus;
using namespace Utils;
2009-11-13 16:14:26 +01:00
CppQuickFixOperation::CppQuickFixOperation(
const QSharedPointer<const CppQuickFixAssistInterface> &interface, int priority)
2010-07-26 13:06:33 +02:00
: QuickFixOperation(priority)
, m_interface(interface)
2010-07-26 13:06:33 +02:00
{}
2010-07-26 13:06:33 +02:00
CppQuickFixOperation::~CppQuickFixOperation()
{}
void CppQuickFixOperation::perform()
{
CppRefactoringChanges refactoring(m_interface->snapshot());
CppRefactoringFilePtr current = refactoring.file(fileName());
performChanges(current, refactoring);
}
const CppQuickFixAssistInterface *CppQuickFixOperation::assistInterface() const
2010-07-26 13:06:33 +02:00
{
return m_interface.data();
}
2010-07-26 13:06:33 +02:00
QString CppQuickFixOperation::fileName() const
{
return m_interface->file()->fileName();
}
2010-07-26 13:06:33 +02:00
CppQuickFixFactory::CppQuickFixFactory()
{
2010-07-26 13:06:33 +02:00
}
2010-07-26 13:06:33 +02:00
CppQuickFixFactory::~CppQuickFixFactory()
{
}
QList<QuickFixOperation::Ptr> CppQuickFixFactory::matchingOperations(
const QSharedPointer<const TextEditor::IAssistInterface> &interface)
2010-07-26 13:06:33 +02:00
{
QSharedPointer<const CppQuickFixAssistInterface> cppInterface =
interface.staticCast<const CppQuickFixAssistInterface>();
if (cppInterface->path().isEmpty())
return QList<QuickFixOperation::Ptr>();
return match(cppInterface);
2010-07-26 13:06:33 +02:00
}
2010-07-26 13:06:33 +02:00
QList<CppQuickFixOperation::Ptr> CppQuickFixFactory::singleResult(CppQuickFixOperation *operation)
{
QList<CppQuickFixOperation::Ptr> result;
result.append(CppQuickFixOperation::Ptr(operation));
return result;
}
2010-07-26 13:06:33 +02:00
QList<CppQuickFixOperation::Ptr> CppQuickFixFactory::noResult()
{
2010-07-26 13:06:33 +02:00
return QList<CppQuickFixOperation::Ptr>();
}