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

114 lines
3.5 KiB
C++
Raw Normal View History

/****************************************************************************
2009-11-13 16:14:26 +01:00
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
2009-11-13 16:14:26 +01:00
**
** This file is part of Qt Creator.
2009-11-13 16:14:26 +01:00
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
2009-11-13 16:14:26 +01:00
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
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 <QTextBlock>
#include <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->document()->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>();
}