aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cpptools/insertionpointlocator.cpp
diff options
context:
space:
mode:
authorLorenz Haas <lykurg@gmail.com>2013-06-07 16:44:08 +0200
committerNikolai Kosjar <nikolai.kosjar@digia.com>2013-06-12 16:32:14 +0200
commit8f4c4b41f6dc93dd7afb1a349484a08588604056 (patch)
tree0ff26b6ee18d5347256deede50f6f0209a4d250e /src/plugins/cpptools/insertionpointlocator.cpp
parentc51195d9bb459d16ea0acfaa40b891189a964645 (diff)
CppTools: Fix nextToSurroundingDefinitions
Now it is checked if the adjacent declaration is also defined and one can define the destination file. Change-Id: Ifff59c49fc2ab3e2f36f41df42ae4b7d7ff8dd35 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src/plugins/cpptools/insertionpointlocator.cpp')
-rw-r--r--src/plugins/cpptools/insertionpointlocator.cpp51
1 files changed, 34 insertions, 17 deletions
diff --git a/src/plugins/cpptools/insertionpointlocator.cpp b/src/plugins/cpptools/insertionpointlocator.cpp
index f7118a2cfe..5170203463 100644
--- a/src/plugins/cpptools/insertionpointlocator.cpp
+++ b/src/plugins/cpptools/insertionpointlocator.cpp
@@ -470,7 +470,9 @@ static Declaration *isNonVirtualFunctionDeclaration(Symbol *s)
return declaration;
}
-static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration, const CppRefactoringChanges &changes)
+static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration,
+ const CppRefactoringChanges &changes,
+ const QString& destinationFile)
{
InsertionLocation noResult;
Class *klass = declaration->enclosingClass();
@@ -489,35 +491,47 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration, const
if (declIndex == -1)
return noResult;
- // scan preceding declarations for a function declaration
+ // scan preceding declarations for a function declaration (and see if it is defined)
+ CppTools::SymbolFinder symbolFinder;
+ Function *definitionFunction = 0;
QString prefix, suffix;
Declaration *surroundingFunctionDecl = 0;
for (int i = declIndex - 1; i >= 0; --i) {
Symbol *s = klass->memberAt(i);
surroundingFunctionDecl = isNonVirtualFunctionDeclaration(s);
- if (surroundingFunctionDecl) {
- prefix = QLatin1String("\n\n");
- break;
+ if (!surroundingFunctionDecl)
+ continue;
+ if ((definitionFunction = symbolFinder.findMatchingDefinition(surroundingFunctionDecl,
+ changes.snapshot())))
+ {
+ if (destinationFile.isEmpty() || destinationFile == QString::fromUtf8(
+ definitionFunction->fileName(), definitionFunction->fileNameLength())) {
+ prefix = QLatin1String("\n\n");
+ break;
+ }
+ definitionFunction = 0;
}
}
- if (!surroundingFunctionDecl) {
+ if (!definitionFunction) {
// try to find one below
for (unsigned i = declIndex + 1; i < klass->memberCount(); ++i) {
Symbol *s = klass->memberAt(i);
surroundingFunctionDecl = isNonVirtualFunctionDeclaration(s);
- if (surroundingFunctionDecl) {
- suffix = QLatin1String("\n\n");
- break;
+ if (!surroundingFunctionDecl)
+ continue;
+ if ((definitionFunction = symbolFinder.findMatchingDefinition(surroundingFunctionDecl,
+ changes.snapshot())))
+ {
+ if (destinationFile.isEmpty() || destinationFile == QString::fromUtf8(
+ definitionFunction->fileName(), definitionFunction->fileNameLength())) {
+ suffix = QLatin1String("\n\n");
+ break;
+ }
+ definitionFunction = 0;
}
}
- if (!surroundingFunctionDecl)
- return noResult;
}
- // find the declaration's definition
- CppTools::SymbolFinder symbolFinder;
- Function *definitionFunction = symbolFinder.findMatchingDefinition(surroundingFunctionDecl,
- changes.snapshot());
if (!definitionFunction)
return noResult;
@@ -546,7 +560,8 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration, const
}
QList<InsertionLocation> InsertionPointLocator::methodDefinition(Symbol *declaration,
- bool useSymbolFinder) const
+ bool useSymbolFinder,
+ const QString &destinationFile) const
{
QList<InsertionLocation> result;
if (!declaration)
@@ -558,7 +573,9 @@ QList<InsertionLocation> InsertionPointLocator::methodDefinition(Symbol *declara
return result;
}
- const InsertionLocation location = nextToSurroundingDefinitions(declaration, m_refactoringChanges);
+ const InsertionLocation location = nextToSurroundingDefinitions(declaration,
+ m_refactoringChanges,
+ destinationFile);
if (location.isValid()) {
result += location;
return result;