forked from qt-creator/qt-creator
C++ Editor: check for method existing decl/def when inserting new ones.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user