2009-11-13 16:14:26 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2009-11-13 16:14:26 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@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
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2009-11-13 16:14:26 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "cppquickfix.h"
|
|
|
|
|
#include "cppeditor.h"
|
2011-04-15 16:19:23 +02:00
|
|
|
#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>
|
|
|
|
|
|
2010-05-28 15:25:24 +02:00
|
|
|
#include <cplusplus/ASTPath.h>
|
2009-11-13 16:43:26 +01:00
|
|
|
#include <cplusplus/CppDocument.h>
|
2009-12-23 14:54:02 +01:00
|
|
|
#include <cplusplus/ResolveExpression.h>
|
2010-07-05 09:24:49 +02:00
|
|
|
#include <cplusplus/Overview.h>
|
2010-07-08 17:28:10 +02:00
|
|
|
#include <cplusplus/TypeOfExpression.h>
|
2010-07-19 17:40:06 +02:00
|
|
|
#include <cplusplus/DependencyTable.h>
|
2010-07-20 15:04:50 +02:00
|
|
|
#include <cplusplus/CppRewriter.h>
|
2009-11-13 16:43:26 +01:00
|
|
|
|
2010-09-30 12:09:38 +02:00
|
|
|
#include <cpptools/cpprefactoringchanges.h>
|
2010-04-26 14:02:09 +02:00
|
|
|
|
|
|
|
|
#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;
|
2010-09-30 12:09:38 +02:00
|
|
|
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;
|
2010-06-14 17:15:53 +02:00
|
|
|
using namespace Utils;
|
2009-11-13 16:14:26 +01:00
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
CppQuickFixOperation::CppQuickFixOperation(
|
|
|
|
|
const QSharedPointer<const CppQuickFixAssistInterface> &interface, int priority)
|
2010-07-26 13:06:33 +02:00
|
|
|
: QuickFixOperation(priority)
|
2011-04-15 16:19:23 +02:00
|
|
|
, m_interface(interface)
|
2010-07-26 13:06:33 +02:00
|
|
|
{}
|
2009-11-19 17:06:44 +01:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
CppQuickFixOperation::~CppQuickFixOperation()
|
|
|
|
|
{}
|
|
|
|
|
|
2010-08-12 13:46:18 +02:00
|
|
|
void CppQuickFixOperation::perform()
|
|
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
CppRefactoringChanges refactoring(m_interface->snapshot());
|
2011-08-17 11:35:57 +02:00
|
|
|
CppRefactoringFilePtr current = refactoring.file(fileName());
|
2010-08-12 13:46:18 +02:00
|
|
|
|
2011-08-17 11:35:57 +02:00
|
|
|
performChanges(current, refactoring);
|
2010-08-12 13:46:18 +02:00
|
|
|
}
|
|
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
const CppQuickFixAssistInterface *CppQuickFixOperation::assistInterface() const
|
2010-07-26 13:06:33 +02:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
return m_interface.data();
|
2009-11-19 17:06:44 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
QString CppQuickFixOperation::fileName() const
|
2011-04-15 16:19:23 +02:00
|
|
|
{
|
|
|
|
|
return m_interface->file()->fileName();
|
|
|
|
|
}
|
2010-07-26 13:06:33 +02:00
|
|
|
|
|
|
|
|
CppQuickFixFactory::CppQuickFixFactory()
|
2009-11-20 15:24:13 +01:00
|
|
|
{
|
2010-07-26 13:06:33 +02:00
|
|
|
}
|
2009-11-20 15:24:13 +01:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
CppQuickFixFactory::~CppQuickFixFactory()
|
|
|
|
|
{
|
|
|
|
|
}
|
2009-11-20 15:24:13 +01:00
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
QList<QuickFixOperation::Ptr> CppQuickFixFactory::matchingOperations(
|
|
|
|
|
const QSharedPointer<const TextEditor::IAssistInterface> &interface)
|
2010-07-26 13:06:33 +02:00
|
|
|
{
|
2011-04-15 16:19:23 +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
|
|
|
}
|
2009-11-20 15:24:13 +01: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;
|
2009-11-20 15:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
QList<CppQuickFixOperation::Ptr> CppQuickFixFactory::noResult()
|
2009-11-20 10:47:19 +01:00
|
|
|
{
|
2010-07-26 13:06:33 +02:00
|
|
|
return QList<CppQuickFixOperation::Ptr>();
|
2009-11-20 10:47:19 +01:00
|
|
|
}
|