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
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2009-11-13 16:14:26 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
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.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2009-11-13 16:14:26 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "cppquickfix.h"
|
|
|
|
|
#include "cppeditor.h"
|
2010-11-01 17:04:48 +01:00
|
|
|
#include "cppquickfixcollector.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>
|
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
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
CppQuickFixState::CppQuickFixState(TextEditor::BaseTextEditor *editor)
|
|
|
|
|
: QuickFixState(editor)
|
|
|
|
|
{}
|
2009-11-20 15:24:13 +01:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
const QList<AST *> &CppQuickFixState::path() const
|
2009-11-19 17:35:49 +01:00
|
|
|
{
|
2010-07-26 13:06:33 +02:00
|
|
|
return _path;
|
|
|
|
|
}
|
2010-07-02 17:15:12 +02:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
Snapshot CppQuickFixState::snapshot() const
|
2010-07-02 17:15:12 +02:00
|
|
|
{
|
2010-07-26 13:06:33 +02:00
|
|
|
return _snapshot;
|
|
|
|
|
}
|
2010-07-02 17:15:12 +02:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
Document::Ptr CppQuickFixState::document() const
|
2010-07-02 17:15:12 +02:00
|
|
|
{
|
2010-07-26 13:06:33 +02:00
|
|
|
return _semanticInfo.doc;
|
|
|
|
|
}
|
2010-07-02 17:15:12 +02:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
SemanticInfo CppQuickFixState::semanticInfo() const
|
2010-07-02 17:15:12 +02:00
|
|
|
{
|
2010-07-26 13:06:33 +02:00
|
|
|
return _semanticInfo;
|
|
|
|
|
}
|
2010-07-02 17:15:12 +02:00
|
|
|
|
2010-07-27 15:29:16 +02:00
|
|
|
const LookupContext &CppQuickFixState::context() const
|
2010-07-08 17:28:10 +02:00
|
|
|
{
|
2010-07-26 13:06:33 +02:00
|
|
|
return _context;
|
|
|
|
|
}
|
2010-07-19 17:40:06 +02:00
|
|
|
|
2010-08-13 12:49:11 +02:00
|
|
|
const CppRefactoringFile CppQuickFixState::currentFile() const
|
2010-07-19 17:40:06 +02:00
|
|
|
{
|
2010-08-13 12:49:11 +02:00
|
|
|
return CppRefactoringFile(editor(), document());
|
2010-07-26 13:06:33 +02:00
|
|
|
}
|
2010-07-19 17:40:06 +02:00
|
|
|
|
2010-11-01 17:04:48 +01:00
|
|
|
bool CppQuickFixState::isCursorOn(unsigned tokenIndex) const
|
|
|
|
|
{
|
|
|
|
|
return currentFile().isCursorOn(tokenIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CppQuickFixState::isCursorOn(const CPlusPlus::AST *ast) const
|
|
|
|
|
{
|
|
|
|
|
return currentFile().isCursorOn(ast);
|
|
|
|
|
}
|
2009-11-19 17:06:44 +01:00
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
CppQuickFixOperation::CppQuickFixOperation(const CppQuickFixState &state, int priority)
|
|
|
|
|
: QuickFixOperation(priority)
|
|
|
|
|
, _state(state)
|
|
|
|
|
{}
|
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()
|
|
|
|
|
{
|
2010-08-13 15:38:45 +02:00
|
|
|
CppRefactoringChanges refactoring(_state.snapshot());
|
2010-08-13 11:48:29 +02:00
|
|
|
CppRefactoringFile current = refactoring.file(fileName());
|
2010-08-12 13:46:18 +02:00
|
|
|
|
|
|
|
|
performChanges(¤t, &refactoring);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
const CppQuickFixState &CppQuickFixOperation::state() const
|
|
|
|
|
{
|
|
|
|
|
return _state;
|
2009-11-19 17:06:44 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
QString CppQuickFixOperation::fileName() const
|
|
|
|
|
{ return state().document()->fileName(); }
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2010-07-26 13:06:33 +02:00
|
|
|
QList<QuickFixOperation::Ptr> CppQuickFixFactory::matchingOperations(QuickFixState *state)
|
|
|
|
|
{
|
|
|
|
|
if (CppQuickFixState *cppState = static_cast<CppQuickFixState *>(state))
|
|
|
|
|
return match(*cppState);
|
|
|
|
|
else
|
|
|
|
|
return QList<TextEditor::QuickFixOperation::Ptr>();
|
|
|
|
|
}
|
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
|
|
|
}
|