diff --git a/src/plugins/cppeditor/cppinsertdecldef.cpp b/src/plugins/cppeditor/cppinsertdecldef.cpp index 6e2d51ab9af0491f5f4edbddaae1c78c08bfe928..cc8b93201d9dd7ea76cba5dd5644c7439af857ca 100644 --- a/src/plugins/cppeditor/cppinsertdecldef.cpp +++ b/src/plugins/cppeditor/cppinsertdecldef.cpp @@ -146,7 +146,7 @@ QList<CppQuickFixOperation::Ptr> DeclFromDef::match(const CppQuickFixState &stat foreach (Symbol *s, targetBinding->symbols()) { if (Class *clazz = s->asClass()) { QList<CppQuickFixOperation::Ptr> results; - const QLatin1String fn(clazz->fileName()); + const QString fn = QString::fromUtf8(clazz->fileName(), clazz->fileNameLength()); const QString decl = generateDeclaration(state, method, targetBinding); diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp index 90d234560b629d390c7b235d343259d31560eb7d..c3c00c1705fc72ecf9d37296911cb81c053a69d4 100644 --- a/src/plugins/cpptools/cpptoolsplugin.cpp +++ b/src/plugins/cpptools/cpptoolsplugin.cpp @@ -264,7 +264,6 @@ QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) co const QString privateHeaderSuffix = QLatin1String("_p"); const QChar dot = QLatin1Char('.'); - QStringList candidates; // Check base matches 'source.h'-> 'source.cpp' and vice versa const QStringList::const_iterator scend = suffixes.constEnd(); for (QStringList::const_iterator it = suffixes.constBegin(); it != scend; ++it) { diff --git a/src/plugins/cpptools/insertionpointlocator.cpp b/src/plugins/cpptools/insertionpointlocator.cpp index f1594b9860453b2761ad2b2fc6a264a29148cf20..8d924a37fbd6fe5589df4c35ba0088064e259141 100644 --- a/src/plugins/cpptools/insertionpointlocator.cpp +++ b/src/plugins/cpptools/insertionpointlocator.cpp @@ -35,6 +35,9 @@ #include <ASTVisitor.h> #include <TranslationUnit.h> +#include <coreplugin/icore.h> +#include <coreplugin/mimedatabase.h> + using namespace CPlusPlus; using namespace CppTools; @@ -298,6 +301,19 @@ InsertionLocation InsertionPointLocator::methodDeclarationInClass( } } +static bool isSourceFile(const QString &fileName) +{ + const Core::MimeDatabase *mimeDb = Core::ICore::instance()->mimeDatabase(); + Core::MimeType cSourceTy = mimeDb->findByType(QLatin1String("text/x-csrc")); + Core::MimeType cppSourceTy = mimeDb->findByType(QLatin1String("text/x-c++src")); + Core::MimeType mSourceTy = mimeDb->findByType(QLatin1String("text/x-objcsrc")); + QStringList suffixes = cSourceTy.suffixes(); + suffixes += cppSourceTy.suffixes(); + suffixes += mSourceTy.suffixes(); + QFileInfo fileInfo(fileName); + return suffixes.contains(fileInfo.suffix()); +} + /// Currently, we return the end of fileName.cpp QList<InsertionLocation> InsertionPointLocator::methodDefinition( Declaration *declaration) const @@ -306,10 +322,14 @@ QList<InsertionLocation> InsertionPointLocator::methodDefinition( if (!declaration) return result; - Internal::CppToolsPlugin *cpptools = Internal::CppToolsPlugin::instance(); + const QString declFileName = QString::fromUtf8(declaration->fileName(), + declaration->fileNameLength()); + QString target = declFileName; + if (!isSourceFile(declFileName)) { + Internal::CppToolsPlugin *cpptools = Internal::CppToolsPlugin::instance(); + target = cpptools->correspondingHeaderOrSource(declFileName); + } - const QString declFileName = QLatin1String(declaration->fileName()); - QString target = cpptools->correspondingHeaderOrSource(declFileName); Document::Ptr doc = m_refactoringChanges->file(target).cppDocument(); if (doc.isNull()) return result;