diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2010-10-07 14:47:25 +0200 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2010-10-07 14:54:04 +0200 |
commit | f0f623bcb8858a916366bfcf8d8b22795fd6197b (patch) | |
tree | cebc2ef0e3f24490ea0230c43f0af48871a2d939 | |
parent | 95107b099864a5fd6ab7d731907d740faaf4c789 (diff) | |
download | qt-creator-f0f623bcb8858a916366bfcf8d8b22795fd6197b.tar.gz |
Fix crash related to 'add definition from declaration' quickfix.
Reviewed-by: hjk
Reviewed-by: Erik Verbruggen
-rw-r--r-- | src/plugins/cppeditor/cppinsertdecldef.cpp | 6 | ||||
-rw-r--r-- | src/plugins/texteditor/refactoringchanges.cpp | 11 |
2 files changed, 10 insertions, 7 deletions
diff --git a/src/plugins/cppeditor/cppinsertdecldef.cpp b/src/plugins/cppeditor/cppinsertdecldef.cpp index 9414a42148..e7ae40d85b 100644 --- a/src/plugins/cppeditor/cppinsertdecldef.cpp +++ b/src/plugins/cppeditor/cppinsertdecldef.cpp @@ -287,8 +287,10 @@ QList<CppQuickFixOperation::Ptr> DefFromDecl::match(const CppQuickFixState &stat CppRefactoringChanges refactoring(state.snapshot()); InsertionPointLocator locator(&refactoring); QList<CppQuickFixOperation::Ptr> results; - foreach (const InsertionLocation &loc, locator.methodDefinition(decl)) - results.append(CppQuickFixOperation::Ptr(new InsertDefOperation(state, idx, decl, loc))); + foreach (const InsertionLocation &loc, locator.methodDefinition(decl)) { + if (loc.isValid()) + results.append(CppQuickFixOperation::Ptr(new InsertDefOperation(state, idx, decl, loc))); + } return results; } } diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index 3cc5118441..303424dfac 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -202,7 +202,7 @@ RefactoringFile::RefactoringFile(const RefactoringFile &other) RefactoringFile::~RefactoringFile() { - if (m_refactoringChanges && m_openEditor) + if (m_refactoringChanges && m_openEditor && !m_fileName.isEmpty()) m_editor = m_refactoringChanges->openEditor(m_fileName, -1); // apply changes, if any @@ -227,14 +227,15 @@ RefactoringFile::~RefactoringFile() } // 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(); QFile file(m_fileName); file.open(QFile::WriteOnly); file.write(newContents); } - m_refactoringChanges->fileChanged(m_fileName); + if (!m_fileName.isEmpty()) + m_refactoringChanges->fileChanged(m_fileName); } delete m_document; @@ -254,9 +255,9 @@ QTextDocument *RefactoringFile::mutableDocument() const { if (m_editor) return m_editor->document(); - else if (!m_document && !m_fileName.isEmpty()) { + else if (!m_document) { QString fileContents; - { + if (!m_fileName.isEmpty()) { QFile file(m_fileName); if (file.open(QIODevice::ReadOnly)) fileContents = file.readAll(); |