Commit f0f623bc authored by Christian Kamm's avatar Christian Kamm

Fix crash related to 'add definition from declaration' quickfix.

Reviewed-by: hjk
Reviewed-by: Erik Verbruggen
parent 95107b09
...@@ -287,8 +287,10 @@ QList<CppQuickFixOperation::Ptr> DefFromDecl::match(const CppQuickFixState &stat ...@@ -287,8 +287,10 @@ QList<CppQuickFixOperation::Ptr> DefFromDecl::match(const CppQuickFixState &stat
CppRefactoringChanges refactoring(state.snapshot()); CppRefactoringChanges refactoring(state.snapshot());
InsertionPointLocator locator(&refactoring); InsertionPointLocator locator(&refactoring);
QList<CppQuickFixOperation::Ptr> results; QList<CppQuickFixOperation::Ptr> results;
foreach (const InsertionLocation &loc, locator.methodDefinition(decl)) foreach (const InsertionLocation &loc, locator.methodDefinition(decl)) {
results.append(CppQuickFixOperation::Ptr(new InsertDefOperation(state, idx, decl, loc))); if (loc.isValid())
results.append(CppQuickFixOperation::Ptr(new InsertDefOperation(state, idx, decl, loc)));
}
return results; return results;
} }
} }
......
...@@ -202,7 +202,7 @@ RefactoringFile::RefactoringFile(const RefactoringFile &other) ...@@ -202,7 +202,7 @@ RefactoringFile::RefactoringFile(const RefactoringFile &other)
RefactoringFile::~RefactoringFile() RefactoringFile::~RefactoringFile()
{ {
if (m_refactoringChanges && m_openEditor) if (m_refactoringChanges && m_openEditor && !m_fileName.isEmpty())
m_editor = m_refactoringChanges->openEditor(m_fileName, -1); m_editor = m_refactoringChanges->openEditor(m_fileName, -1);
// apply changes, if any // apply changes, if any
...@@ -227,14 +227,15 @@ RefactoringFile::~RefactoringFile() ...@@ -227,14 +227,15 @@ RefactoringFile::~RefactoringFile()
} }
// if this document doesn't have an editor, write the result to a file // if this document doesn't have an editor, write the result to a file
if (!m_editor) { if (!m_editor && !m_fileName.isEmpty()) {
const QByteArray &newContents = doc->toPlainText().toUtf8(); const QByteArray &newContents = doc->toPlainText().toUtf8();
QFile file(m_fileName); QFile file(m_fileName);
file.open(QFile::WriteOnly); file.open(QFile::WriteOnly);
file.write(newContents); file.write(newContents);
} }
m_refactoringChanges->fileChanged(m_fileName); if (!m_fileName.isEmpty())
m_refactoringChanges->fileChanged(m_fileName);
} }
delete m_document; delete m_document;
...@@ -254,9 +255,9 @@ QTextDocument *RefactoringFile::mutableDocument() const ...@@ -254,9 +255,9 @@ QTextDocument *RefactoringFile::mutableDocument() const
{ {
if (m_editor) if (m_editor)
return m_editor->document(); return m_editor->document();
else if (!m_document && !m_fileName.isEmpty()) { else if (!m_document) {
QString fileContents; QString fileContents;
{ if (!m_fileName.isEmpty()) {
QFile file(m_fileName); QFile file(m_fileName);
if (file.open(QIODevice::ReadOnly)) if (file.open(QIODevice::ReadOnly))
fileContents = file.readAll(); fileContents = file.readAll();
......
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