summaryrefslogtreecommitdiff
path: root/src/plugins/clangrefactoring
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2016-08-04 15:26:53 +0200
committerMarco Bubke <marco.bubke@qt.io>2016-08-04 14:37:19 +0000
commit4cdb5bab157bfec52ece3a2ed6dd1ace82f80265 (patch)
tree091c985e8ffcb17171475239e7838ad3b20cbbb4 /src/plugins/clangrefactoring
parent2b9edb35ea85e3fdc56f112d7d73021ea47ece08 (diff)
downloadqt-creator-4cdb5bab157bfec52ece3a2ed6dd1ace82f80265.tar.gz
Clang: Add clang refactoring
Change-Id: I2e3f36f810276da3f8dc7dcc587b06f8edb586d3 GPush-Base: d02f51b48fc752fddcdef6dcb32b3f7f6c0195a3 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src/plugins/clangrefactoring')
-rw-r--r--src/plugins/clangrefactoring/ClangRefactoring.json.in20
-rw-r--r--src/plugins/clangrefactoring/clangrefactoring-source.pri13
-rw-r--r--src/plugins/clangrefactoring/clangrefactoring.pro12
-rw-r--r--src/plugins/clangrefactoring/clangrefactoring_dependencies.pri9
-rw-r--r--src/plugins/clangrefactoring/clangrefactoringplugin.cpp91
-rw-r--r--src/plugins/clangrefactoring/clangrefactoringplugin.h61
-rw-r--r--src/plugins/clangrefactoring/refactoringclient.cpp61
-rw-r--r--src/plugins/clangrefactoring/refactoringclient.h52
-rw-r--r--src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.cpp153
-rw-r--r--src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.h59
-rw-r--r--src/plugins/clangrefactoring/refactoringconnectionclient.cpp74
-rw-r--r--src/plugins/clangrefactoring/refactoringconnectionclient.h52
-rw-r--r--src/plugins/clangrefactoring/refactoringengine.cpp118
-rw-r--r--src/plugins/clangrefactoring/refactoringengine.h57
14 files changed, 832 insertions, 0 deletions
diff --git a/src/plugins/clangrefactoring/ClangRefactoring.json.in b/src/plugins/clangrefactoring/ClangRefactoring.json.in
new file mode 100644
index 0000000000..901a5b860a
--- /dev/null
+++ b/src/plugins/clangrefactoring/ClangRefactoring.json.in
@@ -0,0 +1,20 @@
+{
+ \"Name\" : \"ClangRefactoring\",
+ \"Version\" : \"$$QTCREATOR_VERSION\",
+ \"CompatVersion\" : \"$$QTCREATOR_COMPAT_VERSION\",
+ \"Experimental\" : true,
+ \"Vendor\" : \"The Qt Company Ltd\",
+ \"Copyright\" : \"(C) 2016 The Qt Company Ltd\",
+ \"License\" : [ \"Commercial Usage\",
+ \"\",
+ \"Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and The Qt Company.\",
+ \"\",
+ \"GNU General Public License Usage\",
+ \"\",
+ \"Alternatively, this plugin may be used under the terms of the GNU General Public License version 3 as published by the Free Software Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT included in the packaging of this plugin. Please review the following information to ensure the GNU General Public License requirements will be met: https://www.gnu.org/licenses/gpl-3.0.html.\"
+ ],
+ \"Category\" : \"C++\",
+ \"Description\" : \"Clang Refactoring plugin.\",
+ \"Url\" : \"http://www.qt.io\",
+ $$dependencyList
+}
diff --git a/src/plugins/clangrefactoring/clangrefactoring-source.pri b/src/plugins/clangrefactoring/clangrefactoring-source.pri
new file mode 100644
index 0000000000..61048f6fe8
--- /dev/null
+++ b/src/plugins/clangrefactoring/clangrefactoring-source.pri
@@ -0,0 +1,13 @@
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+ $$PWD/refactoringengine.h \
+ $$PWD/refactoringconnectionclient.h \
+ $$PWD/refactoringcompileroptionsbuilder.h \
+ $$PWD/refactoringclient.h
+
+SOURCES += \
+ $$PWD/refactoringengine.cpp \
+ $$PWD/refactoringconnectionclient.cpp \
+ $$PWD/refactoringcompileroptionsbuilder.cpp \
+ $$PWD/refactoringclient.cpp
diff --git a/src/plugins/clangrefactoring/clangrefactoring.pro b/src/plugins/clangrefactoring/clangrefactoring.pro
new file mode 100644
index 0000000000..3716c86b93
--- /dev/null
+++ b/src/plugins/clangrefactoring/clangrefactoring.pro
@@ -0,0 +1,12 @@
+include(../../qtcreatorplugin.pri)
+include(clangrefactoring-source.pri)
+include(../../shared/clang/clang_installation.pri)
+
+DEFINES += CLANG_VERSION=\\\"$${LLVM_VERSION}\\\"
+DEFINES += "\"CLANG_RESOURCE_DIR=\\\"$${LLVM_LIBDIR}/clang/$${LLVM_VERSION}/include\\\"\""
+
+HEADERS += \
+ $$PWD/clangrefactoringplugin.h
+
+SOURCES += \
+ $$PWD/clangrefactoringplugin.cpp
diff --git a/src/plugins/clangrefactoring/clangrefactoring_dependencies.pri b/src/plugins/clangrefactoring/clangrefactoring_dependencies.pri
new file mode 100644
index 0000000000..7426f517e2
--- /dev/null
+++ b/src/plugins/clangrefactoring/clangrefactoring_dependencies.pri
@@ -0,0 +1,9 @@
+QTC_PLUGIN_NAME = ClangRefactoring
+QTC_LIB_DEPENDS += \
+ utils \
+ clangbackendipc
+QTC_PLUGIN_DEPENDS += \
+ coreplugin \
+ cpptools \
+ texteditor
+
diff --git a/src/plugins/clangrefactoring/clangrefactoringplugin.cpp b/src/plugins/clangrefactoring/clangrefactoringplugin.cpp
new file mode 100644
index 0000000000..5db81cb46d
--- /dev/null
+++ b/src/plugins/clangrefactoring/clangrefactoringplugin.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "clangrefactoringplugin.h"
+
+#include <cpptools/cppmodelmanager.h>
+
+#include <coreplugin/icore.h>
+
+#include <utils/hostosinfo.h>
+
+namespace ClangRefactoring {
+
+namespace {
+
+QString backendProcessPath()
+{
+ return Core::ICore::libexecPath()
+ + QStringLiteral("/clangrefactoringbackend")
+ + QStringLiteral(QTC_HOST_EXE_SUFFIX);
+}
+
+} // anonymous namespace
+
+RefactoringClient ClangRefactoringPlugin::client;
+ClangBackEnd::RefactoringConnectionClient ClangRefactoringPlugin::connectionClient(&client);
+RefactoringEngine ClangRefactoringPlugin::engine(connectionClient.serverProxy(), client);
+
+bool ClangRefactoringPlugin::initialize(const QStringList &/*arguments*/, QString */*errorMessage*/)
+{
+ client.setRefactoringEngine(&engine);
+
+ connectBackend();
+ startBackend();
+
+ return true;
+}
+
+void ClangRefactoringPlugin::extensionsInitialized()
+{
+ CppTools::CppModelManager::setRefactoringEngine(&refactoringEngine());
+}
+
+RefactoringEngine &ClangRefactoringPlugin::refactoringEngine()
+{
+ return engine;
+}
+
+void ClangRefactoringPlugin::startBackend()
+{
+ connectionClient.setProcessPath(backendProcessPath());
+
+ connectionClient.startProcessAndConnectToServerAsynchronously();
+}
+
+void ClangRefactoringPlugin::connectBackend()
+{
+ connect(&connectionClient,
+ &ClangBackEnd::RefactoringConnectionClient::connectedToLocalSocket,
+ this,
+ &ClangRefactoringPlugin::backendIsConnected);
+}
+
+void ClangRefactoringPlugin::backendIsConnected()
+{
+ engine.setUsable(true);
+}
+
+} // namespace ClangRefactoring
diff --git a/src/plugins/clangrefactoring/clangrefactoringplugin.h b/src/plugins/clangrefactoring/clangrefactoringplugin.h
new file mode 100644
index 0000000000..892683f67f
--- /dev/null
+++ b/src/plugins/clangrefactoring/clangrefactoringplugin.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "refactoringengine.h"
+#include "refactoringclient.h"
+
+#include <refactoringconnectionclient.h>
+#include <refactoringserverproxy.h>
+
+#include <extensionsystem/iplugin.h>
+
+
+namespace ClangRefactoring {
+
+class ClangRefactoringPlugin : public ExtensionSystem::IPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ClangRefactoring.json")
+
+public:
+ bool initialize(const QStringList &arguments, QString *errorMessage);
+ void extensionsInitialized();
+
+ static RefactoringEngine &refactoringEngine();
+
+private:
+ void startBackend();
+ void connectBackend();
+ void backendIsConnected();
+
+private:
+ static ClangBackEnd::RefactoringConnectionClient connectionClient;
+ static RefactoringClient client;
+ static RefactoringEngine engine;
+};
+
+} // namespace ClangRefactoring
diff --git a/src/plugins/clangrefactoring/refactoringclient.cpp b/src/plugins/clangrefactoring/refactoringclient.cpp
new file mode 100644
index 0000000000..015e67ac9e
--- /dev/null
+++ b/src/plugins/clangrefactoring/refactoringclient.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "refactoringclient.h"
+
+#include <sourcelocationsforrenamingmessage.h>
+
+namespace ClangRefactoring {
+
+void RefactoringClient::alive()
+{
+
+}
+
+void RefactoringClient::sourceLocationsForRenamingMessage(ClangBackEnd::SourceLocationsForRenamingMessage &&message)
+{
+ localRenamingCallback(message.symbolName().toQString(),
+ message.sourceLocations(),
+ message.textDocumentRevision());
+
+ refactoringEngine->setUsable(true);
+}
+
+void RefactoringClient::setLocalRenamingCallback(CppTools::RefactoringEngineInterface::RenameCallback &&localRenamingCallback)
+{
+ this->localRenamingCallback = std::move(localRenamingCallback);
+}
+
+void RefactoringClient::setRefactoringEngine(RefactoringEngine *refactoringEngine)
+{
+ this->refactoringEngine = refactoringEngine;
+}
+
+bool RefactoringClient::hasValidLocalRenamingCallback() const
+{
+ return bool(localRenamingCallback);
+}
+
+} // namespace ClangRefactoring
diff --git a/src/plugins/clangrefactoring/refactoringclient.h b/src/plugins/clangrefactoring/refactoringclient.h
new file mode 100644
index 0000000000..82f162c1f3
--- /dev/null
+++ b/src/plugins/clangrefactoring/refactoringclient.h
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "refactoringengine.h"
+
+#include <refactoringclientinterface.h>
+
+#include <functional>
+
+namespace ClangRefactoring {
+
+class RefactoringClient : public ClangBackEnd::RefactoringClientInterface
+{
+public:
+ void alive() override;
+ void sourceLocationsForRenamingMessage(ClangBackEnd::SourceLocationsForRenamingMessage &&message) override;
+
+ void setLocalRenamingCallback(CppTools::RefactoringEngineInterface::RenameCallback &&localRenamingCallback);
+ void setRefactoringEngine(ClangRefactoring::RefactoringEngine *refactoringEngine);
+
+ bool hasValidLocalRenamingCallback() const;
+
+private:
+ CppTools::RefactoringEngineInterface::RenameCallback localRenamingCallback;
+ ClangRefactoring::RefactoringEngine *refactoringEngine = nullptr;
+};
+
+} // namespace ClangRefactoring
diff --git a/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.cpp b/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.cpp
new file mode 100644
index 0000000000..6546e9b950
--- /dev/null
+++ b/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.cpp
@@ -0,0 +1,153 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "refactoringcompileroptionsbuilder.h"
+
+namespace ClangRefactoring {
+
+namespace {
+
+QString getCreatorResourcePath()
+{
+#ifndef UNIT_TESTS
+ return Core::ICore::instance()->resourcePath();
+#else
+ return QString();
+#endif
+}
+
+QString getClangIncludeDirectory()
+{
+ QDir dir(getCreatorResourcePath() + QLatin1String("/cplusplus/clang/") +
+ QLatin1String(CLANG_VERSION) + QLatin1String("/include"));
+ if (!dir.exists() || !QFileInfo(dir, QLatin1String("stdint.h")).exists())
+ dir = QDir(QLatin1String(CLANG_RESOURCE_DIR));
+ return dir.canonicalPath();
+}
+
+}
+
+RefactoringCompilerOptionsBuilder::RefactoringCompilerOptionsBuilder(CppTools::ProjectPart *projectPart)
+ : CompilerOptionsBuilder(*projectPart)
+{
+}
+
+bool RefactoringCompilerOptionsBuilder::excludeHeaderPath(const QString &path) const
+{
+ if (path.contains(QLatin1String("lib/gcc/i686-apple-darwin")))
+ return true;
+
+ // We already provide a custom clang include path matching the used libclang version,
+ // so better ignore the clang include paths from the system as this might lead to an
+ // unfavorable order with regard to include_next.
+ static QRegularExpression clangIncludeDir(
+ QLatin1String("\\A.*/lib/clang/\\d+\\.\\d+(\\.\\d+)?/include\\z"));
+ if (clangIncludeDir.match(path).hasMatch())
+ return true;
+
+ return false;
+}
+
+void RefactoringCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptions()
+{
+ if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
+ addPredefinedMacrosAndHeaderPathsOptionsForMsvc();
+ else
+ addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc();
+}
+
+void RefactoringCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptionsForMsvc()
+{
+ add(QLatin1String("-nostdinc"));
+ add(QLatin1String("-undef"));
+}
+
+void RefactoringCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc()
+{
+ static const QString resourceDir = getClangIncludeDirectory();
+ if (!resourceDir.isEmpty()) {
+ add(QLatin1String("-nostdlibinc"));
+ add(QLatin1String("-I") + resourceDir);
+ add(QLatin1String("-undef"));
+ }
+}
+
+void RefactoringCompilerOptionsBuilder::addWrappedQtHeadersIncludePath()
+{
+ static const QString wrappedQtHeaders = getCreatorResourcePath()
+ + QStringLiteral("/cplusplus/wrappedQtHeaders");
+
+ if (m_projectPart.qtVersion != CppTools::ProjectPart::NoQt) {
+ add(QLatin1String("-I") + wrappedQtHeaders);
+ add(QLatin1String("-I") + wrappedQtHeaders + QLatin1String("/QtCore"));
+ }
+}
+
+void RefactoringCompilerOptionsBuilder::addProjectConfigFileInclude()
+{
+ if (!m_projectPart.projectConfigFile.isEmpty()) {
+ add(QLatin1String("-include"));
+ add(m_projectPart.projectConfigFile);
+ }
+}
+
+void RefactoringCompilerOptionsBuilder::addExtraOptions()
+{
+ add(QLatin1String("-fmessage-length=0"));
+ add(QLatin1String("-fdiagnostics-show-note-include-stack"));
+ add(QLatin1String("-fmacro-backtrace-limit=0"));
+ add(QLatin1String("-fretain-comments-from-system-headers"));
+ add(QLatin1String("-ferror-limit=1000"));
+}
+
+Utils::SmallStringVector RefactoringCompilerOptionsBuilder::build(CppTools::ProjectPart *projectPart,
+ CppTools::ProjectFile::Kind fileKind)
+{
+ if (projectPart == nullptr)
+ return Utils::SmallStringVector();
+
+ RefactoringCompilerOptionsBuilder optionsBuilder(projectPart);
+
+ optionsBuilder.addTargetTriple();
+ optionsBuilder.addLanguageOption(fileKind);
+ optionsBuilder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
+ optionsBuilder.enableExceptions();
+
+ optionsBuilder.addToolchainAndProjectDefines();
+ optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015();
+
+ optionsBuilder.addPredefinedMacrosAndHeaderPathsOptions();
+ optionsBuilder.addWrappedQtHeadersIncludePath();
+ optionsBuilder.addHeaderPathOptions();
+ optionsBuilder.addProjectConfigFileInclude();
+
+ optionsBuilder.addMsvcCompatibilityVersion();
+
+ optionsBuilder.addExtraOptions();
+
+ return Utils::SmallStringVector(optionsBuilder.options());
+}
+
+} // namespace ClangRefactoring
diff --git a/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.h b/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.h
new file mode 100644
index 0000000000..f0f0dcc016
--- /dev/null
+++ b/src/plugins/clangrefactoring/refactoringcompileroptionsbuilder.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <cpptools/compileroptionsbuilder.h>
+
+#include <utils/smallstringvector.h>
+
+#include <projectexplorer/projectexplorerconstants.h>
+
+#include <coreplugin/icore.h>
+
+#include <QDir>
+#include <QRegularExpression>
+
+namespace ClangRefactoring {
+
+class RefactoringCompilerOptionsBuilder : public CppTools::CompilerOptionsBuilder
+{
+public:
+ static Utils::SmallStringVector build(CppTools::ProjectPart *projectPart,
+ CppTools::ProjectFile::Kind fileKind);
+
+private:
+ RefactoringCompilerOptionsBuilder(CppTools::ProjectPart *projectPart);
+
+ bool excludeHeaderPath(const QString &path) const override;
+ void addPredefinedMacrosAndHeaderPathsOptions();
+ void addPredefinedMacrosAndHeaderPathsOptionsForMsvc();
+ void addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc();
+ void addWrappedQtHeadersIncludePath();
+ void addProjectConfigFileInclude();
+ void addExtraOptions();
+};
+
+} // namespace ClangRefactoring
diff --git a/src/plugins/clangrefactoring/refactoringconnectionclient.cpp b/src/plugins/clangrefactoring/refactoringconnectionclient.cpp
new file mode 100644
index 0000000000..2d05722b19
--- /dev/null
+++ b/src/plugins/clangrefactoring/refactoringconnectionclient.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "refactoringconnectionclient.h"
+
+#include <QCoreApplication>
+#include <QTemporaryDir>
+
+namespace ClangBackEnd {
+
+namespace {
+
+QString currentProcessId()
+{
+ return QString::number(QCoreApplication::applicationPid());
+}
+
+}
+
+RefactoringConnectionClient::RefactoringConnectionClient(RefactoringClientInterface *client)
+ : serverProxy_(client, ioDevice())
+{
+ stdErrPrefixer().setPrefix("RefactoringConnectionClient.error:");
+ stdOutPrefixer().setPrefix("RefactoringConnectionClient.out:");
+}
+
+RefactoringServerProxy &RefactoringConnectionClient::serverProxy()
+{
+ return serverProxy_;
+}
+
+void RefactoringConnectionClient::sendEndCommand()
+{
+ serverProxy_.end();
+}
+
+void RefactoringConnectionClient::resetCounter()
+{
+ serverProxy_.resetCounter();
+}
+
+QString RefactoringConnectionClient::connectionName() const
+{
+ return temporaryDirectory().path() + QStringLiteral("/ClangRefactoringBackEnd-") + currentProcessId();
+}
+
+QString RefactoringConnectionClient::outputName() const
+{
+ return QStringLiteral("RefactoringConnectionClient");
+}
+
+} // namespace ClangBackEnd
diff --git a/src/plugins/clangrefactoring/refactoringconnectionclient.h b/src/plugins/clangrefactoring/refactoringconnectionclient.h
new file mode 100644
index 0000000000..d1271bb6ba
--- /dev/null
+++ b/src/plugins/clangrefactoring/refactoringconnectionclient.h
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <connectionclient.h>
+#include <refactoringserverproxy.h>
+
+namespace ClangBackEnd {
+
+class RefactoringClientInterface;
+
+class RefactoringConnectionClient : public ConnectionClient
+{
+public:
+ RefactoringConnectionClient(RefactoringClientInterface *client);
+
+ RefactoringServerProxy &serverProxy();
+
+protected:
+ void sendEndCommand() override;
+ void resetCounter() override;
+ QString connectionName() const override;
+ QString outputName() const override;
+
+private:
+ RefactoringServerProxy serverProxy_;
+};
+
+} // namespace ClangBackEnd
diff --git a/src/plugins/clangrefactoring/refactoringengine.cpp b/src/plugins/clangrefactoring/refactoringengine.cpp
new file mode 100644
index 0000000000..fe33c82c09
--- /dev/null
+++ b/src/plugins/clangrefactoring/refactoringengine.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "refactoringengine.h"
+
+#include <refactoringcompileroptionsbuilder.h>
+
+#include <refactoringserverinterface.h>
+#include <requestsourcelocationforrenamingmessage.h>
+
+#include <QTextCursor>
+#include <QTextDocument>
+
+#include <algorithm>
+
+namespace ClangRefactoring {
+
+using ClangBackEnd::RequestSourceLocationsForRenamingMessage;
+
+RefactoringEngine::RefactoringEngine(ClangBackEnd::RefactoringServerInterface &server,
+ ClangBackEnd::RefactoringClientInterface &client)
+ : server(server),
+ client(client)
+{
+}
+
+namespace {
+
+ClangBackEnd::FilePath convertToClangBackEndFilePath(const Utils::FileName &filePath)
+{
+ Utils::SmallString utf8FilePath = filePath.toString();
+
+ auto found = std::find(utf8FilePath.rbegin(), utf8FilePath.rend(), '/').base();
+
+ Utils::SmallString fileName(found, utf8FilePath.end());
+ utf8FilePath.resize(std::size_t(std::distance(utf8FilePath.begin(), --found)));
+
+ return ClangBackEnd::FilePath(std::move(utf8FilePath), std::move(fileName));
+}
+
+CppTools::ProjectFile::Kind fileKind(CppTools::ProjectPart *projectPart, const QString &filePath)
+{
+ const auto &projectFiles = projectPart->files;
+
+ auto comparePaths = [&] (const CppTools::ProjectFile &projectFile) {
+ return projectFile.path == filePath;
+ };
+
+ auto found = std::find_if(projectFiles.begin(), projectFiles.end(), comparePaths);
+
+ if (found != projectFiles.end())
+ return found->kind;
+
+ return CppTools::ProjectFile::Unclassified;
+}
+
+}
+
+void RefactoringEngine::startLocalRenaming(const QTextCursor &textCursor,
+ const Utils::FileName &filePath,
+ int revision,
+ CppTools::ProjectPart *projectPart,
+ RenameCallback &&renameSymbolsCallback)
+{
+ isUsable_ = false;
+
+ client.setLocalRenamingCallback(std::move(renameSymbolsCallback));
+
+ auto commandLine = RefactoringCompilerOptionsBuilder::build(projectPart,
+ fileKind(projectPart, filePath.toString()));
+
+ commandLine.push_back(filePath.toString());
+ qDebug() << commandLine.join(" ");
+
+ RequestSourceLocationsForRenamingMessage message(convertToClangBackEndFilePath(filePath),
+ uint(textCursor.blockNumber() + 1),
+ uint(textCursor.positionInBlock() + 1),
+ textCursor.document()->toPlainText(),
+ std::move(commandLine),
+ revision);
+
+
+ server.requestSourceLocationsForRenamingMessage(std::move(message));
+}
+
+bool RefactoringEngine::isUsable() const
+{
+ return isUsable_;
+}
+
+void RefactoringEngine::setUsable(bool isUsable)
+{
+ isUsable_ = isUsable;
+}
+
+} // namespace ClangRefactoring
diff --git a/src/plugins/clangrefactoring/refactoringengine.h b/src/plugins/clangrefactoring/refactoringengine.h
new file mode 100644
index 0000000000..4e577e0b51
--- /dev/null
+++ b/src/plugins/clangrefactoring/refactoringengine.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <cpptools/refactoringengineinterface.h>
+
+namespace ClangBackEnd {
+class RefactoringClientInterface;
+class RefactoringServerInterface;
+}
+
+namespace ClangRefactoring {
+
+class RefactoringEngine : public CppTools::RefactoringEngineInterface
+{
+public:
+ RefactoringEngine(ClangBackEnd::RefactoringServerInterface &server,
+ ClangBackEnd::RefactoringClientInterface &client);
+ void startLocalRenaming(const QTextCursor &textCursor,
+ const Utils::FileName &filePath,
+ int revision,
+ CppTools::ProjectPart *projectPart,
+ RenameCallback &&renameSymbolsCallback) override;
+
+ bool isUsable() const override;
+ void setUsable(bool isUsable);
+
+private:
+ ClangBackEnd::RefactoringServerInterface &server;
+ ClangBackEnd::RefactoringClientInterface &client;
+ bool isUsable_ = false;
+};
+
+} // namespace ClangRefactoring