diff --git a/src/plugins/cpptools/insertionpointlocator.cpp b/src/plugins/cpptools/insertionpointlocator.cpp index 7bbcd3da7a4e58976c3cadff0c813e287f6fffdf..08d9722086f89293a369afbd62a1619ad4f95677 100644 --- a/src/plugins/cpptools/insertionpointlocator.cpp +++ b/src/plugins/cpptools/insertionpointlocator.cpp @@ -516,56 +516,44 @@ static InsertionLocation nextToSurroundingDefinitions(Declaration *declaration, // find the declaration's definition CppTools::SymbolFinder symbolFinder; - Symbol *definition = symbolFinder.findMatchingDefinition(surroundingFunctionDecl, - changes.snapshot()); - if (!definition) + Function *definitionFunction = symbolFinder.findMatchingDefinition(surroundingFunctionDecl, + changes.snapshot()); + if (!definitionFunction) return noResult; unsigned line, column; if (suffix.isEmpty()) { - Function *definitionFunction = definition->asFunction(); - if (!definitionFunction) - return noResult; - - Document::Ptr targetDoc = changes.snapshot().document(QString::fromUtf8(definition->fileName())); + Document::Ptr targetDoc = changes.snapshot().document(QString::fromUtf8(definitionFunction->fileName())); if (!targetDoc) return noResult; targetDoc->translationUnit()->getPosition(definitionFunction->endOffset(), &line, &column); } else { // we don't have an offset to the start of the function definition, so we need to manually find it... - CppRefactoringFilePtr targetFile = changes.file(QString::fromUtf8(definition->fileName())); + CppRefactoringFilePtr targetFile = changes.file(QString::fromUtf8(definitionFunction->fileName())); if (!targetFile->isValid()) return noResult; FindFunctionDefinition finder(targetFile->cppDocument()->translationUnit()); - FunctionDefinitionAST *functionDefinition = finder(definition->line(), definition->column()); + FunctionDefinitionAST *functionDefinition = finder(definitionFunction->line(), definitionFunction->column()); if (!functionDefinition) return noResult; targetFile->cppDocument()->translationUnit()->getTokenStartPosition(functionDefinition->firstToken(), &line, &column); } - return InsertionLocation(QString::fromUtf8(definition->fileName()), prefix, suffix, line, column); + return InsertionLocation(QString::fromUtf8(definitionFunction->fileName()), prefix, suffix, line, column); } -QList<InsertionLocation> InsertionPointLocator::methodDefinition( - Declaration *declaration) const +QList<InsertionLocation> InsertionPointLocator::methodDefinition(Declaration *declaration) const { QList<InsertionLocation> result; if (!declaration) return result; CppTools::SymbolFinder symbolFinder; - if (Symbol *s = symbolFinder.findMatchingDefinition(declaration, - m_refactoringChanges.snapshot(), - true)) { - if (Function *f = s->asFunction()) { - if (f->isConst() == declaration->type().isConst() - && f->isVolatile() == declaration->type().isVolatile()) - return result; - } - } + if (symbolFinder.findMatchingDefinition(declaration, m_refactoringChanges.snapshot(), true)) + return result; const InsertionLocation location = nextToSurroundingDefinitions(declaration, m_refactoringChanges); if (location.isValid()) { diff --git a/src/plugins/cpptools/symbolfinder.cpp b/src/plugins/cpptools/symbolfinder.cpp index 19c25a28dd15ed532ac3b1135acaf666229f9563..9acd841121c758eb6c2b594df805673e8ee274a1 100644 --- a/src/plugins/cpptools/symbolfinder.cpp +++ b/src/plugins/cpptools/symbolfinder.cpp @@ -95,8 +95,8 @@ SymbolFinder::SymbolFinder() {} // strict means the returned symbol has to match exactly, -// including argument count and argument types -Symbol *SymbolFinder::findMatchingDefinition(Symbol *declaration, +// including argument count, argument types, constness and volatileness. +Function *SymbolFinder::findMatchingDefinition(Symbol *declaration, const Snapshot &snapshot, bool strict) { @@ -189,8 +189,11 @@ Symbol *SymbolFinder::findMatchingDefinition(Symbol *declaration, break; } - if (argIt == argc) + if (argIt == argc + && fun->isConst() == declaration->type().isConst() + && fun->isVolatile() == declaration->type().isVolatile()) { best = fun; + } } } diff --git a/src/plugins/cpptools/symbolfinder.h b/src/plugins/cpptools/symbolfinder.h index 7a756d0f061cf10c08eba595337dd7a6af528f01..eb52235efc6108ccb32fcd622e2574f938af10c4 100644 --- a/src/plugins/cpptools/symbolfinder.h +++ b/src/plugins/cpptools/symbolfinder.h @@ -46,9 +46,9 @@ class CPPTOOLS_EXPORT SymbolFinder public: SymbolFinder(); - CPlusPlus::Symbol *findMatchingDefinition(CPlusPlus::Symbol *symbol, - const CPlusPlus::Snapshot &snapshot, - bool strict = false); + CPlusPlus::Function *findMatchingDefinition(CPlusPlus::Symbol *symbol, + const CPlusPlus::Snapshot &snapshot, + bool strict = false); CPlusPlus::Class *findMatchingClassDeclaration(CPlusPlus::Symbol *declaration, const CPlusPlus::Snapshot &snapshot); diff --git a/src/plugins/designer/qtcreatorintegration.cpp b/src/plugins/designer/qtcreatorintegration.cpp index 3074146e0f8b8bc1e0f1047a715697c9b814fd9e..3b1395159f25384fff66cf82e5d3b51f1660b60d 100644 --- a/src/plugins/designer/qtcreatorintegration.cpp +++ b/src/plugins/designer/qtcreatorintegration.cpp @@ -257,11 +257,11 @@ static Document::Ptr findDefinition(Function *functionDeclaration, int *line) if (CppTools::CppModelManagerInterface *cppModelManager = CppTools::CppModelManagerInterface::instance()) { const Snapshot snapshot = cppModelManager->snapshot(); CppTools::SymbolFinder symbolFinder; - if (Symbol *def = symbolFinder.findMatchingDefinition(functionDeclaration, snapshot)) { + if (Function *fun = symbolFinder.findMatchingDefinition(functionDeclaration, snapshot)) { if (line) - *line = def->line(); + *line = fun->line(); - return snapshot.document(QString::fromUtf8(def->fileName(), def->fileNameLength())); + return snapshot.document(QString::fromUtf8(fun->fileName(), fun->fileNameLength())); } }