forked from qt-creator/qt-creator
CppEditor: Fix possible wrong location for function definitions
Having no namespace when inserting generated functions may insert explicitly at the end of a header which is not always desired as we need to take care of e.g. header guards as well. Change-Id: I3b154ae936a96f2f8e7e34cda6b5bcdfcbc83faf Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
committed by
Christian Kandeler
parent
d3d683ec63
commit
1e0b82e77d
@@ -226,10 +226,21 @@ InsertionLocation insertLocationForMethodDefinition(Symbol *symbol, const bool u
|
||||
const InsertionPointLocator locator(refactoring);
|
||||
const QList<InsertionLocation> list
|
||||
= locator.methodDefinition(symbol, useSymbolFinder, fileName);
|
||||
for (int i = 0; i < list.count(); ++i) {
|
||||
const bool isHeader = ProjectFile::isHeader(ProjectFile::classify(fileName));
|
||||
const bool hasIncludeGuard = isHeader
|
||||
&& !file->cppDocument()->includeGuardMacroName().isEmpty();
|
||||
int lastLine;
|
||||
if (hasIncludeGuard) {
|
||||
const TranslationUnit * const tu = file->cppDocument()->translationUnit();
|
||||
tu->getTokenStartPosition(tu->ast()->lastToken(), &lastLine);
|
||||
}
|
||||
int i = 0;
|
||||
for ( ; i < list.count(); ++i) {
|
||||
InsertionLocation location = list.at(i);
|
||||
if (!location.isValid() || location.fileName() != fileName)
|
||||
continue;
|
||||
if (hasIncludeGuard && location.line() == lastLine)
|
||||
continue;
|
||||
if (!requiredNamespaces.isEmpty()) {
|
||||
NSVisitor visitor(file.data(), requiredNamespaces,
|
||||
file->position(location.line(), location.column()));
|
||||
|
||||
Reference in New Issue
Block a user