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

This commit is contained in:
Christian Kamm
2010-08-12 14:18:36 +02:00
parent 538f611503
commit 03b443b86b
5 changed files with 13 additions and 26 deletions

View File

@@ -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;