Commit 03b443b8 authored by Christian Kamm's avatar Christian Kamm
Browse files

QuickFix: Simplify getting a Document for a C++ refactoring.

parent 538f6115
......@@ -84,12 +84,12 @@ public:
void performChanges(TextEditor::RefactoringFile *, CppRefactoringChanges *refactoring)
{
Document::Ptr targetDoc = refactoring->document(m_targetFileName);
TextEditor::RefactoringFile targetFile = refactoring->file(m_targetFileName);
Document::Ptr targetDoc = refactoring->document(targetFile);
InsertionPointLocator locator(targetDoc);
const InsertionLocation loc = locator.methodDeclarationInClass(m_targetSymbol, m_xsSpec);
Q_ASSERT(loc.isValid());
TextEditor::RefactoringFile targetFile = refactoring->file(m_targetFileName);
int targetPosition1 = targetFile.position(loc.line(), loc.column());
int targetPosition2 = qMax(0, targetFile.position(loc.line(), 1) - 1);
......
......@@ -63,33 +63,13 @@ const LookupContext &CppRefactoringChanges::context() const
return m_context;
}
Document::Ptr CppRefactoringChanges::document(const QString &fileName) const
Document::Ptr CppRefactoringChanges::document(const TextEditor::RefactoringFile &file) const
{
QString source;
unsigned editorRevision = 0;
QDateTime lastModified;
if (m_workingCopy.contains(fileName)) {
const QPair<QString, unsigned> workingCopy = m_workingCopy.get(fileName);
source = workingCopy.first;
editorRevision = workingCopy.second;
} else {
QFile file(fileName);
if (! file.open(QFile::ReadOnly))
return Document::Ptr();
lastModified = QFileInfo(file).lastModified();
source = QTextStream(&file).readAll(); // ### FIXME read bytes, and remove the convert below
file.close();
}
QString source = file.document()->toPlainText();
QString fileName = file.fileName();
const QByteArray contents = m_snapshot.preprocessedCode(source, fileName);
Document::Ptr doc = m_snapshot.documentFromSource(contents, fileName);
if (lastModified.isValid())
doc->setLastModified(lastModified);
else
doc->setEditorRevision(editorRevision);
doc->check();
return doc;
......
......@@ -48,9 +48,10 @@ public:
CPlusPlus::Document::Ptr thisDocument() const;
const CPlusPlus::Snapshot &snapshot() const;
CPlusPlus::Document::Ptr document(const QString &fileName) const;
const CPlusPlus::LookupContext &context() const;
CPlusPlus::Document::Ptr document(const TextEditor::RefactoringFile &file) const;
private:
virtual void indentSelection(const QTextCursor &selection) const;
virtual void fileChanged(const QString &fileName);
......
......@@ -270,6 +270,11 @@ const QTextCursor RefactoringFile::cursor() const
return QTextCursor();
}
QString RefactoringFile::fileName() const
{
return m_fileName;
}
int RefactoringFile::position(unsigned line, unsigned column) const
{
Q_ASSERT(line != 0);
......
......@@ -57,6 +57,7 @@ public:
const QTextDocument *document() const;
const QTextCursor cursor() const;
QString fileName() const;
// converts 1-based line and column into 0-based offset
int position(unsigned line, unsigned column) const;
......
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