C++ Editor: check for method existing decl/def when inserting new ones.

This commit is contained in:
Erik Verbruggen
2010-10-06 15:49:59 +02:00
parent 0555837c7f
commit ac9fc40645
4 changed files with 60 additions and 46 deletions

View File

@@ -104,7 +104,8 @@ CppRefactoringFile::CppRefactoringFile(TextEditor::BaseTextEditor *editor, CPlus
Document::Ptr CppRefactoringFile::cppDocument() const
{
if (!m_cppDocument) {
if (!m_cppDocument || !m_cppDocument->translationUnit() ||
!m_cppDocument->translationUnit()->ast()) {
const QString source = document()->toPlainText();
const QString name = fileName();
const Snapshot &snapshot = refactoringChanges()->snapshot();

View File

@@ -315,6 +315,7 @@ static bool isSourceFile(const QString &fileName)
}
/// Currently, we return the end of fileName.cpp
/// \todo take the definitions of the surrounding declarations into account
QList<InsertionLocation> InsertionPointLocator::methodDefinition(
Declaration *declaration) const
{
@@ -334,6 +335,15 @@ QList<InsertionLocation> InsertionPointLocator::methodDefinition(
if (doc.isNull())
return result;
Snapshot simplified = m_refactoringChanges->snapshot().simplified(doc);
if (Symbol *s = simplified.findMatchingDefinition(declaration)) {
if (Function *f = s->asFunction()) {
if (f->isConst() == declaration->type().isConst()
&& f->isVolatile() == declaration->type().isVolatile())
return result;
}
}
TranslationUnit *xUnit = doc->translationUnit();
unsigned tokenCount = xUnit->tokenCount();
if (tokenCount < 2) // no tokens available