Commit e78380fd authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Share the LookupContext.

parent b374fcc4
......@@ -909,8 +909,7 @@ public:
}
}
LookupContext context(document(), snapshot());
QSharedPointer<Control> control = context.control();
QSharedPointer<Control> control = context().control();
const Name *trName = control->nameId(control->findOrInsertIdentifier("tr"));
// Check whether we are in a method:
......@@ -918,7 +917,7 @@ public:
{
if (FunctionDefinitionAST *definition = path.at(i)->asFunctionDefinition()) {
Function *function = definition->symbol;
ClassOrNamespace *b = context.lookupType(function);
ClassOrNamespace *b = context().lookupType(function);
if (b) {
// Do we have a tr method?
foreach(const LookupItem &r, b->find(trName)) {
......@@ -1388,14 +1387,12 @@ public:
{
if (ast && isCursorOn(ast)) {
if (const Name *name = ast->name) {
context = LookupContext(document(), snapshot());
unsigned line, column;
document()->translationUnit()->getTokenStartPosition(ast->firstToken(), &line, &column);
fwdClass = 0;
foreach (const LookupItem &r, context.lookup(name, document()->scopeAt(line, column))) {
foreach (const LookupItem &r, context().lookup(name, document()->scopeAt(line, column))) {
if (! r.declaration())
continue;
else if (ForwardClassDeclaration *fwd = r.declaration()->asForwardClassDeclaration())
......@@ -1488,7 +1485,6 @@ public:
}
private:
LookupContext context;
Symbol *fwdClass;
};
......@@ -1513,7 +1509,7 @@ int CppQuickFixOperation::match(TextEditor::QuickFixState *state)
_document = s->info.doc;
if (_refactoringChanges)
delete _refactoringChanges;
_refactoringChanges = new CppRefactoringChanges(s->snapshot);
_refactoringChanges = new CppRefactoringChanges(_document, s->snapshot);
return match(s->path);
}
......@@ -1546,9 +1542,10 @@ Document::Ptr CppQuickFixOperation::document() const
{ return _document; }
const Snapshot &CppQuickFixOperation::snapshot() const
{
return _refactoringChanges->snapshot();
}
{ return _refactoringChanges->snapshot(); }
const CPlusPlus::LookupContext &CppQuickFixOperation::context() const
{ return _refactoringChanges->context(); }
const CPlusPlus::Token &CppQuickFixOperation::tokenAt(unsigned index) const
{ return _document->translationUnit()->tokenAt(index); }
......
......@@ -62,6 +62,7 @@ public:
CPlusPlus::Document::Ptr document() const;
const CPlusPlus::Snapshot &snapshot() const;
const CPlusPlus::LookupContext &context() const;
virtual int match(TextEditor::QuickFixState *state);
......
......@@ -29,24 +29,33 @@
#include "cpprefactoringchanges.h"
using namespace CPlusPlus;
using namespace CppTools;
using namespace TextEditor;
using namespace CppEditor;
using namespace CPlusPlus;
CppRefactoringChanges::CppRefactoringChanges(const Snapshot &snapshot)
: m_snapshot(snapshot)
CppRefactoringChanges::CppRefactoringChanges(const Document::Ptr &thisDocument, const Snapshot &snapshot)
: m_thisDocument(thisDocument)
, m_snapshot(snapshot)
, m_context(m_thisDocument, m_snapshot)
, m_modelManager(CppTools::CppModelManagerInterface::instance())
{
Q_ASSERT(m_modelManager);
m_workingCopy = m_modelManager->workingCopy();
}
const CPlusPlus::Snapshot &CppRefactoringChanges::snapshot() const
Document::Ptr CppRefactoringChanges::thisDocument() const
{
return m_thisDocument;
}
const Snapshot &CppRefactoringChanges::snapshot() const
{
return m_snapshot;
}
const LookupContext &CppRefactoringChanges::context() const
{
return m_context;
}
QStringList CppRefactoringChanges::apply()
{
......
......@@ -31,6 +31,7 @@
#define CPPREFACTORINGCHANGES_H
#include <cplusplus/CppDocument.h>
#include <cplusplus/LookupContext.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <cppeditor/cppeditor_global.h>
......@@ -42,15 +43,20 @@ namespace CppEditor {
class CPPEDITOR_EXPORT CppRefactoringChanges: public TextEditor::RefactoringChanges
{
public:
CppRefactoringChanges(const CPlusPlus::Snapshot &snapshot);
CppRefactoringChanges(const CPlusPlus::Document::Ptr &thisDocument,
const CPlusPlus::Snapshot &snapshot);
virtual QStringList apply();
CPlusPlus::Document::Ptr thisDocument() const;
const CPlusPlus::Snapshot &snapshot() const;
CPlusPlus::Document::Ptr document(const QString &fileName) const;
const CPlusPlus::LookupContext &context() const;
private:
CPlusPlus::Document::Ptr m_thisDocument;
CPlusPlus::Snapshot m_snapshot;
CPlusPlus::LookupContext m_context;
CppTools::CppModelManagerInterface *m_modelManager;
CppTools::CppModelManagerInterface::WorkingCopy m_workingCopy;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment