From 1402c067b1cf9c46c2e38190f243e44138deddbe Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Tue, 16 Jun 2015 11:56:00 +0200 Subject: Clang: Rename CodeModelBackEnd in ClangBackEnd Change-Id: I13e8a458634110456375956d4d4da7239c86957f Reviewed-by: Nikolai Kosjar --- .gitignore | 2 +- src/libs/clangbackendipc/clangbackendipc-lib.pri | 73 +++ src/libs/clangbackendipc/clangbackendipc.pro | 2 + src/libs/clangbackendipc/clangbackendipc.qbs | 28 + .../clangbackendipc_dependencies.pri | 3 + src/libs/clangbackendipc/clangbackendipc_global.h | 50 ++ src/libs/clangbackendipc/cmbalivecommand.cpp | 64 ++ src/libs/clangbackendipc/cmbalivecommand.h | 55 ++ .../clangbackendipc/cmbcodecompletedcommand.cpp | 106 ++++ src/libs/clangbackendipc/cmbcodecompletedcommand.h | 74 +++ src/libs/clangbackendipc/cmbcommands.cpp | 108 ++++ src/libs/clangbackendipc/cmbcommands.h | 45 ++ .../clangbackendipc/cmbcompletecodecommand.cpp | 146 +++++ src/libs/clangbackendipc/cmbcompletecodecommand.h | 86 +++ src/libs/clangbackendipc/cmbechocommand.cpp | 92 +++ src/libs/clangbackendipc/cmbechocommand.h | 68 +++ src/libs/clangbackendipc/cmbendcommand.cpp | 71 +++ src/libs/clangbackendipc/cmbendcommand.h | 55 ++ ...cmbregisterprojectsforcodecompletioncommand.cpp | 102 ++++ .../cmbregisterprojectsforcodecompletioncommand.h | 69 +++ ...tertranslationunitsforcodecompletioncommand.cpp | 100 ++++ ...istertranslationunitsforcodecompletioncommand.h | 69 +++ ...bunregisterprojectsforcodecompletioncommand.cpp | 101 ++++ ...cmbunregisterprojectsforcodecompletioncommand.h | 71 +++ ...tertranslationunitsforcodecompletioncommand.cpp | 106 ++++ ...istertranslationunitsforcodecompletioncommand.h | 74 +++ src/libs/clangbackendipc/codecompletion.cpp | 255 ++++++++ src/libs/clangbackendipc/codecompletion.h | 141 +++++ src/libs/clangbackendipc/codecompletionchunk.cpp | 178 ++++++ src/libs/clangbackendipc/codecompletionchunk.h | 105 ++++ src/libs/clangbackendipc/connectionclient.cpp | 288 +++++++++ src/libs/clangbackendipc/connectionclient.h | 113 ++++ src/libs/clangbackendipc/connectionserver.cpp | 150 +++++ src/libs/clangbackendipc/connectionserver.h | 83 +++ src/libs/clangbackendipc/container_common.h | 62 ++ src/libs/clangbackendipc/filecontainer.cpp | 136 +++++ src/libs/clangbackendipc/filecontainer.h | 79 +++ src/libs/clangbackendipc/ipcclientdispatcher.cpp | 78 +++ src/libs/clangbackendipc/ipcclientdispatcher.h | 58 ++ src/libs/clangbackendipc/ipcclientinterface.cpp | 69 +++ src/libs/clangbackendipc/ipcclientinterface.h | 63 ++ src/libs/clangbackendipc/ipcclientproxy.cpp | 114 ++++ src/libs/clangbackendipc/ipcclientproxy.h | 80 +++ src/libs/clangbackendipc/ipcinterface.cpp | 40 ++ src/libs/clangbackendipc/ipcinterface.h | 53 ++ src/libs/clangbackendipc/ipcserver.cpp | 46 ++ src/libs/clangbackendipc/ipcserver.h | 47 ++ src/libs/clangbackendipc/ipcserverinterface.cpp | 87 +++ src/libs/clangbackendipc/ipcserverinterface.h | 65 ++ src/libs/clangbackendipc/ipcserverproxy.cpp | 100 ++++ src/libs/clangbackendipc/ipcserverproxy.h | 78 +++ src/libs/clangbackendipc/projectpartcontainer.cpp | 107 ++++ src/libs/clangbackendipc/projectpartcontainer.h | 73 +++ .../projectpartsdonotexistcommand.cpp | 99 +++ .../projectpartsdonotexistcommand.h | 72 +++ src/libs/clangbackendipc/readcommandblock.cpp | 113 ++++ src/libs/clangbackendipc/readcommandblock.h | 66 ++ .../translationunitdoesnotexistcommand.cpp | 112 ++++ .../translationunitdoesnotexistcommand.h | 73 +++ src/libs/clangbackendipc/writecommandblock.cpp | 78 +++ src/libs/clangbackendipc/writecommandblock.h | 62 ++ src/libs/codemodelbackendipc/cmbalivecommand.cpp | 64 -- src/libs/codemodelbackendipc/cmbalivecommand.h | 55 -- .../cmbcodecompletedcommand.cpp | 106 ---- .../codemodelbackendipc/cmbcodecompletedcommand.h | 74 --- src/libs/codemodelbackendipc/cmbcommands.cpp | 108 ---- src/libs/codemodelbackendipc/cmbcommands.h | 45 -- .../codemodelbackendipc/cmbcompletecodecommand.cpp | 146 ----- .../codemodelbackendipc/cmbcompletecodecommand.h | 86 --- src/libs/codemodelbackendipc/cmbechocommand.cpp | 92 --- src/libs/codemodelbackendipc/cmbechocommand.h | 68 --- src/libs/codemodelbackendipc/cmbendcommand.cpp | 71 --- src/libs/codemodelbackendipc/cmbendcommand.h | 55 -- ...cmbregisterprojectsforcodecompletioncommand.cpp | 102 ---- .../cmbregisterprojectsforcodecompletioncommand.h | 69 --- ...tertranslationunitsforcodecompletioncommand.cpp | 100 ---- ...istertranslationunitsforcodecompletioncommand.h | 69 --- ...bunregisterprojectsforcodecompletioncommand.cpp | 101 ---- ...cmbunregisterprojectsforcodecompletioncommand.h | 71 --- ...tertranslationunitsforcodecompletioncommand.cpp | 106 ---- ...istertranslationunitsforcodecompletioncommand.h | 74 --- src/libs/codemodelbackendipc/codecompletion.cpp | 255 -------- src/libs/codemodelbackendipc/codecompletion.h | 141 ----- .../codemodelbackendipc/codecompletionchunk.cpp | 178 ------ src/libs/codemodelbackendipc/codecompletionchunk.h | 105 ---- .../codemodelbackendipc-lib.pri | 73 --- .../codemodelbackendipc/codemodelbackendipc.pro | 2 - .../codemodelbackendipc/codemodelbackendipc.qbs | 28 - .../codemodelbackendipc_dependencies.pri | 3 - .../codemodelbackendipc_global.cpp | 37 -- .../codemodelbackendipc_global.h | 50 -- src/libs/codemodelbackendipc/connectionclient.cpp | 288 --------- src/libs/codemodelbackendipc/connectionclient.h | 113 ---- src/libs/codemodelbackendipc/connectionserver.cpp | 150 ----- src/libs/codemodelbackendipc/connectionserver.h | 83 --- src/libs/codemodelbackendipc/container_common.h | 62 -- src/libs/codemodelbackendipc/filecontainer.cpp | 136 ----- src/libs/codemodelbackendipc/filecontainer.h | 79 --- .../codemodelbackendipc/ipcclientdispatcher.cpp | 78 --- src/libs/codemodelbackendipc/ipcclientdispatcher.h | 58 -- .../codemodelbackendipc/ipcclientinterface.cpp | 69 --- src/libs/codemodelbackendipc/ipcclientinterface.h | 63 -- src/libs/codemodelbackendipc/ipcclientproxy.cpp | 114 ---- src/libs/codemodelbackendipc/ipcclientproxy.h | 80 --- src/libs/codemodelbackendipc/ipcinterface.cpp | 40 -- src/libs/codemodelbackendipc/ipcinterface.h | 53 -- src/libs/codemodelbackendipc/ipcserver.cpp | 46 -- src/libs/codemodelbackendipc/ipcserver.h | 47 -- .../codemodelbackendipc/ipcserverinterface.cpp | 87 --- src/libs/codemodelbackendipc/ipcserverinterface.h | 65 -- src/libs/codemodelbackendipc/ipcserverproxy.cpp | 100 ---- src/libs/codemodelbackendipc/ipcserverproxy.h | 78 --- .../codemodelbackendipc/projectpartcontainer.cpp | 107 ---- .../codemodelbackendipc/projectpartcontainer.h | 73 --- .../projectpartsdonotexistcommand.cpp | 99 --- .../projectpartsdonotexistcommand.h | 72 --- src/libs/codemodelbackendipc/readcommandblock.cpp | 113 ---- src/libs/codemodelbackendipc/readcommandblock.h | 66 -- .../translationunitdoesnotexistcommand.cpp | 112 ---- .../translationunitdoesnotexistcommand.h | 73 --- src/libs/codemodelbackendipc/writecommandblock.cpp | 78 --- src/libs/codemodelbackendipc/writecommandblock.h | 62 -- src/libs/libs.pro | 2 +- src/libs/libs.qbs | 2 +- .../clangcodemodel/clangbackendipcintegration.cpp | 455 ++++++++++++++ .../clangcodemodel/clangbackendipcintegration.h | 157 +++++ src/plugins/clangcodemodel/clangcodemodel.pro | 4 +- src/plugins/clangcodemodel/clangcodemodel.qbs | 6 +- .../clangcodemodel/clangcodemodel_dependencies.pri | 2 +- src/plugins/clangcodemodel/clangcompletion.cpp | 2 +- src/plugins/clangcodemodel/clangcompletion.h | 12 +- .../clangeditordocumentprocessor.cpp | 2 +- .../clangcodemodel/clangmodelmanagersupport.cpp | 8 +- .../codemodelbackendipcintegration.cpp | 455 -------------- .../codemodelbackendipcintegration.h | 157 ----- .../completionchunkstotextconverter.cpp | 10 +- .../completionchunkstotextconverter.h | 10 +- .../test/clangcodecompletion_test.cpp | 16 +- src/tools/clangbackend/clangbackend.pri | 26 + src/tools/clangbackend/clangbackend.pro | 5 + src/tools/clangbackend/clangbackend.qbs | 30 + src/tools/clangbackend/clangbackendmain.cpp | 61 ++ .../ipcsource/clangbackendclangipc-source.pri | 37 ++ .../ipcsource/clangcodecompleteresults.cpp | 72 +++ .../ipcsource/clangcodecompleteresults.h | 63 ++ .../clangbackend/ipcsource/clangipcserver.cpp | 128 ++++ src/tools/clangbackend/ipcsource/clangipcserver.h | 67 +++ src/tools/clangbackend/ipcsource/clangstring.cpp | 74 +++ src/tools/clangbackend/ipcsource/clangstring.h | 62 ++ .../ipcsource/codecompletefailedexception.cpp | 37 ++ .../ipcsource/codecompletefailedexception.h | 41 ++ src/tools/clangbackend/ipcsource/codecompleter.cpp | 78 +++ src/tools/clangbackend/ipcsource/codecompleter.h | 61 ++ .../ipcsource/codecompletionchunkconverter.cpp | 97 +++ .../ipcsource/codecompletionchunkconverter.h | 61 ++ .../ipcsource/codecompletionsextractor.cpp | 285 +++++++++ .../ipcsource/codecompletionsextractor.h | 84 +++ src/tools/clangbackend/ipcsource/projectpart.cpp | 158 +++++ src/tools/clangbackend/ipcsource/projectpart.h | 85 +++ .../ipcsource/projectpartsdonotexistexception.cpp | 56 ++ .../ipcsource/projectpartsdonotexistexception.h | 62 ++ src/tools/clangbackend/ipcsource/projects.cpp | 105 ++++ src/tools/clangbackend/ipcsource/projects.h | 66 ++ .../clangbackend/ipcsource/translationunit.cpp | 230 +++++++ src/tools/clangbackend/ipcsource/translationunit.h | 103 ++++ .../translationunitdoesnotexistexception.cpp | 63 ++ .../translationunitdoesnotexistexception.h | 61 ++ .../translationunitfilenotexitexception.cpp | 56 ++ .../translationunitfilenotexitexception.h | 62 ++ .../ipcsource/translationunitisnullexception.cpp | 42 ++ .../ipcsource/translationunitisnullexception.h | 54 ++ .../translationunitparseerrorexception.cpp | 66 ++ .../ipcsource/translationunitparseerrorexception.h | 64 ++ .../clangbackend/ipcsource/translationunits.cpp | 150 +++++ .../clangbackend/ipcsource/translationunits.h | 74 +++ src/tools/clangbackend/ipcsource/unsavedfiles.cpp | 188 ++++++ src/tools/clangbackend/ipcsource/unsavedfiles.h | 88 +++ src/tools/codemodelbackend/codemodelbackend.pri | 26 - src/tools/codemodelbackend/codemodelbackend.pro | 5 - src/tools/codemodelbackend/codemodelbackend.qbs | 30 - .../codemodelbackend/codemodelbackendmain.cpp | 61 -- .../ipcsource/clangcodecompleteresults.cpp | 72 --- .../ipcsource/clangcodecompleteresults.h | 63 -- .../codemodelbackend/ipcsource/clangipcserver.cpp | 128 ---- .../codemodelbackend/ipcsource/clangipcserver.h | 67 --- .../codemodelbackend/ipcsource/clangstring.cpp | 74 --- src/tools/codemodelbackend/ipcsource/clangstring.h | 62 -- .../ipcsource/codecompletefailedexception.cpp | 37 -- .../ipcsource/codecompletefailedexception.h | 41 -- .../codemodelbackend/ipcsource/codecompleter.cpp | 78 --- .../codemodelbackend/ipcsource/codecompleter.h | 61 -- .../ipcsource/codecompletionchunkconverter.cpp | 97 --- .../ipcsource/codecompletionchunkconverter.h | 61 -- .../ipcsource/codecompletionsextractor.cpp | 285 --------- .../ipcsource/codecompletionsextractor.h | 84 --- .../ipcsource/codemodelbackendclangipc-source.pri | 37 -- .../ipcsource/projectcontainer.cpp | 99 --- .../codemodelbackend/ipcsource/projectcontainer.h | 73 --- .../codemodelbackend/ipcsource/projectpart.cpp | 158 ----- src/tools/codemodelbackend/ipcsource/projectpart.h | 85 --- .../ipcsource/projectpartsdonotexistexception.cpp | 56 -- .../ipcsource/projectpartsdonotexistexception.h | 62 -- src/tools/codemodelbackend/ipcsource/projects.cpp | 105 ---- src/tools/codemodelbackend/ipcsource/projects.h | 66 -- .../codemodelbackend/ipcsource/translationunit.cpp | 230 ------- .../codemodelbackend/ipcsource/translationunit.h | 103 ---- .../translationunitdoesnotexistexception.cpp | 63 -- .../translationunitdoesnotexistexception.h | 61 -- .../translationunitfilenotexitexception.cpp | 56 -- .../translationunitfilenotexitexception.h | 62 -- .../ipcsource/translationunitisnullexception.cpp | 42 -- .../ipcsource/translationunitisnullexception.h | 54 -- .../translationunitparseerrorexception.cpp | 66 -- .../ipcsource/translationunitparseerrorexception.h | 64 -- .../ipcsource/translationunits.cpp | 150 ----- .../codemodelbackend/ipcsource/translationunits.h | 74 --- .../codemodelbackend/ipcsource/unsavedfiles.cpp | 188 ------ .../codemodelbackend/ipcsource/unsavedfiles.h | 88 --- src/tools/tools.pro | 2 +- src/tools/tools.qbs | 2 +- tests/unit/codemodelbackend/codemodelbackend.pro | 5 - .../codemodelbackend/echoserver/echoipcserver.cpp | 92 --- .../codemodelbackend/echoserver/echoipcserver.h | 55 -- .../codemodelbackend/echoserver/echoserver.pro | 28 - .../echoserver/echoserverprocessmain.cpp | 59 -- .../unittest/clangcodecompleteresultstest.cpp | 87 --- .../unittest/clangipcservertest.cpp | 382 ------------ .../codemodelbackend/unittest/clangstringtest.cpp | 70 --- .../unittest/clientserverinprocesstest.cpp | 234 -------- .../unittest/clientserveroutsideprocess.cpp | 201 ------- .../unittest/codecompletionsextractortest.cpp | 663 --------------------- .../unittest/codecompletiontest.cpp | 148 ----- .../completionchunkstotextconvertertest.cpp | 128 ---- .../createtablesqlstatementbuildertest.cpp | 189 ------ .../unittest/data/complete_completer.cpp | 101 ---- .../unittest/data/complete_completer_unsaved.cpp | 100 ---- .../unittest/data/complete_extractor_class.cpp | 21 - .../data/complete_extractor_constructor.cpp | 22 - .../data/complete_extractor_enumeration.cpp | 22 - .../unittest/data/complete_extractor_function.cpp | 22 - .../data/complete_extractor_function_unsaved.cpp | 22 - .../data/complete_extractor_function_unsaved_2.cpp | 22 - .../unittest/data/complete_extractor_namespace.cpp | 22 - .../unittest/data/complete_extractor_variable.cpp | 36 -- .../unittest/data/complete_testfile_1.cpp | 50 -- .../data/complete_translationunit_parse_error.cpp | 2 - .../unittest/gtest-qt-printing.cpp | 31 - .../codemodelbackend/unittest/gtest-qt-printing.h | 68 --- tests/unit/codemodelbackend/unittest/main.cpp | 47 -- .../unit/codemodelbackend/unittest/mockipclient.h | 52 -- .../unit/codemodelbackend/unittest/mockipcserver.h | 53 -- .../unit/codemodelbackend/unittest/projecttest.cpp | 188 ------ .../unittest/readandwritecommandblocktest.cpp | 225 ------- tests/unit/codemodelbackend/unittest/spydummy.cpp | 42 -- tests/unit/codemodelbackend/unittest/spydummy.h | 49 -- .../codemodelbackend/unittest/sqlitecolumntest.cpp | 95 --- .../unittest/sqlitedatabasebackendtest.cpp | 154 ----- .../unittest/sqlitedatabasetest.cpp | 112 ---- .../unittest/sqlitestatementtest.cpp | 570 ------------------ .../codemodelbackend/unittest/sqlitetabletest.cpp | 123 ---- .../unittest/sqlstatementbuildertest.cpp | 176 ------ .../unittest/translationunitstest.cpp | 182 ------ .../unittest/translationunittest.cpp | 155 ----- tests/unit/codemodelbackend/unittest/unittest.pro | 89 --- .../codemodelbackend/unittest/unsavedfilestest.cpp | 154 ----- tests/unit/codemodelbackend/unittest/utf8test.cpp | 273 --------- tests/unit/echoserver/echoipcserver.cpp | 92 +++ tests/unit/echoserver/echoipcserver.h | 55 ++ tests/unit/echoserver/echoserver.pro | 28 + tests/unit/echoserver/echoserverprocessmain.cpp | 59 ++ tests/unit/unit.pro | 5 + .../unit/unittest/clangcodecompleteresultstest.cpp | 87 +++ tests/unit/unittest/clangipcservertest.cpp | 382 ++++++++++++ tests/unit/unittest/clangstringtest.cpp | 70 +++ tests/unit/unittest/clientserverinprocesstest.cpp | 234 ++++++++ tests/unit/unittest/clientserveroutsideprocess.cpp | 201 +++++++ .../unit/unittest/codecompletionsextractortest.cpp | 663 +++++++++++++++++++++ tests/unit/unittest/codecompletiontest.cpp | 148 +++++ .../completionchunkstotextconvertertest.cpp | 128 ++++ .../createtablesqlstatementbuildertest.cpp | 189 ++++++ tests/unit/unittest/data/complete_completer.cpp | 101 ++++ .../unittest/data/complete_completer_unsaved.cpp | 100 ++++ .../unittest/data/complete_extractor_class.cpp | 21 + .../data/complete_extractor_constructor.cpp | 22 + .../data/complete_extractor_enumeration.cpp | 22 + .../unittest/data/complete_extractor_function.cpp | 22 + .../data/complete_extractor_function_unsaved.cpp | 22 + .../data/complete_extractor_function_unsaved_2.cpp | 22 + .../unittest/data/complete_extractor_namespace.cpp | 22 + .../unittest/data/complete_extractor_variable.cpp | 36 ++ tests/unit/unittest/data/complete_testfile_1.cpp | 50 ++ .../data/complete_translationunit_parse_error.cpp | 2 + tests/unit/unittest/gtest-qt-printing.cpp | 31 + tests/unit/unittest/gtest-qt-printing.h | 68 +++ tests/unit/unittest/main.cpp | 47 ++ tests/unit/unittest/mockipclient.h | 52 ++ tests/unit/unittest/mockipcserver.h | 53 ++ tests/unit/unittest/projecttest.cpp | 188 ++++++ .../unit/unittest/readandwritecommandblocktest.cpp | 225 +++++++ tests/unit/unittest/spydummy.cpp | 42 ++ tests/unit/unittest/spydummy.h | 49 ++ tests/unit/unittest/sqlitecolumntest.cpp | 95 +++ tests/unit/unittest/sqlitedatabasebackendtest.cpp | 154 +++++ tests/unit/unittest/sqlitedatabasetest.cpp | 112 ++++ tests/unit/unittest/sqlitestatementtest.cpp | 570 ++++++++++++++++++ tests/unit/unittest/sqlitetabletest.cpp | 123 ++++ tests/unit/unittest/sqlstatementbuildertest.cpp | 176 ++++++ tests/unit/unittest/translationunitstest.cpp | 182 ++++++ tests/unit/unittest/translationunittest.cpp | 155 +++++ tests/unit/unittest/unittest.pro | 89 +++ tests/unit/unittest/unsavedfilestest.cpp | 154 +++++ tests/unit/unittest/utf8test.cpp | 273 +++++++++ 312 files changed, 14717 insertions(+), 14926 deletions(-) create mode 100644 src/libs/clangbackendipc/clangbackendipc-lib.pri create mode 100644 src/libs/clangbackendipc/clangbackendipc.pro create mode 100644 src/libs/clangbackendipc/clangbackendipc.qbs create mode 100644 src/libs/clangbackendipc/clangbackendipc_dependencies.pri create mode 100644 src/libs/clangbackendipc/clangbackendipc_global.h create mode 100644 src/libs/clangbackendipc/cmbalivecommand.cpp create mode 100644 src/libs/clangbackendipc/cmbalivecommand.h create mode 100644 src/libs/clangbackendipc/cmbcodecompletedcommand.cpp create mode 100644 src/libs/clangbackendipc/cmbcodecompletedcommand.h create mode 100644 src/libs/clangbackendipc/cmbcommands.cpp create mode 100644 src/libs/clangbackendipc/cmbcommands.h create mode 100644 src/libs/clangbackendipc/cmbcompletecodecommand.cpp create mode 100644 src/libs/clangbackendipc/cmbcompletecodecommand.h create mode 100644 src/libs/clangbackendipc/cmbechocommand.cpp create mode 100644 src/libs/clangbackendipc/cmbechocommand.h create mode 100644 src/libs/clangbackendipc/cmbendcommand.cpp create mode 100644 src/libs/clangbackendipc/cmbendcommand.h create mode 100644 src/libs/clangbackendipc/cmbregisterprojectsforcodecompletioncommand.cpp create mode 100644 src/libs/clangbackendipc/cmbregisterprojectsforcodecompletioncommand.h create mode 100644 src/libs/clangbackendipc/cmbregistertranslationunitsforcodecompletioncommand.cpp create mode 100644 src/libs/clangbackendipc/cmbregistertranslationunitsforcodecompletioncommand.h create mode 100644 src/libs/clangbackendipc/cmbunregisterprojectsforcodecompletioncommand.cpp create mode 100644 src/libs/clangbackendipc/cmbunregisterprojectsforcodecompletioncommand.h create mode 100644 src/libs/clangbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.cpp create mode 100644 src/libs/clangbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.h create mode 100644 src/libs/clangbackendipc/codecompletion.cpp create mode 100644 src/libs/clangbackendipc/codecompletion.h create mode 100644 src/libs/clangbackendipc/codecompletionchunk.cpp create mode 100644 src/libs/clangbackendipc/codecompletionchunk.h create mode 100644 src/libs/clangbackendipc/connectionclient.cpp create mode 100644 src/libs/clangbackendipc/connectionclient.h create mode 100644 src/libs/clangbackendipc/connectionserver.cpp create mode 100644 src/libs/clangbackendipc/connectionserver.h create mode 100644 src/libs/clangbackendipc/container_common.h create mode 100644 src/libs/clangbackendipc/filecontainer.cpp create mode 100644 src/libs/clangbackendipc/filecontainer.h create mode 100644 src/libs/clangbackendipc/ipcclientdispatcher.cpp create mode 100644 src/libs/clangbackendipc/ipcclientdispatcher.h create mode 100644 src/libs/clangbackendipc/ipcclientinterface.cpp create mode 100644 src/libs/clangbackendipc/ipcclientinterface.h create mode 100644 src/libs/clangbackendipc/ipcclientproxy.cpp create mode 100644 src/libs/clangbackendipc/ipcclientproxy.h create mode 100644 src/libs/clangbackendipc/ipcinterface.cpp create mode 100644 src/libs/clangbackendipc/ipcinterface.h create mode 100644 src/libs/clangbackendipc/ipcserver.cpp create mode 100644 src/libs/clangbackendipc/ipcserver.h create mode 100644 src/libs/clangbackendipc/ipcserverinterface.cpp create mode 100644 src/libs/clangbackendipc/ipcserverinterface.h create mode 100644 src/libs/clangbackendipc/ipcserverproxy.cpp create mode 100644 src/libs/clangbackendipc/ipcserverproxy.h create mode 100644 src/libs/clangbackendipc/projectpartcontainer.cpp create mode 100644 src/libs/clangbackendipc/projectpartcontainer.h create mode 100644 src/libs/clangbackendipc/projectpartsdonotexistcommand.cpp create mode 100644 src/libs/clangbackendipc/projectpartsdonotexistcommand.h create mode 100644 src/libs/clangbackendipc/readcommandblock.cpp create mode 100644 src/libs/clangbackendipc/readcommandblock.h create mode 100644 src/libs/clangbackendipc/translationunitdoesnotexistcommand.cpp create mode 100644 src/libs/clangbackendipc/translationunitdoesnotexistcommand.h create mode 100644 src/libs/clangbackendipc/writecommandblock.cpp create mode 100644 src/libs/clangbackendipc/writecommandblock.h delete mode 100644 src/libs/codemodelbackendipc/cmbalivecommand.cpp delete mode 100644 src/libs/codemodelbackendipc/cmbalivecommand.h delete mode 100644 src/libs/codemodelbackendipc/cmbcodecompletedcommand.cpp delete mode 100644 src/libs/codemodelbackendipc/cmbcodecompletedcommand.h delete mode 100644 src/libs/codemodelbackendipc/cmbcommands.cpp delete mode 100644 src/libs/codemodelbackendipc/cmbcommands.h delete mode 100644 src/libs/codemodelbackendipc/cmbcompletecodecommand.cpp delete mode 100644 src/libs/codemodelbackendipc/cmbcompletecodecommand.h delete mode 100644 src/libs/codemodelbackendipc/cmbechocommand.cpp delete mode 100644 src/libs/codemodelbackendipc/cmbechocommand.h delete mode 100644 src/libs/codemodelbackendipc/cmbendcommand.cpp delete mode 100644 src/libs/codemodelbackendipc/cmbendcommand.h delete mode 100644 src/libs/codemodelbackendipc/cmbregisterprojectsforcodecompletioncommand.cpp delete mode 100644 src/libs/codemodelbackendipc/cmbregisterprojectsforcodecompletioncommand.h delete mode 100644 src/libs/codemodelbackendipc/cmbregistertranslationunitsforcodecompletioncommand.cpp delete mode 100644 src/libs/codemodelbackendipc/cmbregistertranslationunitsforcodecompletioncommand.h delete mode 100644 src/libs/codemodelbackendipc/cmbunregisterprojectsforcodecompletioncommand.cpp delete mode 100644 src/libs/codemodelbackendipc/cmbunregisterprojectsforcodecompletioncommand.h delete mode 100644 src/libs/codemodelbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.cpp delete mode 100644 src/libs/codemodelbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.h delete mode 100644 src/libs/codemodelbackendipc/codecompletion.cpp delete mode 100644 src/libs/codemodelbackendipc/codecompletion.h delete mode 100644 src/libs/codemodelbackendipc/codecompletionchunk.cpp delete mode 100644 src/libs/codemodelbackendipc/codecompletionchunk.h delete mode 100644 src/libs/codemodelbackendipc/codemodelbackendipc-lib.pri delete mode 100644 src/libs/codemodelbackendipc/codemodelbackendipc.pro delete mode 100644 src/libs/codemodelbackendipc/codemodelbackendipc.qbs delete mode 100644 src/libs/codemodelbackendipc/codemodelbackendipc_dependencies.pri delete mode 100644 src/libs/codemodelbackendipc/codemodelbackendipc_global.cpp delete mode 100644 src/libs/codemodelbackendipc/codemodelbackendipc_global.h delete mode 100644 src/libs/codemodelbackendipc/connectionclient.cpp delete mode 100644 src/libs/codemodelbackendipc/connectionclient.h delete mode 100644 src/libs/codemodelbackendipc/connectionserver.cpp delete mode 100644 src/libs/codemodelbackendipc/connectionserver.h delete mode 100644 src/libs/codemodelbackendipc/container_common.h delete mode 100644 src/libs/codemodelbackendipc/filecontainer.cpp delete mode 100644 src/libs/codemodelbackendipc/filecontainer.h delete mode 100644 src/libs/codemodelbackendipc/ipcclientdispatcher.cpp delete mode 100644 src/libs/codemodelbackendipc/ipcclientdispatcher.h delete mode 100644 src/libs/codemodelbackendipc/ipcclientinterface.cpp delete mode 100644 src/libs/codemodelbackendipc/ipcclientinterface.h delete mode 100644 src/libs/codemodelbackendipc/ipcclientproxy.cpp delete mode 100644 src/libs/codemodelbackendipc/ipcclientproxy.h delete mode 100644 src/libs/codemodelbackendipc/ipcinterface.cpp delete mode 100644 src/libs/codemodelbackendipc/ipcinterface.h delete mode 100644 src/libs/codemodelbackendipc/ipcserver.cpp delete mode 100644 src/libs/codemodelbackendipc/ipcserver.h delete mode 100644 src/libs/codemodelbackendipc/ipcserverinterface.cpp delete mode 100644 src/libs/codemodelbackendipc/ipcserverinterface.h delete mode 100644 src/libs/codemodelbackendipc/ipcserverproxy.cpp delete mode 100644 src/libs/codemodelbackendipc/ipcserverproxy.h delete mode 100644 src/libs/codemodelbackendipc/projectpartcontainer.cpp delete mode 100644 src/libs/codemodelbackendipc/projectpartcontainer.h delete mode 100644 src/libs/codemodelbackendipc/projectpartsdonotexistcommand.cpp delete mode 100644 src/libs/codemodelbackendipc/projectpartsdonotexistcommand.h delete mode 100644 src/libs/codemodelbackendipc/readcommandblock.cpp delete mode 100644 src/libs/codemodelbackendipc/readcommandblock.h delete mode 100644 src/libs/codemodelbackendipc/translationunitdoesnotexistcommand.cpp delete mode 100644 src/libs/codemodelbackendipc/translationunitdoesnotexistcommand.h delete mode 100644 src/libs/codemodelbackendipc/writecommandblock.cpp delete mode 100644 src/libs/codemodelbackendipc/writecommandblock.h create mode 100644 src/plugins/clangcodemodel/clangbackendipcintegration.cpp create mode 100644 src/plugins/clangcodemodel/clangbackendipcintegration.h delete mode 100644 src/plugins/clangcodemodel/codemodelbackendipcintegration.cpp delete mode 100644 src/plugins/clangcodemodel/codemodelbackendipcintegration.h create mode 100644 src/tools/clangbackend/clangbackend.pri create mode 100644 src/tools/clangbackend/clangbackend.pro create mode 100644 src/tools/clangbackend/clangbackend.qbs create mode 100644 src/tools/clangbackend/clangbackendmain.cpp create mode 100644 src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri create mode 100644 src/tools/clangbackend/ipcsource/clangcodecompleteresults.cpp create mode 100644 src/tools/clangbackend/ipcsource/clangcodecompleteresults.h create mode 100644 src/tools/clangbackend/ipcsource/clangipcserver.cpp create mode 100644 src/tools/clangbackend/ipcsource/clangipcserver.h create mode 100644 src/tools/clangbackend/ipcsource/clangstring.cpp create mode 100644 src/tools/clangbackend/ipcsource/clangstring.h create mode 100644 src/tools/clangbackend/ipcsource/codecompletefailedexception.cpp create mode 100644 src/tools/clangbackend/ipcsource/codecompletefailedexception.h create mode 100644 src/tools/clangbackend/ipcsource/codecompleter.cpp create mode 100644 src/tools/clangbackend/ipcsource/codecompleter.h create mode 100644 src/tools/clangbackend/ipcsource/codecompletionchunkconverter.cpp create mode 100644 src/tools/clangbackend/ipcsource/codecompletionchunkconverter.h create mode 100644 src/tools/clangbackend/ipcsource/codecompletionsextractor.cpp create mode 100644 src/tools/clangbackend/ipcsource/codecompletionsextractor.h create mode 100644 src/tools/clangbackend/ipcsource/projectpart.cpp create mode 100644 src/tools/clangbackend/ipcsource/projectpart.h create mode 100644 src/tools/clangbackend/ipcsource/projectpartsdonotexistexception.cpp create mode 100644 src/tools/clangbackend/ipcsource/projectpartsdonotexistexception.h create mode 100644 src/tools/clangbackend/ipcsource/projects.cpp create mode 100644 src/tools/clangbackend/ipcsource/projects.h create mode 100644 src/tools/clangbackend/ipcsource/translationunit.cpp create mode 100644 src/tools/clangbackend/ipcsource/translationunit.h create mode 100644 src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.cpp create mode 100644 src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.h create mode 100644 src/tools/clangbackend/ipcsource/translationunitfilenotexitexception.cpp create mode 100644 src/tools/clangbackend/ipcsource/translationunitfilenotexitexception.h create mode 100644 src/tools/clangbackend/ipcsource/translationunitisnullexception.cpp create mode 100644 src/tools/clangbackend/ipcsource/translationunitisnullexception.h create mode 100644 src/tools/clangbackend/ipcsource/translationunitparseerrorexception.cpp create mode 100644 src/tools/clangbackend/ipcsource/translationunitparseerrorexception.h create mode 100644 src/tools/clangbackend/ipcsource/translationunits.cpp create mode 100644 src/tools/clangbackend/ipcsource/translationunits.h create mode 100644 src/tools/clangbackend/ipcsource/unsavedfiles.cpp create mode 100644 src/tools/clangbackend/ipcsource/unsavedfiles.h delete mode 100644 src/tools/codemodelbackend/codemodelbackend.pri delete mode 100644 src/tools/codemodelbackend/codemodelbackend.pro delete mode 100644 src/tools/codemodelbackend/codemodelbackend.qbs delete mode 100644 src/tools/codemodelbackend/codemodelbackendmain.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/clangcodecompleteresults.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/clangcodecompleteresults.h delete mode 100644 src/tools/codemodelbackend/ipcsource/clangipcserver.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/clangipcserver.h delete mode 100644 src/tools/codemodelbackend/ipcsource/clangstring.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/clangstring.h delete mode 100644 src/tools/codemodelbackend/ipcsource/codecompletefailedexception.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/codecompletefailedexception.h delete mode 100644 src/tools/codemodelbackend/ipcsource/codecompleter.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/codecompleter.h delete mode 100644 src/tools/codemodelbackend/ipcsource/codecompletionchunkconverter.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/codecompletionchunkconverter.h delete mode 100644 src/tools/codemodelbackend/ipcsource/codecompletionsextractor.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/codecompletionsextractor.h delete mode 100644 src/tools/codemodelbackend/ipcsource/codemodelbackendclangipc-source.pri delete mode 100644 src/tools/codemodelbackend/ipcsource/projectcontainer.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/projectcontainer.h delete mode 100644 src/tools/codemodelbackend/ipcsource/projectpart.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/projectpart.h delete mode 100644 src/tools/codemodelbackend/ipcsource/projectpartsdonotexistexception.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/projectpartsdonotexistexception.h delete mode 100644 src/tools/codemodelbackend/ipcsource/projects.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/projects.h delete mode 100644 src/tools/codemodelbackend/ipcsource/translationunit.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/translationunit.h delete mode 100644 src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistexception.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistexception.h delete mode 100644 src/tools/codemodelbackend/ipcsource/translationunitfilenotexitexception.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/translationunitfilenotexitexception.h delete mode 100644 src/tools/codemodelbackend/ipcsource/translationunitisnullexception.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/translationunitisnullexception.h delete mode 100644 src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.h delete mode 100644 src/tools/codemodelbackend/ipcsource/translationunits.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/translationunits.h delete mode 100644 src/tools/codemodelbackend/ipcsource/unsavedfiles.cpp delete mode 100644 src/tools/codemodelbackend/ipcsource/unsavedfiles.h delete mode 100644 tests/unit/codemodelbackend/codemodelbackend.pro delete mode 100644 tests/unit/codemodelbackend/echoserver/echoipcserver.cpp delete mode 100644 tests/unit/codemodelbackend/echoserver/echoipcserver.h delete mode 100644 tests/unit/codemodelbackend/echoserver/echoserver.pro delete mode 100644 tests/unit/codemodelbackend/echoserver/echoserverprocessmain.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/clangcodecompleteresultstest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/clangipcservertest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/clangstringtest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/clientserveroutsideprocess.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/codecompletionsextractortest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/codecompletiontest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/completionchunkstotextconvertertest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/createtablesqlstatementbuildertest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/data/complete_completer.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/data/complete_completer_unsaved.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/data/complete_extractor_class.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/data/complete_extractor_constructor.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/data/complete_extractor_enumeration.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/data/complete_extractor_function.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/data/complete_extractor_function_unsaved.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/data/complete_extractor_function_unsaved_2.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/data/complete_extractor_namespace.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/data/complete_extractor_variable.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/data/complete_testfile_1.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/data/complete_translationunit_parse_error.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/gtest-qt-printing.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/gtest-qt-printing.h delete mode 100644 tests/unit/codemodelbackend/unittest/main.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/mockipclient.h delete mode 100644 tests/unit/codemodelbackend/unittest/mockipcserver.h delete mode 100644 tests/unit/codemodelbackend/unittest/projecttest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/readandwritecommandblocktest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/spydummy.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/spydummy.h delete mode 100644 tests/unit/codemodelbackend/unittest/sqlitecolumntest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/sqlitedatabasebackendtest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/sqlitedatabasetest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/sqlitestatementtest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/sqlitetabletest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/sqlstatementbuildertest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/translationunitstest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/translationunittest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/unittest.pro delete mode 100644 tests/unit/codemodelbackend/unittest/unsavedfilestest.cpp delete mode 100644 tests/unit/codemodelbackend/unittest/utf8test.cpp create mode 100644 tests/unit/echoserver/echoipcserver.cpp create mode 100644 tests/unit/echoserver/echoipcserver.h create mode 100644 tests/unit/echoserver/echoserver.pro create mode 100644 tests/unit/echoserver/echoserverprocessmain.cpp create mode 100644 tests/unit/unit.pro create mode 100644 tests/unit/unittest/clangcodecompleteresultstest.cpp create mode 100644 tests/unit/unittest/clangipcservertest.cpp create mode 100644 tests/unit/unittest/clangstringtest.cpp create mode 100644 tests/unit/unittest/clientserverinprocesstest.cpp create mode 100644 tests/unit/unittest/clientserveroutsideprocess.cpp create mode 100644 tests/unit/unittest/codecompletionsextractortest.cpp create mode 100644 tests/unit/unittest/codecompletiontest.cpp create mode 100644 tests/unit/unittest/completionchunkstotextconvertertest.cpp create mode 100644 tests/unit/unittest/createtablesqlstatementbuildertest.cpp create mode 100644 tests/unit/unittest/data/complete_completer.cpp create mode 100644 tests/unit/unittest/data/complete_completer_unsaved.cpp create mode 100644 tests/unit/unittest/data/complete_extractor_class.cpp create mode 100644 tests/unit/unittest/data/complete_extractor_constructor.cpp create mode 100644 tests/unit/unittest/data/complete_extractor_enumeration.cpp create mode 100644 tests/unit/unittest/data/complete_extractor_function.cpp create mode 100644 tests/unit/unittest/data/complete_extractor_function_unsaved.cpp create mode 100644 tests/unit/unittest/data/complete_extractor_function_unsaved_2.cpp create mode 100644 tests/unit/unittest/data/complete_extractor_namespace.cpp create mode 100644 tests/unit/unittest/data/complete_extractor_variable.cpp create mode 100644 tests/unit/unittest/data/complete_testfile_1.cpp create mode 100644 tests/unit/unittest/data/complete_translationunit_parse_error.cpp create mode 100644 tests/unit/unittest/gtest-qt-printing.cpp create mode 100644 tests/unit/unittest/gtest-qt-printing.h create mode 100644 tests/unit/unittest/main.cpp create mode 100644 tests/unit/unittest/mockipclient.h create mode 100644 tests/unit/unittest/mockipcserver.h create mode 100644 tests/unit/unittest/projecttest.cpp create mode 100644 tests/unit/unittest/readandwritecommandblocktest.cpp create mode 100644 tests/unit/unittest/spydummy.cpp create mode 100644 tests/unit/unittest/spydummy.h create mode 100644 tests/unit/unittest/sqlitecolumntest.cpp create mode 100644 tests/unit/unittest/sqlitedatabasebackendtest.cpp create mode 100644 tests/unit/unittest/sqlitedatabasetest.cpp create mode 100644 tests/unit/unittest/sqlitestatementtest.cpp create mode 100644 tests/unit/unittest/sqlitetabletest.cpp create mode 100644 tests/unit/unittest/sqlstatementbuildertest.cpp create mode 100644 tests/unit/unittest/translationunitstest.cpp create mode 100644 tests/unit/unittest/translationunittest.cpp create mode 100644 tests/unit/unittest/unittest.pro create mode 100644 tests/unit/unittest/unsavedfilestest.cpp create mode 100644 tests/unit/unittest/utf8test.cpp diff --git a/.gitignore b/.gitignore index 5efdf6e49f..1242e01ea6 100644 --- a/.gitignore +++ b/.gitignore @@ -117,7 +117,7 @@ tmp/ *.dll *.exe /bin/buildoutputparser -/bin/codemodelbackend +/bin/clangbackend /bin/cpaster /bin/cplusplus-ast2png /bin/cplusplus-frontend diff --git a/src/libs/clangbackendipc/clangbackendipc-lib.pri b/src/libs/clangbackendipc/clangbackendipc-lib.pri new file mode 100644 index 0000000000..ed1a01d6f3 --- /dev/null +++ b/src/libs/clangbackendipc/clangbackendipc-lib.pri @@ -0,0 +1,73 @@ +contains(CONFIG, dll) { + DEFINES += CLANGBACKENDIPC_BUILD_LIB +} else { + DEFINES += CLANGBACKENDIPC_BUILD_STATIC_LIB +} + +QT += network + +DEFINES += CLANGBACKENDIPC_LIBRARY + +INCLUDEPATH += $$PWD + +SOURCES += $$PWD/ipcserverinterface.cpp \ + $$PWD/ipcserverproxy.cpp \ + $$PWD/ipcserver.cpp \ + $$PWD/ipcclientinterface.cpp \ + $$PWD/cmbendcommand.cpp \ + $$PWD/cmbalivecommand.cpp \ + $$PWD/ipcclientproxy.cpp \ + $$PWD/cmbcommands.cpp \ + $$PWD/writecommandblock.cpp \ + $$PWD/readcommandblock.cpp \ + $$PWD/ipcinterface.cpp \ + $$PWD/connectionserver.cpp \ + $$PWD/connectionclient.cpp \ + $$PWD/cmbechocommand.cpp \ + $$PWD/ipcclientdispatcher.cpp \ + $$PWD/cmbregistertranslationunitsforcodecompletioncommand.cpp \ + $$PWD/filecontainer.cpp \ + $$PWD/cmbunregistertranslationunitsforcodecompletioncommand.cpp \ + $$PWD/cmbcompletecodecommand.cpp \ + $$PWD/cmbcodecompletedcommand.cpp \ + $$PWD/codecompletion.cpp \ + $$PWD/cmbregisterprojectsforcodecompletioncommand.cpp \ + $$PWD/cmbunregisterprojectsforcodecompletioncommand.cpp \ + $$PWD/translationunitdoesnotexistcommand.cpp \ + $$PWD/codecompletionchunk.cpp \ + $$PWD/projectpartcontainer.cpp \ + $$PWD/projectpartsdonotexistcommand.cpp + + +HEADERS += \ + $$PWD/ipcserverinterface.h \ + $$PWD/ipcserverproxy.h \ + $$PWD/ipcserver.h \ + $$PWD/ipcclientinterface.h \ + $$PWD/cmbendcommand.h \ + $$PWD/cmbalivecommand.h \ + $$PWD/ipcclientproxy.h \ + $$PWD/cmbcommands.h \ + $$PWD/writecommandblock.h \ + $$PWD/readcommandblock.h \ + $$PWD/ipcinterface.h \ + $$PWD/connectionserver.h \ + $$PWD/connectionclient.h \ + $$PWD/cmbechocommand.h \ + $$PWD/ipcclientdispatcher.h \ + $$PWD/cmbregistertranslationunitsforcodecompletioncommand.h \ + $$PWD/filecontainer.h \ + $$PWD/cmbunregistertranslationunitsforcodecompletioncommand.h \ + $$PWD/cmbcompletecodecommand.h \ + $$PWD/cmbcodecompletedcommand.h \ + $$PWD/codecompletion.h \ + $$PWD/cmbregisterprojectsforcodecompletioncommand.h \ + $$PWD/cmbunregisterprojectsforcodecompletioncommand.h \ + $$PWD/translationunitdoesnotexistcommand.h \ + $$PWD/codecompletionchunk.h \ + $$PWD/projectpartcontainer.h \ + $$PWD/projectpartsdonotexistcommand.h \ + $$PWD/container_common.h \ + $$PWD/clangbackendipc_global.h + +contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols diff --git a/src/libs/clangbackendipc/clangbackendipc.pro b/src/libs/clangbackendipc/clangbackendipc.pro new file mode 100644 index 0000000000..e5997d0688 --- /dev/null +++ b/src/libs/clangbackendipc/clangbackendipc.pro @@ -0,0 +1,2 @@ +include(../../qtcreatorlibrary.pri) +include(clangbackendipc-lib.pri) diff --git a/src/libs/clangbackendipc/clangbackendipc.qbs b/src/libs/clangbackendipc/clangbackendipc.qbs new file mode 100644 index 0000000000..0ffe8cacb2 --- /dev/null +++ b/src/libs/clangbackendipc/clangbackendipc.qbs @@ -0,0 +1,28 @@ +import qbs 1.0 + +QtcLibrary { + name: "ClangBackEndIpc" + + Depends { name: "Qt.network" } + Depends { name: "Sqlite" } + + cpp.defines: base.concat("CLANGIPC_LIBRARY") + cpp.includePaths: base.concat(".") + + Group { + files: [ + "*.h", + "*.cpp" + ] + } + + Export { + Depends { name: "Sqlite" } + Depends { name: "Qt.network" } + cpp.includePaths: [ + "." + ] + } +} + + diff --git a/src/libs/clangbackendipc/clangbackendipc_dependencies.pri b/src/libs/clangbackendipc/clangbackendipc_dependencies.pri new file mode 100644 index 0000000000..4813d6ce77 --- /dev/null +++ b/src/libs/clangbackendipc/clangbackendipc_dependencies.pri @@ -0,0 +1,3 @@ +QTC_LIB_NAME = Clangbackendipc +QTC_LIB_DEPENDS += sqlite +INCLUDEPATH *= $$IDE_SOURCE_TREE/src/libs/clangbackendipc diff --git a/src/libs/clangbackendipc/clangbackendipc_global.h b/src/libs/clangbackendipc/clangbackendipc_global.h new file mode 100644 index 0000000000..38b20faf42 --- /dev/null +++ b/src/libs/clangbackendipc/clangbackendipc_global.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKENDIPC_GLOBAL_H +#define CLANGBACKENDIPC_GLOBAL_H + +#include + +#if defined(CLANGBACKENDIPC_LIBRARY) +# define CMBIPC_EXPORT Q_DECL_EXPORT +#else +# define CMBIPC_EXPORT Q_DECL_IMPORT +#endif + +#ifndef CLANGBACKENDPROCESSPATH +# define CLANGBACKENDPROCESSPATH "" +#endif + +namespace ClangBackEnd { +CMBIPC_EXPORT void registerTypes(); +} + +#endif // CLANGBACKENDIPC_GLOBAL_H diff --git a/src/libs/clangbackendipc/cmbalivecommand.cpp b/src/libs/clangbackendipc/cmbalivecommand.cpp new file mode 100644 index 0000000000..9be8d30745 --- /dev/null +++ b/src/libs/clangbackendipc/cmbalivecommand.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cmbalivecommand.h" + +#include + +#include + +namespace ClangBackEnd { + +QDataStream &operator<<(QDataStream &out, const AliveCommand &/*command*/) +{ + return out; +} + +QDataStream &operator>>(QDataStream &in, AliveCommand &/*command*/) +{ + return in; +} + +bool operator==(const AliveCommand &/*first*/, const AliveCommand &/*second*/) +{ + return true; +} + +bool operator<(const AliveCommand &/*first*/, const AliveCommand &/*second*/) +{ + return true; +} + +QDebug operator<<(QDebug debug, const AliveCommand &/*command*/) +{ + return debug.nospace() << "AliveCommand()"; +} + +} diff --git a/src/libs/clangbackendipc/cmbalivecommand.h b/src/libs/clangbackendipc/cmbalivecommand.h new file mode 100644 index 0000000000..5ddb747fa9 --- /dev/null +++ b/src/libs/clangbackendipc/cmbalivecommand.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CMBALIVECOMMAND_H +#define CMBALIVECOMMAND_H + +#include "clangbackendipc_global.h" + +#include + +namespace ClangBackEnd { + +class CMBIPC_EXPORT AliveCommand +{ +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const AliveCommand &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, AliveCommand &command); +CMBIPC_EXPORT bool operator==(const AliveCommand &first, const AliveCommand &second); +CMBIPC_EXPORT bool operator<(const AliveCommand &first, const AliveCommand &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const AliveCommand &command); + +} + +Q_DECLARE_METATYPE(ClangBackEnd::AliveCommand) + +#endif // CMBALIVECOMMAND_H diff --git a/src/libs/clangbackendipc/cmbcodecompletedcommand.cpp b/src/libs/clangbackendipc/cmbcodecompletedcommand.cpp new file mode 100644 index 0000000000..75473fd34d --- /dev/null +++ b/src/libs/clangbackendipc/cmbcodecompletedcommand.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cmbcodecompletedcommand.h" + +#include + +#include + +#include + +namespace ClangBackEnd { + +CodeCompletedCommand::CodeCompletedCommand(const QVector &codeCompletions, quint64 ticketNumber) + : codeCompletions_(codeCompletions), + ticketNumber_(ticketNumber) +{ +} + +const QVector &CodeCompletedCommand::codeCompletions() const +{ + return codeCompletions_; +} + +quint64 CodeCompletedCommand::ticketNumber() const +{ + return ticketNumber_; +} + +QDataStream &operator<<(QDataStream &out, const CodeCompletedCommand &command) +{ + out << command.codeCompletions_; + out << command.ticketNumber_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, CodeCompletedCommand &command) +{ + in >> command.codeCompletions_; + in >> command.ticketNumber_; + + return in; +} + +bool operator==(const CodeCompletedCommand &first, const CodeCompletedCommand &second) +{ + return first.ticketNumber_ == second.ticketNumber_ + && first.codeCompletions_ == second.codeCompletions_; +} + +bool operator<(const CodeCompletedCommand &first, const CodeCompletedCommand &second) +{ + return first.ticketNumber_ < second.ticketNumber_; +} + +QDebug operator<<(QDebug debug, const CodeCompletedCommand &command) +{ + debug.nospace() << "CodeCompletedCommand("; + + debug.nospace() << command.codeCompletions_ << ", " << command.ticketNumber_; + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const CodeCompletedCommand &command, ::std::ostream* os) +{ + QString output; + QDebug debug(&output); + + debug << command; + + *os << output.toUtf8().constData(); +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/cmbcodecompletedcommand.h b/src/libs/clangbackendipc/cmbcodecompletedcommand.h new file mode 100644 index 0000000000..c6e6b87685 --- /dev/null +++ b/src/libs/clangbackendipc/cmbcodecompletedcommand.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_CODECOMPLETEDCOMMAND_H +#define CLANGBACKEND_CODECOMPLETEDCOMMAND_H + +#include +#include + +#include "codecompletion.h" + +namespace ClangBackEnd { + +class CMBIPC_EXPORT CodeCompletedCommand +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletedCommand &command); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CodeCompletedCommand &command); + friend CMBIPC_EXPORT bool operator==(const CodeCompletedCommand &first, const CodeCompletedCommand &second); + friend CMBIPC_EXPORT bool operator<(const CodeCompletedCommand &first, const CodeCompletedCommand &second); + friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CodeCompletedCommand &command); + friend void PrintTo(const CodeCompletedCommand &command, ::std::ostream* os); +public: + CodeCompletedCommand() = default; + CodeCompletedCommand(const QVector &codeCompletions, quint64 ticketNumber); + + const QVector &codeCompletions() const; + + quint64 ticketNumber() const; + +private: + QVector codeCompletions_; + quint64 ticketNumber_ = 0; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletedCommand &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CodeCompletedCommand &command); +CMBIPC_EXPORT bool operator==(const CodeCompletedCommand &first, const CodeCompletedCommand &second); +CMBIPC_EXPORT bool operator<(const CodeCompletedCommand &first, const CodeCompletedCommand &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CodeCompletedCommand &command); +void PrintTo(const CodeCompletedCommand &command, ::std::ostream* os); + +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::CodeCompletedCommand) + +#endif // CLANGBACKEND_CODECOMPLETEDCOMMAND_H diff --git a/src/libs/clangbackendipc/cmbcommands.cpp b/src/libs/clangbackendipc/cmbcommands.cpp new file mode 100644 index 0000000000..169df08246 --- /dev/null +++ b/src/libs/clangbackendipc/cmbcommands.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cmbcommands.h" + +#include "cmbalivecommand.h" +#include "cmbendcommand.h" +#include "cmbechocommand.h" +#include "cmbregistertranslationunitsforcodecompletioncommand.h" +#include "cmbunregistertranslationunitsforcodecompletioncommand.h" +#include "cmbregisterprojectsforcodecompletioncommand.h" +#include "cmbunregisterprojectsforcodecompletioncommand.h" +#include "cmbcompletecodecommand.h" +#include "cmbcodecompletedcommand.h" +#include "projectpartsdonotexistcommand.h" +#include "translationunitdoesnotexistcommand.h" + +#include + +namespace ClangBackEnd { + +void Commands::registerCommands() +{ + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/cmbcommands.h b/src/libs/clangbackendipc/cmbcommands.h new file mode 100644 index 0000000000..7cad34ced4 --- /dev/null +++ b/src/libs/clangbackendipc/cmbcommands.h @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_COMMANDS_H +#define CLANGBACKEND_COMMANDS_H + +#include + +namespace ClangBackEnd { + +namespace Commands +{ +CMBIPC_EXPORT void registerCommands(); +} + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_COMMANDS_H diff --git a/src/libs/clangbackendipc/cmbcompletecodecommand.cpp b/src/libs/clangbackendipc/cmbcompletecodecommand.cpp new file mode 100644 index 0000000000..cbf242582b --- /dev/null +++ b/src/libs/clangbackendipc/cmbcompletecodecommand.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cmbcompletecodecommand.h" + +#include + +#include + +#include + +namespace ClangBackEnd { + +quint64 CompleteCodeCommand::ticketCounter = 0; + +CompleteCodeCommand::CompleteCodeCommand(const Utf8String &filePath, quint32 line, quint32 column, const Utf8String &projectPartId) + : filePath_(filePath), + projectPartId_(projectPartId), + ticketNumber_(++ticketCounter), + line_(line), + column_(column) +{ +} + +const Utf8String &CompleteCodeCommand::filePath() const +{ + return filePath_; +} + +const Utf8String &CompleteCodeCommand::projectPartId() const +{ + return projectPartId_; +} + +quint32 CompleteCodeCommand::line() const +{ + return line_; +} + +quint32 CompleteCodeCommand::column() const +{ + return column_; +} + +quint64 CompleteCodeCommand::ticketNumber() const +{ + return ticketNumber_; +} + +QDataStream &operator<<(QDataStream &out, const CompleteCodeCommand &command) +{ + out << command.filePath_; + out << command.projectPartId_; + out << command.ticketNumber_; + out << command.line_; + out << command.column_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, CompleteCodeCommand &command) +{ + in >> command.filePath_; + in >> command.projectPartId_; + in >> command.ticketNumber_; + in >> command.line_; + in >> command.column_; + + return in; +} + +bool operator==(const CompleteCodeCommand &first, const CompleteCodeCommand &second) +{ + return first.ticketNumber_ == second.ticketNumber_ + && first.filePath_ == second.filePath_ + && first.projectPartId_ == second.projectPartId_ + && first.line_ == second.line_ + && first.column_ == second.column_; +} + +bool operator<(const CompleteCodeCommand &first, const CompleteCodeCommand &second) +{ + return first.ticketNumber_ < second.ticketNumber_ + && first.filePath_ < second.filePath_ + && first.projectPartId_ < second.projectPartId_ + && first.line_ < second.line_ + && first.column_ < second.column_; +} + +QDebug operator<<(QDebug debug, const CompleteCodeCommand &command) +{ + debug.nospace() << "CompleteCodeCommand("; + + debug.nospace() << command.filePath_ << ", "; + debug.nospace() << command.line_<< ", "; + debug.nospace() << command.column_<< ", "; + debug.nospace() << command.projectPartId_ << ", "; + debug.nospace() << command.ticketNumber_; + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const CompleteCodeCommand &command, ::std::ostream* os) +{ + *os << "CompleteCodeCommand("; + + *os << command.filePath_.constData() << ", "; + *os << command.line_ << ", "; + *os << command.column_ << ", "; + *os << command.projectPartId_.constData() << ", "; + *os << command.ticketNumber_; + + *os << ")"; +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/cmbcompletecodecommand.h b/src/libs/clangbackendipc/cmbcompletecodecommand.h new file mode 100644 index 0000000000..545c6ab926 --- /dev/null +++ b/src/libs/clangbackendipc/cmbcompletecodecommand.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_COMPLETECODECOMMAND_H +#define CLANGBACKEND_COMPLETECODECOMMAND_H + +#include "clangbackendipc_global.h" + +#include +#include + +namespace ClangBackEnd { + +class CMBIPC_EXPORT CompleteCodeCommand +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CompleteCodeCommand &command); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CompleteCodeCommand &command); + friend CMBIPC_EXPORT bool operator==(const CompleteCodeCommand &first, const CompleteCodeCommand &second); + friend CMBIPC_EXPORT bool operator<(const CompleteCodeCommand &first, const CompleteCodeCommand &second); + friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CompleteCodeCommand &command); + friend void PrintTo(const CompleteCodeCommand &command, ::std::ostream* os); + +public: + CompleteCodeCommand() = default; + CompleteCodeCommand(const Utf8String &filePath, + quint32 line, + quint32 column, + const Utf8String &projectPartId); + + const Utf8String &filePath() const; + const Utf8String &projectPartId() const; + + quint32 line() const; + quint32 column() const; + + quint64 ticketNumber() const; + +private: + Utf8String filePath_; + Utf8String projectPartId_; + static quint64 ticketCounter; + quint64 ticketNumber_; + quint32 line_ = 0; + quint32 column_ = 0; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CompleteCodeCommand &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CompleteCodeCommand &command); +CMBIPC_EXPORT bool operator==(const CompleteCodeCommand &first, const CompleteCodeCommand &second); +CMBIPC_EXPORT bool operator<(const CompleteCodeCommand &first, const CompleteCodeCommand &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CompleteCodeCommand &command); +void PrintTo(const CompleteCodeCommand &command, ::std::ostream* os); + +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::CompleteCodeCommand) + +#endif // CLANGBACKEND_COMPLETECODECOMMAND_H diff --git a/src/libs/clangbackendipc/cmbechocommand.cpp b/src/libs/clangbackendipc/cmbechocommand.cpp new file mode 100644 index 0000000000..812c6f24e6 --- /dev/null +++ b/src/libs/clangbackendipc/cmbechocommand.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cmbechocommand.h" + +#include + +#include + +#include + +namespace ClangBackEnd { + +EchoCommand::EchoCommand(const QVariant &command) + : command_(command) +{ + +} + +const QVariant &EchoCommand::command() const +{ + return command_; +} + +QDataStream &operator<<(QDataStream &out, const EchoCommand &command) +{ + out << command.command(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, EchoCommand &command) +{ + in >> command.command_; + + return in; +} + +bool operator==(const EchoCommand &first, const EchoCommand &second) +{ + return first.command_ == second.command_; +} + +bool operator<(const EchoCommand &first, const EchoCommand &second) +{ + return first.command_ < second.command_; +} + +QDebug operator<<(QDebug debug, const EchoCommand &command) +{ + return debug.nospace() << "EchoCommand(" << command.command() << ")"; +} + +void PrintTo(const EchoCommand &command, ::std::ostream* os) +{ + QString output; + QDebug debug(&output); + + debug << command; + + *os << output.toUtf8().constData(); +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/cmbechocommand.h b/src/libs/clangbackendipc/cmbechocommand.h new file mode 100644 index 0000000000..73660ea484 --- /dev/null +++ b/src/libs/clangbackendipc/cmbechocommand.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_ECHOCOMMAND_H +#define CLANGBACKEND_ECHOCOMMAND_H + +#include "clangbackendipc_global.h" + +#include +#include + +namespace ClangBackEnd { + +class CMBIPC_EXPORT EchoCommand +{ + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, EchoCommand &command); + friend CMBIPC_EXPORT bool operator==(const EchoCommand &first, const EchoCommand &second); + friend CMBIPC_EXPORT bool operator<(const EchoCommand &first, const EchoCommand &second); +public: + EchoCommand() = default; + explicit EchoCommand(const QVariant &command); + + const QVariant &command() const; + +private: + QVariant command_; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const EchoCommand &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, EchoCommand &command); +CMBIPC_EXPORT bool operator==(const EchoCommand &first, const EchoCommand &second); +CMBIPC_EXPORT bool operator<(const EchoCommand &first, const EchoCommand &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const EchoCommand &command); +void PrintTo(const EchoCommand &command, ::std::ostream* os); + +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::EchoCommand) + +#endif // CLANGBACKEND_ECHOCOMMAND_H diff --git a/src/libs/clangbackendipc/cmbendcommand.cpp b/src/libs/clangbackendipc/cmbendcommand.cpp new file mode 100644 index 0000000000..e99a50137b --- /dev/null +++ b/src/libs/clangbackendipc/cmbendcommand.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cmbendcommand.h" + +#include + +#include + +#include + +namespace ClangBackEnd { + +QDataStream &operator<<(QDataStream &out, const EndCommand &/*command*/) +{ + return out; +} + +QDataStream &operator>>(QDataStream &in, EndCommand &/*command*/) +{ + return in; +} + +bool operator==(const EndCommand &/*first*/, const EndCommand &/*second*/) +{ + return true; +} + +bool operator<(const EndCommand &/*first*/, const EndCommand &/*second*/) +{ + return true; +} + +QDebug operator<<(QDebug debug, const EndCommand &/*command*/) +{ + return debug.nospace() << "EndCommand()"; +} + +void PrintTo(const EndCommand &/*command*/, ::std::ostream* os) +{ + *os << "EndCommand()"; +} +} + diff --git a/src/libs/clangbackendipc/cmbendcommand.h b/src/libs/clangbackendipc/cmbendcommand.h new file mode 100644 index 0000000000..418e7abdfe --- /dev/null +++ b/src/libs/clangbackendipc/cmbendcommand.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CMBENDCOMMAND_H +#define CMBENDCOMMAND_H + +#include "clangbackendipc_global.h" + +#include + +namespace ClangBackEnd { + +class CMBIPC_EXPORT EndCommand +{ +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const EndCommand &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, EndCommand &command); +CMBIPC_EXPORT bool operator==(const EndCommand &first, const EndCommand &second); +CMBIPC_EXPORT bool operator<(const EndCommand &first, const EndCommand &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const EndCommand &command); +void PrintTo(const EndCommand &command, ::std::ostream* os); +} + +Q_DECLARE_METATYPE(ClangBackEnd::EndCommand) + +#endif // CMBENDCOMMAND_H diff --git a/src/libs/clangbackendipc/cmbregisterprojectsforcodecompletioncommand.cpp b/src/libs/clangbackendipc/cmbregisterprojectsforcodecompletioncommand.cpp new file mode 100644 index 0000000000..83e582f7e2 --- /dev/null +++ b/src/libs/clangbackendipc/cmbregisterprojectsforcodecompletioncommand.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cmbregisterprojectsforcodecompletioncommand.h" + +#include + +#include + +#include + +#include + +#include "container_common.h" + +namespace ClangBackEnd { + +RegisterProjectPartsForCodeCompletionCommand::RegisterProjectPartsForCodeCompletionCommand(const QVector &projectContainers) + :projectContainers_(projectContainers) +{ +} + +const QVector &RegisterProjectPartsForCodeCompletionCommand::projectContainers() const +{ + return projectContainers_; +} + +QDataStream &operator<<(QDataStream &out, const RegisterProjectPartsForCodeCompletionCommand &command) +{ + out << command.projectContainers_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, RegisterProjectPartsForCodeCompletionCommand &command) +{ + in >> command.projectContainers_; + + return in; +} + +bool operator==(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second) +{ + return first.projectContainers_ == second.projectContainers_; +} + +bool operator<(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second) +{ + return compareContainer(first.projectContainers_, second.projectContainers_); +} + +QDebug operator<<(QDebug debug, const RegisterProjectPartsForCodeCompletionCommand &command) +{ + debug.nospace() << "RegisterProjectPartsForCodeCompletion("; + + for (const ProjectPartContainer &projectContainer : command.projectContainers()) + debug.nospace() << projectContainer<< ", "; + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const RegisterProjectPartsForCodeCompletionCommand &command, ::std::ostream* os) +{ + *os << "RegisterProjectPartsForCodeCompletion("; + + for (const ProjectPartContainer &projectContainer : command.projectContainers()) + PrintTo(projectContainer, os); + + *os << ")"; +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/cmbregisterprojectsforcodecompletioncommand.h b/src/libs/clangbackendipc/cmbregisterprojectsforcodecompletioncommand.h new file mode 100644 index 0000000000..8902181a1c --- /dev/null +++ b/src/libs/clangbackendipc/cmbregisterprojectsforcodecompletioncommand.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_REGISTERPROJECTSFORCODECOMPLETIONCOMAND_H +#define CLANGBACKEND_REGISTERPROJECTSFORCODECOMPLETIONCOMAND_H + +#include +#include + +#include "projectpartcontainer.h" + +namespace ClangBackEnd { + +class CMBIPC_EXPORT RegisterProjectPartsForCodeCompletionCommand +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const RegisterProjectPartsForCodeCompletionCommand &command); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, RegisterProjectPartsForCodeCompletionCommand &command); + friend CMBIPC_EXPORT bool operator==(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second); + friend CMBIPC_EXPORT bool operator<(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second); + friend void PrintTo(const RegisterProjectPartsForCodeCompletionCommand &command, ::std::ostream* os); +public: + RegisterProjectPartsForCodeCompletionCommand() = default; + RegisterProjectPartsForCodeCompletionCommand(const QVector &projectContainers); + + const QVector &projectContainers() const; + +private: + QVector projectContainers_; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const RegisterProjectPartsForCodeCompletionCommand &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, RegisterProjectPartsForCodeCompletionCommand &command); +CMBIPC_EXPORT bool operator==(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second); +CMBIPC_EXPORT bool operator<(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const RegisterProjectPartsForCodeCompletionCommand &command); +void PrintTo(const RegisterProjectPartsForCodeCompletionCommand &command, ::std::ostream* os); +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::RegisterProjectPartsForCodeCompletionCommand) + +#endif // CLANGBACKEND_REGISTERPROJECTSFORCODECOMPLETIONCOMAND_H diff --git a/src/libs/clangbackendipc/cmbregistertranslationunitsforcodecompletioncommand.cpp b/src/libs/clangbackendipc/cmbregistertranslationunitsforcodecompletioncommand.cpp new file mode 100644 index 0000000000..39b3d083db --- /dev/null +++ b/src/libs/clangbackendipc/cmbregistertranslationunitsforcodecompletioncommand.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cmbregistertranslationunitsforcodecompletioncommand.h" + +#include + +#include + +#include + +#include "container_common.h" + +namespace ClangBackEnd { + +RegisterTranslationUnitForCodeCompletionCommand::RegisterTranslationUnitForCodeCompletionCommand(const QVector &fileContainers) + : fileContainers_(fileContainers) +{ +} + +const QVector &RegisterTranslationUnitForCodeCompletionCommand::fileContainers() const +{ + return fileContainers_; +} + +QDataStream &operator<<(QDataStream &out, const RegisterTranslationUnitForCodeCompletionCommand &command) +{ + out << command.fileContainers_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, RegisterTranslationUnitForCodeCompletionCommand &command) +{ + in >> command.fileContainers_; + + return in; +} + +bool operator==(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second) +{ + return first.fileContainers_ == second.fileContainers_; +} + +bool operator<(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second) +{ + return compareContainer(first.fileContainers_, second.fileContainers_); +} + +QDebug operator<<(QDebug debug, const RegisterTranslationUnitForCodeCompletionCommand &command) +{ + debug.nospace() << "RegisterTranslationUnitForCodeCompletionCommand("; + + for (const FileContainer &fileContainer : command.fileContainers()) + debug.nospace() << fileContainer<< ", "; + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const RegisterTranslationUnitForCodeCompletionCommand &command, ::std::ostream* os) +{ + *os << "RegisterTranslationUnitForCodeCompletionCommand("; + + for (const FileContainer &fileContainer : command.fileContainers()) + PrintTo(fileContainer, os); + + *os << ")"; +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/cmbregistertranslationunitsforcodecompletioncommand.h b/src/libs/clangbackendipc/cmbregistertranslationunitsforcodecompletioncommand.h new file mode 100644 index 0000000000..e598b0cdb5 --- /dev/null +++ b/src/libs/clangbackendipc/cmbregistertranslationunitsforcodecompletioncommand.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_REGISTERFILEFORCODECOMPLETION_H +#define CLANGBACKEND_REGISTERFILEFORCODECOMPLETION_H + +#include + +#include +#include "filecontainer.h" + +namespace ClangBackEnd { + +class CMBIPC_EXPORT RegisterTranslationUnitForCodeCompletionCommand +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const RegisterTranslationUnitForCodeCompletionCommand &command); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, RegisterTranslationUnitForCodeCompletionCommand &command); + friend CMBIPC_EXPORT bool operator==(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second); + friend CMBIPC_EXPORT bool operator<(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second); + friend void PrintTo(const RegisterTranslationUnitForCodeCompletionCommand &command, ::std::ostream* os); +public: + RegisterTranslationUnitForCodeCompletionCommand() = default; + RegisterTranslationUnitForCodeCompletionCommand(const QVector &fileContainers); + + const QVector &fileContainers() const; + +private: + QVector fileContainers_; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const RegisterTranslationUnitForCodeCompletionCommand &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, RegisterTranslationUnitForCodeCompletionCommand &command); +CMBIPC_EXPORT bool operator==(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second); +CMBIPC_EXPORT bool operator<(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const RegisterTranslationUnitForCodeCompletionCommand &command); +void PrintTo(const RegisterTranslationUnitForCodeCompletionCommand &command, ::std::ostream* os); +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::RegisterTranslationUnitForCodeCompletionCommand) + +#endif // CLANGBACKEND_REGISTERFILEFORCODECOMPLITION_H diff --git a/src/libs/clangbackendipc/cmbunregisterprojectsforcodecompletioncommand.cpp b/src/libs/clangbackendipc/cmbunregisterprojectsforcodecompletioncommand.cpp new file mode 100644 index 0000000000..6abb3b45eb --- /dev/null +++ b/src/libs/clangbackendipc/cmbunregisterprojectsforcodecompletioncommand.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cmbunregisterprojectsforcodecompletioncommand.h" + +#include + +#include + +#include + +#include "container_common.h" + +namespace ClangBackEnd { + + +UnregisterProjectPartsForCodeCompletionCommand::UnregisterProjectPartsForCodeCompletionCommand(const Utf8StringVector &filePaths) + : filePaths_(filePaths) +{ +} + +const Utf8StringVector &UnregisterProjectPartsForCodeCompletionCommand::filePaths() const +{ + return filePaths_; +} + +QDataStream &operator<<(QDataStream &out, const UnregisterProjectPartsForCodeCompletionCommand &command) +{ + out << command.filePaths_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, UnregisterProjectPartsForCodeCompletionCommand &command) +{ + in >> command.filePaths_; + + return in; +} + +bool operator==(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second) +{ + return first.filePaths_ == second.filePaths_; +} + +bool operator<(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second) +{ + return compareContainer(first.filePaths_, second.filePaths_); +} + +QDebug operator<<(QDebug debug, const UnregisterProjectPartsForCodeCompletionCommand &command) +{ + debug.nospace() << "UnregisterProjectPartsForCodeCompletionCommand("; + + for (const Utf8String &fileNames_ : command.filePaths()) + debug.nospace() << fileNames_ << ", "; + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const UnregisterProjectPartsForCodeCompletionCommand &command, ::std::ostream* os) +{ + *os << "UnregisterProjectPartsForCodeCompletionCommand("; + + for (const Utf8String &fileNames_ : command.filePaths()) + *os << fileNames_.constData() << ", "; + + *os << ")"; +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/cmbunregisterprojectsforcodecompletioncommand.h b/src/libs/clangbackendipc/cmbunregisterprojectsforcodecompletioncommand.h new file mode 100644 index 0000000000..59bf8ce5c5 --- /dev/null +++ b/src/libs/clangbackendipc/cmbunregisterprojectsforcodecompletioncommand.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_UNREGISTERPROJECTSFORCODECOMPLETION_H +#define CLANGBACKEND_UNREGISTERPROJECTSFORCODECOMPLETION_H + +#include "clangbackendipc_global.h" + +#include + +#include + +namespace ClangBackEnd { + +class CMBIPC_EXPORT UnregisterProjectPartsForCodeCompletionCommand +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UnregisterProjectPartsForCodeCompletionCommand &command); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UnregisterProjectPartsForCodeCompletionCommand &command); + friend CMBIPC_EXPORT bool operator==(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second); + friend CMBIPC_EXPORT bool operator<(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second); + friend void PrintTo(const UnregisterProjectPartsForCodeCompletionCommand &command, ::std::ostream* os); + +public: + UnregisterProjectPartsForCodeCompletionCommand() = default; + UnregisterProjectPartsForCodeCompletionCommand(const Utf8StringVector &filePaths); + + const Utf8StringVector &filePaths() const; + +private: + Utf8StringVector filePaths_; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UnregisterProjectPartsForCodeCompletionCommand &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UnregisterProjectPartsForCodeCompletionCommand &command); +CMBIPC_EXPORT bool operator==(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second); +CMBIPC_EXPORT bool operator<(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const UnregisterProjectPartsForCodeCompletionCommand &command); +void PrintTo(const UnregisterProjectPartsForCodeCompletionCommand &command, ::std::ostream* os); +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::UnregisterProjectPartsForCodeCompletionCommand) + +#endif // CLANGBACKEND_UNREGISTERPROJECTSFORCODECOMPLETION_H diff --git a/src/libs/clangbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.cpp b/src/libs/clangbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.cpp new file mode 100644 index 0000000000..cf19c18a7c --- /dev/null +++ b/src/libs/clangbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cmbunregistertranslationunitsforcodecompletioncommand.h" + +#include + +#ifdef CLANGBACKEND_TESTS +#include +#endif + +#include + +#include "container_common.h" + +namespace ClangBackEnd { + + +UnregisterTranslationUnitsForCodeCompletionCommand::UnregisterTranslationUnitsForCodeCompletionCommand(const QVector &fileContainers) + : fileContainers_(fileContainers) +{ +} + +const QVector &UnregisterTranslationUnitsForCodeCompletionCommand::fileContainers() const +{ + return fileContainers_; +} + +QDataStream &operator<<(QDataStream &out, const UnregisterTranslationUnitsForCodeCompletionCommand &command) +{ + out << command.fileContainers_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, UnregisterTranslationUnitsForCodeCompletionCommand &command) +{ + in >> command.fileContainers_; + + return in; +} + +bool operator==(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second) +{ + return first.fileContainers_ == second.fileContainers_; +} + +bool operator<(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second) +{ + return compareContainer(first.fileContainers_, second.fileContainers_); +} + +QDebug operator<<(QDebug debug, const UnregisterTranslationUnitsForCodeCompletionCommand &command) +{ + debug.nospace() << "UnregisterTranslationUnitsForCodeCompletionCommand("; + + for (const FileContainer &fileContainer : command.fileContainers()) + debug.nospace() << fileContainer << ", "; + + debug.nospace() << ")"; + + return debug; +} + +#ifdef CLANGBACKEND_TESTS +void PrintTo(const UnregisterTranslationUnitsForCodeCompletionCommand &command, ::std::ostream* os) +{ + *os << "UnregisterTranslationUnitsForCodeCompletionCommand("; + + for (const FileContainer &fileContainer : command.fileContainers()) + *os << ::testing::PrintToString(fileContainer) << ", "; + + *os << ")"; +} +#endif + + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.h b/src/libs/clangbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.h new file mode 100644 index 0000000000..327dd99556 --- /dev/null +++ b/src/libs/clangbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_UNRegisterTranslationUnitForCodeCompletionCommand_H +#define CLANGBACKEND_UNRegisterTranslationUnitForCodeCompletionCommand_H + +#include "clangbackendipc_global.h" + +#include "filecontainer.h" + +#include +#include + +namespace ClangBackEnd { + +class CMBIPC_EXPORT UnregisterTranslationUnitsForCodeCompletionCommand +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UnregisterTranslationUnitsForCodeCompletionCommand &command); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UnregisterTranslationUnitsForCodeCompletionCommand &command); + friend CMBIPC_EXPORT bool operator==(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second); + friend CMBIPC_EXPORT bool operator<(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second); + friend void PrintTo(const UnregisterTranslationUnitsForCodeCompletionCommand &command, ::std::ostream* os); + +public: + UnregisterTranslationUnitsForCodeCompletionCommand() = default; + UnregisterTranslationUnitsForCodeCompletionCommand(const QVector &fileContainers); + + const QVector &fileContainers() const; + +private: + QVector fileContainers_; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UnregisterTranslationUnitsForCodeCompletionCommand &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UnregisterTranslationUnitsForCodeCompletionCommand &command); +CMBIPC_EXPORT bool operator==(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second); +CMBIPC_EXPORT bool operator<(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const UnregisterTranslationUnitsForCodeCompletionCommand &command); +#ifdef CLANGBACKEND_TESTS +void PrintTo(const UnregisterTranslationUnitsForCodeCompletionCommand &command, ::std::ostream* os); +#endif +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand) + +#endif // CLANGBACKEND_UNRegisterTranslationUnitForCodeCompletionCommand_H diff --git a/src/libs/clangbackendipc/codecompletion.cpp b/src/libs/clangbackendipc/codecompletion.cpp new file mode 100644 index 0000000000..542fcf4e13 --- /dev/null +++ b/src/libs/clangbackendipc/codecompletion.cpp @@ -0,0 +1,255 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "codecompletion.h" + +#include + +#include + +#include + +namespace ClangBackEnd { + +CodeCompletion::CodeCompletion(const Utf8String &text, + const Utf8String &hint, + const Utf8String &snippet, + quint32 priority, + Kind completionKind, + Availability availability, + bool hasParameters) + : text_(text), + hint_(hint), + snippet_(snippet), + priority_(priority), + completionKind_(completionKind), + availability_(availability), + hasParameters_(hasParameters) +{ +} + +void CodeCompletion::setText(const Utf8String &text) +{ + text_ = text; +} + +const Utf8String &CodeCompletion::text() const +{ + return text_; +} +const Utf8String &CodeCompletion::hint() const +{ + return hint_; +} + +const Utf8String &CodeCompletion::snippet() const +{ + return snippet_; +} + +void CodeCompletion::setCompletionKind(CodeCompletion::Kind completionKind) +{ + completionKind_ = completionKind; +} + +CodeCompletion::Kind CodeCompletion::completionKind() const +{ + return completionKind_; +} + +void CodeCompletion::setChunks(const QVector &chunks) +{ + chunks_ = chunks; +} + +const QVector &CodeCompletion::chunks() const +{ + return chunks_; +} + +void CodeCompletion::setAvailability(CodeCompletion::Availability availability) +{ + availability_ = availability; +} + +CodeCompletion::Availability CodeCompletion::availability() const +{ + return availability_; +} + +void CodeCompletion::setHasParameters(bool hasParameters) +{ + hasParameters_ = hasParameters; +} + +bool CodeCompletion::hasParameters() const +{ + return hasParameters_; +} + +void CodeCompletion::setPriority(quint32 priority) +{ + priority_ = priority; +} + +quint32 CodeCompletion::priority() const +{ + return priority_; +} + +quint32 &CodeCompletion::completionKindAsInt() +{ + return reinterpret_cast(completionKind_); +} + +quint32 &CodeCompletion::availabilityAsInt() +{ + return reinterpret_cast(availability_); +} + +QDataStream &operator<<(QDataStream &out, const CodeCompletion &command) +{ + out << command.text_; + out << command.hint_; + out << command.snippet_; + out << command.chunks_; + out << command.priority_; + out << command.completionKind_; + out << command.availability_; + out << command.hasParameters_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, CodeCompletion &command) +{ + in >> command.text_; + in >> command.hint_; + in >> command.snippet_; + in >> command.chunks_; + in >> command.priority_; + in >> command.completionKindAsInt(); + in >> command.availabilityAsInt(); + in >> command.hasParameters_; + + return in; +} + +bool operator==(const CodeCompletion &first, const CodeCompletion &second) +{ + return first.text_ == second.text_ + && first.completionKind_ == second.completionKind_; +} + +bool operator<(const CodeCompletion &first, const CodeCompletion &second) +{ + return first.text_ < second.text_; +} + +static const char *completionKindToString(CodeCompletion::Kind kind) +{ + switch (kind) { + case CodeCompletion::Other: return "Other"; + case CodeCompletion::FunctionCompletionKind: return "Function"; + case CodeCompletion::TemplateFunctionCompletionKind: return "TemplateFunction"; + case CodeCompletion::ConstructorCompletionKind: return "Constructor"; + case CodeCompletion::DestructorCompletionKind: return "Destructor"; + case CodeCompletion::VariableCompletionKind: return "Variable"; + case CodeCompletion::ClassCompletionKind: return "Class"; + case CodeCompletion::TemplateClassCompletionKind: return "TemplateClass"; + case CodeCompletion::EnumerationCompletionKind: return "Enumeration"; + case CodeCompletion::EnumeratorCompletionKind: return "Enumerator"; + case CodeCompletion::NamespaceCompletionKind: return "Namespace"; + case CodeCompletion::PreProcessorCompletionKind: return "PreProcessor"; + case CodeCompletion::SignalCompletionKind: return "Signal"; + case CodeCompletion::SlotCompletionKind: return "Slot"; + case CodeCompletion::ObjCMessageCompletionKind: return "ObjCMessage"; + case CodeCompletion::KeywordCompletionKind: return "Keyword"; + case CodeCompletion::ClangSnippetKind: return "ClangSnippet"; + } + + return nullptr; +} + +static const char *availabilityToString(CodeCompletion::Availability availability) +{ + switch (availability) { + case CodeCompletion::Available: return "Available"; + case CodeCompletion::Deprecated: return "Deprecated"; + case CodeCompletion::NotAvailable: return "NotAvailable"; + case CodeCompletion::NotAccessible: return "NotAccessible"; + } + return nullptr; +} + +QDebug operator<<(QDebug debug, const CodeCompletion &command) +{ + debug.nospace() << "CodeCompletion("; + + debug.nospace() << command.text_ << ", "; + debug.nospace() << command.hint_ << ", "; + debug.nospace() << command.snippet_ << ", "; + debug.nospace() << command.priority_ << ", "; + debug.nospace() << completionKindToString(command.completionKind_) << ", "; + debug.nospace() << availabilityToString(command.availability_) << ", "; + debug.nospace() << command.hasParameters_; + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const CodeCompletion &command, ::std::ostream* os) +{ + *os << "CodeCompletion("; + + *os << command.text_.constData() << ", "; + *os << command.hint_.constData() << ", "; + *os << command.snippet_.constData() << ", "; + *os << command.priority_ << ", "; + *os << completionKindToString(command.completionKind_) << ", "; + *os << availabilityToString(command.availability_) << ", "; + *os << command.hasParameters_; + + *os << ")"; +} + +void PrintTo(CodeCompletion::Kind kind, ::std::ostream *os) +{ + *os << completionKindToString(kind); +} + +void PrintTo(CodeCompletion::Availability availability, std::ostream *os) +{ + *os << availabilityToString(availability); +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/codecompletion.h b/src/libs/clangbackendipc/codecompletion.h new file mode 100644 index 0000000000..328fa50402 --- /dev/null +++ b/src/libs/clangbackendipc/codecompletion.h @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_CODECOMPLETION_H +#define CLANGBACKEND_CODECOMPLETION_H + +#include +#include + +#include "codecompletionchunk.h" + +#include "clangbackendipc_global.h" + +namespace ClangBackEnd { + +class CMBIPC_EXPORT CodeCompletion +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletion &command); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CodeCompletion &command); + friend CMBIPC_EXPORT bool operator==(const CodeCompletion &first, const CodeCompletion &second); + friend CMBIPC_EXPORT bool operator<(const CodeCompletion &first, const CodeCompletion &second); + friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CodeCompletion &command); + friend void PrintTo(const CodeCompletion &command, ::std::ostream* os); + +public: + enum Kind : quint32 { + Other = 0, + FunctionCompletionKind, + TemplateFunctionCompletionKind, + ConstructorCompletionKind, + DestructorCompletionKind, + VariableCompletionKind, + ClassCompletionKind, + TemplateClassCompletionKind, + EnumerationCompletionKind, + EnumeratorCompletionKind, + NamespaceCompletionKind, + PreProcessorCompletionKind, + SignalCompletionKind, + SlotCompletionKind, + ObjCMessageCompletionKind, + KeywordCompletionKind, + ClangSnippetKind + }; + + enum Availability : quint32 { + Available, + Deprecated, + NotAvailable, + NotAccessible + }; + +public: + CodeCompletion() = default; + CodeCompletion(const Utf8String &text, + const Utf8String &hint = Utf8String(), + const Utf8String &snippet = Utf8String(), + quint32 priority = 0, + Kind completionKind = Other, + Availability availability = Available, + bool hasParameters = false); + + void setText(const Utf8String &text); + const Utf8String &text() const; + + const Utf8String &hint() const; + const Utf8String &snippet() const; + + void setCompletionKind(Kind completionKind); + Kind completionKind() const; + + void setChunks(const QVector &chunks); + const QVector &chunks() const; + + void setAvailability(Availability availability); + Availability availability() const; + + void setHasParameters(bool hasParameters); + bool hasParameters() const; + + void setPriority(quint32 priority); + quint32 priority() const; + +private: + quint32 &completionKindAsInt(); + quint32 &availabilityAsInt(); + +private: + Utf8String text_; + Utf8String hint_; + Utf8String snippet_; + QVector chunks_; + quint32 priority_ = 0; + Kind completionKind_ = Other; + Availability availability_ = NotAvailable; + bool hasParameters_ = false; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletion &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CodeCompletion &command); +CMBIPC_EXPORT bool operator==(const CodeCompletion &first, const CodeCompletion &second); +CMBIPC_EXPORT bool operator<(const CodeCompletion &first, const CodeCompletion &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CodeCompletion &command); +CMBIPC_EXPORT QDebug operator<<(QDebug debug, CodeCompletion::Kind kind); + +void PrintTo(const CodeCompletion &command, ::std::ostream* os); +void PrintTo(CodeCompletion::Kind kind, ::std::ostream *os); +void PrintTo(CodeCompletion::Availability availability, ::std::ostream *os); +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::CodeCompletion) + +#endif // CLANGBACKEND_CODECOMPLETION_H diff --git a/src/libs/clangbackendipc/codecompletionchunk.cpp b/src/libs/clangbackendipc/codecompletionchunk.cpp new file mode 100644 index 0000000000..5b5dfbb587 --- /dev/null +++ b/src/libs/clangbackendipc/codecompletionchunk.cpp @@ -0,0 +1,178 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "codecompletionchunk.h" + +#include + +#include + +#include + +namespace ClangBackEnd { + +CodeCompletionChunk::CodeCompletionChunk() + : kind_(Invalid) +{ +} + +CodeCompletionChunk::CodeCompletionChunk(CodeCompletionChunk::Kind kind, + const Utf8String &text, + const QVector &optionalChunks) + : text_(text), + optionalChunks_(optionalChunks), + kind_(kind) +{ +} + +CodeCompletionChunk::Kind CodeCompletionChunk::kind() const +{ + return kind_; +} + +const Utf8String &CodeCompletionChunk::text() const +{ + return text_; +} + +const QVector &CodeCompletionChunk::optionalChunks() const +{ + return optionalChunks_; +} + +quint32 &CodeCompletionChunk::kindAsInt() +{ + return reinterpret_cast(kind_); +} + +QDataStream &operator<<(QDataStream &out, const CodeCompletionChunk &chunk) +{ + out << chunk.kind_; + out << chunk.text_; + + if (chunk.kind() == CodeCompletionChunk::Optional) + out << chunk.optionalChunks_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, CodeCompletionChunk &chunk) +{ + in >> chunk.kindAsInt(); + in >> chunk.text_; + + if (chunk.kind_ == CodeCompletionChunk::Optional) + in >> chunk.optionalChunks_; + + return in; +} + +bool operator==(const CodeCompletionChunk &first, const CodeCompletionChunk &second) +{ + return first.kind() == second.kind() + && first.text() == second.text() + && first.optionalChunks() == second.optionalChunks(); +} + +static const char *completionChunkKindToString(CodeCompletionChunk::Kind kind) +{ + switch (kind) { + case CodeCompletionChunk::Optional: return "Optional"; + case CodeCompletionChunk::TypedText: return "TypedText"; + case CodeCompletionChunk::Text: return "Text"; + case CodeCompletionChunk::Placeholder: return "Placeholder"; + case CodeCompletionChunk::Informative: return "Informative"; + case CodeCompletionChunk::CurrentParameter: return "CurrentParameter"; + case CodeCompletionChunk::LeftParen: return "LeftParen"; + case CodeCompletionChunk::RightParen: return "RightParen"; + case CodeCompletionChunk::LeftBracket: return "LeftBracket"; + case CodeCompletionChunk::RightBracket: return "RightBracket"; + case CodeCompletionChunk::LeftBrace: return "LeftBrace"; + case CodeCompletionChunk::RightBrace: return "RightBrace"; + case CodeCompletionChunk::LeftAngle: return "LeftAngle"; + case CodeCompletionChunk::RightAngle: return "RightAngle"; + case CodeCompletionChunk::Comma: return "Comma"; + case CodeCompletionChunk::ResultType: return "ResultType"; + case CodeCompletionChunk::Colon: return "Colon"; + case CodeCompletionChunk::SemiColon: return "SemiColon"; + case CodeCompletionChunk::Equal: return "Equal"; + case CodeCompletionChunk::HorizontalSpace: return "HorizontalSpace"; + case CodeCompletionChunk::VerticalSpace: return "VerticalSpace"; + case CodeCompletionChunk::Invalid: return "Invalid"; + } + + return nullptr; +} + +QDebug operator<<(QDebug debug, const CodeCompletionChunk &chunk) +{ + debug.nospace() << "CodeCompletionChunk("; + debug.nospace() << completionChunkKindToString(chunk.kind()) << ", "; + debug.nospace() << chunk.text(); + + if (chunk.kind() == CodeCompletionChunk::Optional) + debug.nospace() << ", " << chunk.optionalChunks(); + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const CodeCompletionChunk &chunk, ::std::ostream* os) +{ + *os << "{"; + *os << completionChunkKindToString(chunk.kind()) << ", "; + *os << chunk.text().constData(); + + if (chunk.kind() == CodeCompletionChunk::Optional) { + const auto optionalChunks = chunk.optionalChunks(); + *os << ", {"; + + for (auto optionalChunkPosition = optionalChunks.cbegin(); + optionalChunkPosition != optionalChunks.cend(); + ++optionalChunkPosition) { + PrintTo(*optionalChunkPosition, os); + if (std::next(optionalChunkPosition) != optionalChunks.cend()) + *os << ", "; + } + + *os << "}"; + } + + *os << "}"; +} + +void PrintTo(const CodeCompletionChunk::Kind &kind, ::std::ostream* os) +{ + *os << completionChunkKindToString(kind); +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/codecompletionchunk.h b/src/libs/clangbackendipc/codecompletionchunk.h new file mode 100644 index 0000000000..d6b481ab72 --- /dev/null +++ b/src/libs/clangbackendipc/codecompletionchunk.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_CODECOMPLETIONCHUNK_H +#define CLANGBACKEND_CODECOMPLETIONCHUNK_H + +#include + +#include + +#include "clangbackendipc_global.h" + +namespace ClangBackEnd { + +class CMBIPC_EXPORT CodeCompletionChunk +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletionChunk &chunk); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CodeCompletionChunk &chunk); + friend CMBIPC_EXPORT bool operator==(const CodeCompletionChunk &first, const CodeCompletionChunk &second); + +public: + enum Kind : quint32 { + Optional, + TypedText, + Text, + Placeholder, + Informative, + CurrentParameter, + LeftParen, + RightParen, + LeftBracket, + RightBracket, + LeftBrace, + RightBrace, + LeftAngle, + RightAngle, + Comma, + ResultType, + Colon, + SemiColon, + Equal, + HorizontalSpace, + VerticalSpace, + Invalid = 255}; + + CodeCompletionChunk(); + CodeCompletionChunk(Kind kind, + const Utf8String &text, + const QVector &optionalChunks = QVector()); + + Kind kind() const; + const Utf8String &text() const; + const QVector &optionalChunks() const; + +private: + quint32 &kindAsInt(); + +private: + Utf8String text_; + QVector optionalChunks_; + Kind kind_ = Invalid; + +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletionChunk &chunk); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CodeCompletionChunk &chunk); +CMBIPC_EXPORT bool operator==(const CodeCompletionChunk &first, const CodeCompletionChunk &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CodeCompletionChunk &chunk); + +void PrintTo(const CodeCompletionChunk &chunk, ::std::ostream* os); +void PrintTo(const CodeCompletionChunk::Kind &kind, ::std::ostream* os); + +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::CodeCompletionChunk) + +#endif // CLANGBACKEND_CODECOMPLETIONCHUNK_H diff --git a/src/libs/clangbackendipc/connectionclient.cpp b/src/libs/clangbackendipc/connectionclient.cpp new file mode 100644 index 0000000000..c2f504e036 --- /dev/null +++ b/src/libs/clangbackendipc/connectionclient.cpp @@ -0,0 +1,288 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "connectionclient.h" + +#include +#include +#include + +#include "cmbregistertranslationunitsforcodecompletioncommand.h" +#include "cmbunregistertranslationunitsforcodecompletioncommand.h" +#include "cmbcompletecodecommand.h" + +namespace ClangBackEnd { + +namespace { +QString currentProcessId() +{ + return QString::number(QCoreApplication::applicationPid()); +} + +QString connectionName() +{ + return QStringLiteral("ClangBackEnd-") + currentProcessId(); +} +} + +ConnectionClient::ConnectionClient(IpcClientInterface *client) + : serverProxy_(client, &localSocket), + isAliveTimerResetted(false) +{ + processAliveTimer.setInterval(10000); + + connect(&processAliveTimer, &QTimer::timeout, + this, &ConnectionClient::restartProcessIfTimerIsNotResettedAndSocketIsEmpty); + + connect(&localSocket, + static_cast(&QLocalSocket::error), + this, + &ConnectionClient::printLocalSocketError); +} + +ConnectionClient::~ConnectionClient() +{ + finishProcess(); +} + +bool ConnectionClient::connectToServer() +{ + startProcess(); + resetProcessAliveTimer(); + const bool isConnected = connectToLocalSocket(); + + return isConnected; +} + +bool ConnectionClient::disconnectFromServer() +{ + localSocket.disconnectFromServer(); + if (localSocket.state() != QLocalSocket::UnconnectedState) + return localSocket.waitForDisconnected(); + + return true; +} + +bool ConnectionClient::isConnected() const +{ + return localSocket.state() == QLocalSocket::ConnectedState; +} + +void ConnectionClient::sendEndCommand() +{ + serverProxy_.end(); + localSocket.flush(); +} + +void ConnectionClient::resetProcessAliveTimer() +{ + isAliveTimerResetted = true; + processAliveTimer.start(); +} + +void ConnectionClient::setProcessAliveTimerInterval(int processTimerInterval) +{ + processAliveTimer.setInterval(processTimerInterval); +} + +void ConnectionClient::startProcess() +{ + if (!isProcessIsRunning()) { + connectProcessFinished(); + connectStandardOutputAndError(); + process()->start(processPath(), {connectionName()}); + process()->waitForStarted(); + resetProcessAliveTimer(); + } +} + +void ConnectionClient::restartProcess() +{ + finishProcess(); + startProcess(); + + connectToServer(); + + emit processRestarted(); +} + +void ConnectionClient::restartProcessIfTimerIsNotResettedAndSocketIsEmpty() +{ + if (isAliveTimerResetted) { + isAliveTimerResetted = false; + return; // Already reset, but we were scheduled after. + } + + if (localSocket.bytesAvailable() > 0) + return; // We come first, the incoming data was not yet processed. + + restartProcess(); +} + +bool ConnectionClient::connectToLocalSocket() +{ + QThread::msleep(30); + + for (int counter = 0; counter < 1000; counter++) { + localSocket.connectToServer(connectionName()); + bool isConnected = localSocket.waitForConnected(20); + + if (isConnected) + return isConnected; + else + QThread::msleep(30); + } + + qDebug() << "Cannot connect:" <waitForFinished(); + } +} + +void ConnectionClient::terminateProcess() +{ +#ifndef Q_OS_WIN32 + if (isProcessIsRunning()) { + process()->terminate(); + process()->waitForFinished(); + } +#endif +} + +void ConnectionClient::killProcess() +{ + if (isProcessIsRunning()) { + process()->kill(); + process()->waitForFinished(); + } +} + +void ConnectionClient::printLocalSocketError(QLocalSocket::LocalSocketError /*socketError*/) +{ + qWarning() << "ClangCodeModel ConnectionClient LocalSocket Error:" << localSocket.errorString(); +} + +void ConnectionClient::printStandardOutput() +{ + qWarning() << "ClangBackEnd:" << process_->readAllStandardOutput(); +} + +void ConnectionClient::printStandardError() +{ + qWarning() << "ClangBackEnd Error:" << process_->readAllStandardError(); +} + +void ConnectionClient::finishProcess() +{ + processAliveTimer.stop(); + + disconnectProcessFinished(); + endProcess(); + disconnectFromServer(); + terminateProcess(); + killProcess(); + + process_.reset(); + + serverProxy_.resetCounter(); +} + +bool ConnectionClient::waitForEcho() +{ + return localSocket.waitForReadyRead(); +} + +IpcServerProxy &ConnectionClient::serverProxy() +{ + return serverProxy_; +} + +QProcess *ConnectionClient::processForTestOnly() const +{ + return process_.get(); +} + +bool ConnectionClient::isProcessIsRunning() const +{ + return process_ && process_->state() == QProcess::Running; +} + +QProcess *ConnectionClient::process() const +{ + if (!process_) + process_.reset(new QProcess); + + return process_.get(); +} + +void ConnectionClient::connectProcessFinished() const +{ + connect(process(), + static_cast(&QProcess::finished), + this, + &ConnectionClient::restartProcess); + +} + +void ConnectionClient::disconnectProcessFinished() const +{ + if (process_) { + disconnect(process_.get(), + static_cast(&QProcess::finished), + this, + &ConnectionClient::restartProcess); + } +} + +void ConnectionClient::connectStandardOutputAndError() const +{ + connect(process(), &QProcess::readyReadStandardOutput, this, &ConnectionClient::printStandardOutput); + connect(process(), &QProcess::readyReadStandardError, this, &ConnectionClient::printStandardError); +} + +const QString &ConnectionClient::processPath() const +{ + return processPath_; +} + +void ConnectionClient::setProcessPath(const QString &processPath) +{ + processPath_ = processPath; +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/connectionclient.h b/src/libs/clangbackendipc/connectionclient.h new file mode 100644 index 0000000000..390995792b --- /dev/null +++ b/src/libs/clangbackendipc/connectionclient.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_CONNECTIONCLIENT_H +#define CLANGBACKEND_CONNECTIONCLIENT_H + +#include + +#include + +#include "ipcserverproxy.h" + +QT_BEGIN_NAMESPACE +class QProcess; +QT_END_NAMESPACE + +class Utf8String; +class Utf8StringVector; + +namespace ClangBackEnd { + +class FileContainer; + +class CMBIPC_EXPORT ConnectionClient : public QObject +{ + Q_OBJECT + +public: + ConnectionClient(IpcClientInterface *client); + ~ConnectionClient(); + + bool connectToServer(); + bool disconnectFromServer(); + bool isConnected() const; + + void sendEndCommand(); + + void resetProcessAliveTimer(); + void setProcessAliveTimerInterval(int processTimerInterval); + + const QString &processPath() const; + void setProcessPath(const QString &processPath); + + void startProcess(); + void restartProcess(); + void restartProcessIfTimerIsNotResettedAndSocketIsEmpty(); + void finishProcess(); + bool isProcessIsRunning() const; + + bool waitForEcho(); + + IpcServerProxy &serverProxy(); + + QProcess *processForTestOnly() const; + +signals: + void processRestarted(); + +private: + bool connectToLocalSocket(); + void endProcess(); + void terminateProcess(); + void killProcess(); + void printLocalSocketError(QLocalSocket::LocalSocketError socketError); + void printStandardOutput(); + void printStandardError(); + + QProcess *process() const; + void connectProcessFinished() const; + void disconnectProcessFinished() const; + void connectStandardOutputAndError() const; + + void waitUntilSocketIsFlushed() const; + +private: + mutable std::unique_ptr process_; + QLocalSocket localSocket; + IpcServerProxy serverProxy_; + QTimer processAliveTimer; + QString processPath_; + bool isAliveTimerResetted; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_CONNECTIONCLIENT_H diff --git a/src/libs/clangbackendipc/connectionserver.cpp b/src/libs/clangbackendipc/connectionserver.cpp new file mode 100644 index 0000000000..f16e2f56d7 --- /dev/null +++ b/src/libs/clangbackendipc/connectionserver.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "connectionserver.h" + +#include +#include +#include + +#include + +#include + +namespace ClangBackEnd { + +QString ConnectionServer::connectionName; + +ConnectionServer::ConnectionServer(const QString &connectionName) + : aliveTimerId(startTimer(5000)) +{ + this->connectionName = connectionName; + + connect(&localServer, &QLocalServer::newConnection, this, &ConnectionServer::handleNewConnection); + std::atexit(&ConnectionServer::removeServer); +#if defined(_GLIBCXX_HAVE_AT_QUICK_EXIT) + std::at_quick_exit(&ConnectionServer::removeServer); +#endif + std::set_terminate(&ConnectionServer::removeServer); +} + +ConnectionServer::~ConnectionServer() +{ + removeServer(); +} + +void ConnectionServer::start() +{ + QLocalServer::removeServer(connectionName); + localServer.listen(connectionName); +} + +void ConnectionServer::setIpcServer(IpcServerInterface *ipcServer) +{ + this->ipcServer = ipcServer; + +} + +int ConnectionServer::clientProxyCount() const +{ + return ipcClientProxies.size(); +} + +void ConnectionServer::timerEvent(QTimerEvent *timerEvent) +{ + if (aliveTimerId == timerEvent->timerId()) + sendAliveCommand(); +} + +void ConnectionServer::handleNewConnection() +{ + QLocalSocket *localSocket(nextPendingConnection()); + + ipcClientProxies.emplace_back(ipcServer, localSocket); + + ipcServer->addClient(&ipcClientProxies.back()); + + localSockets.push_back(localSocket); + + emit newConnection(); +} + +void ConnectionServer::sendAliveCommand() +{ + ipcServer->client()->alive(); +} + +void ConnectionServer::handleSocketDisconnect() +{ + QLocalSocket *senderLocalSocket = static_cast(sender()); + + removeClientProxyWithLocalSocket(senderLocalSocket); + localSockets.erase(std::remove_if(localSockets.begin(), + localSockets.end(), + [senderLocalSocket](QLocalSocket *localSocketInList) { return localSocketInList == senderLocalSocket;})); + + delayedExitApplicationIfNoSockedIsConnected(); +} + +void ConnectionServer::removeClientProxyWithLocalSocket(QLocalSocket *localSocket) +{ + ipcClientProxies.erase(std::remove_if(ipcClientProxies.begin(), + ipcClientProxies.end(), + [localSocket](const IpcClientProxy &client) { return client.isUsingThatIoDevice(localSocket);})); +} + +QLocalSocket *ConnectionServer::nextPendingConnection() +{ + QLocalSocket *localSocket = localServer.nextPendingConnection(); + + connect(localSocket, &QLocalSocket::disconnected, this, &ConnectionServer::handleSocketDisconnect); + + return localSocket; +} + +void ConnectionServer::removeServer() +{ + QLocalServer::removeServer(connectionName); +} + +void ConnectionServer::delayedExitApplicationIfNoSockedIsConnected() +{ + if (localSockets.size() == 0) + QTimer::singleShot(60000, this, &ConnectionServer::exitApplicationIfNoSockedIsConnected); +} + +void ConnectionServer::exitApplicationIfNoSockedIsConnected() +{ + if (localSockets.size() == 0) + QCoreApplication::exit(); +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/connectionserver.h b/src/libs/clangbackendipc/connectionserver.h new file mode 100644 index 0000000000..27d1265c95 --- /dev/null +++ b/src/libs/clangbackendipc/connectionserver.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_CONNECTIONSERVER_H +#define CLANGBACKEND_CONNECTIONSERVER_H + +#include +#include +#include + +namespace ClangBackEnd { + +class IpcServerInterface; +class IpcClientProxy; + +class CMBIPC_EXPORT ConnectionServer : public QObject +{ + Q_OBJECT +public: + ConnectionServer(const QString &connectionName); + ~ConnectionServer(); + + void start(); + void setIpcServer(IpcServerInterface *ipcServer); + + int clientProxyCount() const; + + static void removeServer(); + +signals: + void newConnection(); + +protected: + void timerEvent(QTimerEvent *timerEvent); + +private: + void handleNewConnection(); + void sendAliveCommand(); + void handleSocketDisconnect(); + void removeClientProxyWithLocalSocket(QLocalSocket *localSocket); + QLocalSocket *nextPendingConnection(); + void delayedExitApplicationIfNoSockedIsConnected(); + void exitApplicationIfNoSockedIsConnected(); + +private: + std::vector ipcClientProxies; + std::vector localSockets; + IpcServerInterface *ipcServer; + QLocalServer localServer; + static QString connectionName; + int aliveTimerId; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_CONNECTIONSERVER_H diff --git a/src/libs/clangbackendipc/container_common.h b/src/libs/clangbackendipc/container_common.h new file mode 100644 index 0000000000..e20b5d04ec --- /dev/null +++ b/src/libs/clangbackendipc/container_common.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CONTAINER_COMMON_H +#define CONTAINER_COMMON_H + + +namespace ClangBackEnd { + +template +bool compareContainer(const Container &first, const Container &second) +{ + if (first.size() != second.size()) + return first.size() < second.size(); + + Container firstCopy = first; + Container secondCopy = second; + + std::sort(firstCopy.begin(), firstCopy.end()); + std::sort(secondCopy.begin(), secondCopy.end()); + + auto isProjectPartContainerSmaller = [] (decltype(*first.cbegin()) &firstElement, + decltype(*second.cbegin()) &secondElement) { + return firstElement < secondElement; + }; + + return std::equal(firstCopy.cbegin(), + firstCopy.cend(), + secondCopy.cbegin(), + isProjectPartContainerSmaller); +} +} + +#endif // CONTAINER_COMMON_H + diff --git a/src/libs/clangbackendipc/filecontainer.cpp b/src/libs/clangbackendipc/filecontainer.cpp new file mode 100644 index 0000000000..9073ca6f37 --- /dev/null +++ b/src/libs/clangbackendipc/filecontainer.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "filecontainer.h" + +#include + +#include + +#include + +namespace ClangBackEnd { + +FileContainer::FileContainer(const Utf8String &fileName, + const Utf8String &projectPartId, + const Utf8String &unsavedFileContent, + bool hasUnsavedFileContent) + : filePath_(fileName), + projectPartId_(projectPartId), + unsavedFileContent_(unsavedFileContent), + hasUnsavedFileContent_(hasUnsavedFileContent) +{ +} + +const Utf8String &FileContainer::filePath() const +{ + return filePath_; +} + +const Utf8String &FileContainer::projectPartId() const +{ + return projectPartId_; +} + +const Utf8String &FileContainer::unsavedFileContent() const +{ + return unsavedFileContent_; +} + +bool FileContainer::hasUnsavedFileContent() const +{ + return hasUnsavedFileContent_; +} + +QDataStream &operator<<(QDataStream &out, const FileContainer &container) +{ + out << container.filePath_; + out << container.projectPartId_; + out << container.unsavedFileContent_; + out << container.hasUnsavedFileContent_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, FileContainer &container) +{ + in >> container.filePath_; + in >> container.projectPartId_; + in >> container.unsavedFileContent_; + in >> container.hasUnsavedFileContent_; + + return in; +} + +bool operator==(const FileContainer &first, const FileContainer &second) +{ + return first.filePath_ == second.filePath_ && first.projectPartId_ == second.projectPartId_; +} + +bool operator<(const FileContainer &first, const FileContainer &second) +{ + if (first.filePath_ == second.filePath_) + return first.projectPartId_ < second.projectPartId_; + + return first.filePath_ < second.filePath_; +} + +QDebug operator<<(QDebug debug, const FileContainer &container) +{ + debug.nospace() << "FileContainer(" + << container.filePath() + << ", " + << container.projectPartId(); + + if (container.hasUnsavedFileContent()) + debug.nospace() << ", " + << container.unsavedFileContent(); + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const FileContainer &container, ::std::ostream* os) +{ + *os << "FileContainer(" + << container.filePath().constData() + << ", " + << container.projectPartId().constData(); + + if (container.hasUnsavedFileContent()) + *os << ", " + << container.unsavedFileContent().constData(); + + *os << ")"; +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/filecontainer.h b/src/libs/clangbackendipc/filecontainer.h new file mode 100644 index 0000000000..2a749e0809 --- /dev/null +++ b/src/libs/clangbackendipc/filecontainer.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_FILECONTAINER_H +#define CLANGBACKEND_FILECONTAINER_H + +#include + +#include + +#include + +namespace ClangBackEnd { + +class CMBIPC_EXPORT FileContainer +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const FileContainer &container); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, FileContainer &container); + friend CMBIPC_EXPORT bool operator==(const FileContainer &first, const FileContainer &second); + friend CMBIPC_EXPORT bool operator<(const FileContainer &first, const FileContainer &second); +public: + FileContainer() = default; + FileContainer(const Utf8String &filePath, + const Utf8String &projectPartId, + const Utf8String &unsavedFileContent = Utf8String(), + bool hasUnsavedFileContent = false); + + const Utf8String &filePath() const; + const Utf8String &projectPartId() const; + const Utf8String &unsavedFileContent() const; + bool hasUnsavedFileContent() const; + +private: + Utf8String filePath_; + Utf8String projectPartId_; + Utf8String unsavedFileContent_; + bool hasUnsavedFileContent_ = false; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const FileContainer &container); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, FileContainer &container); +CMBIPC_EXPORT bool operator==(const FileContainer &first, const FileContainer &second); +CMBIPC_EXPORT bool operator<(const FileContainer &first, const FileContainer &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const FileContainer &container); +void PrintTo(const FileContainer &container, ::std::ostream* os); + +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::FileContainer) + +#endif // CLANGBACKEND_FILECONTAINER_H diff --git a/src/libs/clangbackendipc/ipcclientdispatcher.cpp b/src/libs/clangbackendipc/ipcclientdispatcher.cpp new file mode 100644 index 0000000000..7de8c7f01d --- /dev/null +++ b/src/libs/clangbackendipc/ipcclientdispatcher.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ipcclientdispatcher.h" + +#include + +namespace ClangBackEnd { + +void IpcClientDispatcher::addClient(IpcClientInterface *client) +{ + clients.append(client); +} + +void IpcClientDispatcher::removeClient(IpcClientInterface *client) +{ + clients.removeOne(client); +} + +void IpcClientDispatcher::alive() +{ + for (auto *client : clients) + client->alive(); +} + +void IpcClientDispatcher::echo(const EchoCommand &command) +{ + for (auto *client : clients) + client->echo(command); +} + +void IpcClientDispatcher::codeCompleted(const CodeCompletedCommand &command) +{ + for (auto *client : clients) + client->codeCompleted(command); +} + +void IpcClientDispatcher::translationUnitDoesNotExist(const TranslationUnitDoesNotExistCommand &command) +{ + for (auto *client : clients) + client->translationUnitDoesNotExist(command); +} + +void IpcClientDispatcher::projectPartsDoNotExist(const ProjectPartsDoNotExistCommand &command) +{ + for (auto *client : clients) + client->projectPartsDoNotExist(command); +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/ipcclientdispatcher.h b/src/libs/clangbackendipc/ipcclientdispatcher.h new file mode 100644 index 0000000000..70fd77b954 --- /dev/null +++ b/src/libs/clangbackendipc/ipcclientdispatcher.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_IPCCLIENTDISPATCHER_H +#define CLANGBACKEND_IPCCLIENTDISPATCHER_H + +#include "ipcclientinterface.h" + +#include + +namespace ClangBackEnd { + +class CMBIPC_EXPORT IpcClientDispatcher : public ClangBackEnd::IpcClientInterface +{ +public: + void addClient(IpcClientInterface *client); + void removeClient(IpcClientInterface *client); + + void alive() override; + void echo(const EchoCommand &command) override; + void codeCompleted(const CodeCompletedCommand &command) override; + void translationUnitDoesNotExist(const TranslationUnitDoesNotExistCommand &command) override; + void projectPartsDoNotExist(const ProjectPartsDoNotExistCommand &command) override; + +private: + QVector clients; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_IPCCLIENTDISPATCHER_H diff --git a/src/libs/clangbackendipc/ipcclientinterface.cpp b/src/libs/clangbackendipc/ipcclientinterface.cpp new file mode 100644 index 0000000000..b1959ceab3 --- /dev/null +++ b/src/libs/clangbackendipc/ipcclientinterface.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ipcclientinterface.h" + +#include +#include + +#include "cmbechocommand.h" +#include "cmbcodecompletedcommand.h" +#include "translationunitdoesnotexistcommand.h" +#include "projectpartsdonotexistcommand.h" + +namespace ClangBackEnd { + + +void IpcClientInterface::dispatch(const QVariant &command) +{ + static const int aliveCommandType = QMetaType::type("ClangBackEnd::AliveCommand"); + static const int echoCommandType = QMetaType::type("ClangBackEnd::EchoCommand"); + static const int codeCompletedCommandType = QMetaType::type("ClangBackEnd::CodeCompletedCommand"); + static const int translationUnitDoesNotExistCommand = QMetaType::type("ClangBackEnd::TranslationUnitDoesNotExistCommand"); + static const int projectPartsDoNotExistCommand = QMetaType::type("ClangBackEnd::ProjectPartsDoNotExistCommand"); + + int type = command.userType(); + + if (type == aliveCommandType) + alive(); + else if (type == echoCommandType) + echo(command.value()); + else if (type == codeCompletedCommandType) + codeCompleted(command.value()); + else if (type == translationUnitDoesNotExistCommand) + translationUnitDoesNotExist(command.value()); + else if (type == projectPartsDoNotExistCommand) + projectPartsDoNotExist(command.value()); + else + qWarning() << "Unknown IpcClientCommand"; +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/ipcclientinterface.h b/src/libs/clangbackendipc/ipcclientinterface.h new file mode 100644 index 0000000000..31db6d6c73 --- /dev/null +++ b/src/libs/clangbackendipc/ipcclientinterface.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_IPCCLIENTINTERFACE_H +#define CLANGBACKEND_IPCCLIENTINTERFACE_H + +#include "ipcinterface.h" + +namespace ClangBackEnd { + +class IpcServerInterface; +class RegisterTranslationUnitForCodeCompletionCommand; +class RegisterProjectPartsForCodeCompletionCommand; +class UnregisterTranslationUnitsForCodeCompletionCommand; +class UnregisterProjectPartsForCodeCompletionCommand; +class EchoCommand; +class CompleteCodeCommand; +class CodeCompletedCommand; +class TranslationUnitDoesNotExistCommand; +class ProjectPartsDoNotExistCommand; + +class CMBIPC_EXPORT IpcClientInterface : public IpcInterface +{ +public: + void dispatch(const QVariant &command) override; + + virtual void alive() = 0; + virtual void echo(const EchoCommand &command) = 0; + virtual void codeCompleted(const CodeCompletedCommand &command) = 0; + virtual void translationUnitDoesNotExist(const TranslationUnitDoesNotExistCommand &command) = 0; + virtual void projectPartsDoNotExist(const ProjectPartsDoNotExistCommand &command) = 0; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_IPCCLIENTINTERFACE_H diff --git a/src/libs/clangbackendipc/ipcclientproxy.cpp b/src/libs/clangbackendipc/ipcclientproxy.cpp new file mode 100644 index 0000000000..ea0655e7fb --- /dev/null +++ b/src/libs/clangbackendipc/ipcclientproxy.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ipcclientproxy.h" + +#include + +#include +#include +#include +#include + +#include "ipcserverinterface.h" +#include "cmbechocommand.h" +#include "cmbregistertranslationunitsforcodecompletioncommand.h" +#include "cmbcodecompletedcommand.h" +#include "translationunitdoesnotexistcommand.h" +#include "projectpartsdonotexistcommand.h" + +namespace ClangBackEnd { + +IpcClientProxy::IpcClientProxy(IpcServerInterface *server, QIODevice *ioDevice) + : writeCommandBlock(ioDevice), + readCommandBlock(ioDevice), + server(server), + ioDevice(ioDevice) +{ + QObject::connect(ioDevice, &QIODevice::readyRead, [this] () {IpcClientProxy::readCommands();}); +} + +IpcClientProxy::IpcClientProxy(IpcClientProxy &&other) + : writeCommandBlock(std::move(other.writeCommandBlock)), + readCommandBlock(std::move(other.readCommandBlock)), + server(std::move(other.server)), + ioDevice(std::move(other.ioDevice)) +{ + +} + +IpcClientProxy &IpcClientProxy::operator=(IpcClientProxy &&other) +{ + writeCommandBlock = std::move(other.writeCommandBlock); + readCommandBlock = std::move(other.readCommandBlock); + server = std::move(other.server); + ioDevice = std::move(other.ioDevice); + + return *this; +} + +void IpcClientProxy::alive() +{ + writeCommandBlock.write(QVariant::fromValue(AliveCommand())); +} + +void IpcClientProxy::echo(const EchoCommand &command) +{ + writeCommandBlock.write(QVariant::fromValue(command)); +} + +void IpcClientProxy::codeCompleted(const CodeCompletedCommand &command) +{ + writeCommandBlock.write(QVariant::fromValue(command)); +} + +void IpcClientProxy::translationUnitDoesNotExist(const TranslationUnitDoesNotExistCommand &command) +{ + writeCommandBlock.write(QVariant::fromValue(command)); +} + +void IpcClientProxy::projectPartsDoNotExist(const ProjectPartsDoNotExistCommand &command) +{ + writeCommandBlock.write(QVariant::fromValue(command)); +} + +void IpcClientProxy::readCommands() +{ + for (const QVariant &command : readCommandBlock.readAll()) + server->dispatch(command); +} + +bool IpcClientProxy::isUsingThatIoDevice(QIODevice *ioDevice) const +{ + return this->ioDevice == ioDevice; +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/ipcclientproxy.h b/src/libs/clangbackendipc/ipcclientproxy.h new file mode 100644 index 0000000000..36820266c0 --- /dev/null +++ b/src/libs/clangbackendipc/ipcclientproxy.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CODELMODELBACKEND_IPCCLIENTPROXY_H +#define CODELMODELBACKEND_IPCCLIENTPROXY_H + +#include + +#include + +#include "clangbackendipc_global.h" +#include "ipcclientinterface.h" + +#include "writecommandblock.h" +#include "readcommandblock.h" + +QT_BEGIN_NAMESPACE +class QLocalServer; +class QIODevice; +QT_END_NAMESPACE + +namespace ClangBackEnd { + +class CMBIPC_EXPORT IpcClientProxy : public IpcClientInterface +{ +public: + explicit IpcClientProxy(IpcServerInterface *server, QIODevice *ioDevice); + IpcClientProxy(const IpcClientProxy&) = delete; + const IpcClientProxy &operator=(const IpcClientProxy&) = delete; + + IpcClientProxy(IpcClientProxy&&other); + IpcClientProxy &operator=(IpcClientProxy&&other); + + void alive() override; + void echo(const EchoCommand &command) override; + void codeCompleted(const CodeCompletedCommand &command) override; + void translationUnitDoesNotExist(const TranslationUnitDoesNotExistCommand &command) override; + void projectPartsDoNotExist(const ProjectPartsDoNotExistCommand &command) override; + + void readCommands(); + + bool isUsingThatIoDevice(QIODevice *ioDevice) const; + +private: + ClangBackEnd::WriteCommandBlock writeCommandBlock; + ClangBackEnd::ReadCommandBlock readCommandBlock; + IpcServerInterface *server = nullptr; + QIODevice *ioDevice = nullptr; +}; + +} // namespace ClangBackEnd + +#endif // CODELMODELBACKEND_IPCCLIENTPROXY_H diff --git a/src/libs/clangbackendipc/ipcinterface.cpp b/src/libs/clangbackendipc/ipcinterface.cpp new file mode 100644 index 0000000000..8645c25f90 --- /dev/null +++ b/src/libs/clangbackendipc/ipcinterface.cpp @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ipcinterface.h" + +namespace ClangBackEnd { + +IpcInterface::~IpcInterface() +{ +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/ipcinterface.h b/src/libs/clangbackendipc/ipcinterface.h new file mode 100644 index 0000000000..68cfa6724e --- /dev/null +++ b/src/libs/clangbackendipc/ipcinterface.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_IPCINTERFACE_H +#define CLANGBACKEND_IPCINTERFACE_H + +#include + +QT_BEGIN_NAMESPACE +class QVariant; +QT_END_NAMESPACE + +#include "clangbackendipc_global.h" + +namespace ClangBackEnd { + +class CMBIPC_EXPORT IpcInterface +{ +public: + virtual ~IpcInterface(); + virtual void dispatch(const QVariant &command) = 0; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_IPCINTERFACE_H diff --git a/src/libs/clangbackendipc/ipcserver.cpp b/src/libs/clangbackendipc/ipcserver.cpp new file mode 100644 index 0000000000..220361c623 --- /dev/null +++ b/src/libs/clangbackendipc/ipcserver.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ipcserver.h" + +namespace ClangBackEnd { + +IpcServer::IpcServer() +{ + +} + +IpcServer::~IpcServer() +{ + +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/ipcserver.h b/src/libs/clangbackendipc/ipcserver.h new file mode 100644 index 0000000000..0512f99234 --- /dev/null +++ b/src/libs/clangbackendipc/ipcserver.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_IPCSERVER_H +#define CLANGBACKEND_IPCSERVER_H + +#include "ipcserverinterface.h" + +namespace ClangBackEnd { + +class IpcServer : public IpcServerInterface +{ +public: + IpcServer(); + ~IpcServer(); +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_IPCSERVER_H diff --git a/src/libs/clangbackendipc/ipcserverinterface.cpp b/src/libs/clangbackendipc/ipcserverinterface.cpp new file mode 100644 index 0000000000..87ef9a5c3a --- /dev/null +++ b/src/libs/clangbackendipc/ipcserverinterface.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ipcserverinterface.h" + +#include +#include + +#include "cmbregistertranslationunitsforcodecompletioncommand.h" +#include "cmbunregistertranslationunitsforcodecompletioncommand.h" +#include "cmbregisterprojectsforcodecompletioncommand.h" +#include "cmbunregisterprojectsforcodecompletioncommand.h" +#include "cmbcompletecodecommand.h" + +namespace ClangBackEnd { + +void IpcServerInterface::dispatch(const QVariant &command) +{ + static const int endCommandType = QMetaType::type("ClangBackEnd::EndCommand"); + static const int registerTranslationUnitsForCodeCompletionCommandType = QMetaType::type("ClangBackEnd::RegisterTranslationUnitForCodeCompletionCommand"); + static const int unregisterTranslationUnitsForCodeCompletionCommandType = QMetaType::type("ClangBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand"); + static const int registerProjectPartsForCodeCompletionCommandType = QMetaType::type("ClangBackEnd::RegisterProjectPartsForCodeCompletionCommand"); + static const int unregisterProjectPartsForCodeCompletionCommandType = QMetaType::type("ClangBackEnd::UnregisterProjectPartsForCodeCompletionCommand"); + static const int completeCodeCommandType = QMetaType::type("ClangBackEnd::CompleteCodeCommand"); + + int type = command.userType(); + + if (type == endCommandType) + end(); + else if (type == registerTranslationUnitsForCodeCompletionCommandType) + registerTranslationUnitsForCodeCompletion(command.value()); + else if (type == unregisterTranslationUnitsForCodeCompletionCommandType) + unregisterTranslationUnitsForCodeCompletion(command.value()); + else if (type == registerProjectPartsForCodeCompletionCommandType) + registerProjectPartsForCodeCompletion(command.value()); + else if (type == unregisterProjectPartsForCodeCompletionCommandType) + unregisterProjectPartsForCodeCompletion(command.value()); + else if (type == completeCodeCommandType) + completeCode(command.value()); + else + qWarning() << "Unknown IpcServerCommand"; +} + +void IpcServerInterface::addClient(IpcClientInterface *client) +{ + clientDispatcher.addClient(client); +} + +void IpcServerInterface::removeClient(IpcClientInterface *client) +{ + clientDispatcher.removeClient(client); +} + +IpcClientInterface *IpcServerInterface::client() +{ + return &clientDispatcher; +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/ipcserverinterface.h b/src/libs/clangbackendipc/ipcserverinterface.h new file mode 100644 index 0000000000..b67cff3c30 --- /dev/null +++ b/src/libs/clangbackendipc/ipcserverinterface.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_IPCSERVERINTERFACE_H +#define CLANGBACKEND_IPCSERVERINTERFACE_H + +#include "ipcinterface.h" + +#include "ipcclientdispatcher.h" + +namespace ClangBackEnd { + +class IpcClientInterface; + +class CMBIPC_EXPORT IpcServerInterface : public IpcInterface +{ +public: + void dispatch(const QVariant &command) override; + + virtual void end() = 0; + virtual void registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) = 0; + virtual void unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) = 0; + virtual void registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) = 0; + virtual void unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) = 0; + virtual void completeCode(const CompleteCodeCommand &command) = 0; + + void addClient(IpcClientInterface *client); + void removeClient(IpcClientInterface *client); + + IpcClientInterface *client(); + +private: + IpcClientDispatcher clientDispatcher; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_IPCSERVERINTERFACE_H diff --git a/src/libs/clangbackendipc/ipcserverproxy.cpp b/src/libs/clangbackendipc/ipcserverproxy.cpp new file mode 100644 index 0000000000..30e002cee2 --- /dev/null +++ b/src/libs/clangbackendipc/ipcserverproxy.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ipcserverproxy.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace ClangBackEnd { + +IpcServerProxy::IpcServerProxy(IpcClientInterface *client, QIODevice *ioDevice) + : writeCommandBlock(ioDevice), + readCommandBlock(ioDevice), + client(client) +{ + QObject::connect(ioDevice, &QIODevice::readyRead, [this] () {IpcServerProxy::readCommands();}); +} + +void IpcServerProxy::readCommands() +{ + for (const QVariant &command : readCommandBlock.readAll()) + client->dispatch(command); +} + +void IpcServerProxy::resetCounter() +{ + writeCommandBlock.resetCounter(); + readCommandBlock.resetCounter(); +} + +void IpcServerProxy::end() +{ + writeCommandBlock.write(QVariant::fromValue(EndCommand())); +} + +void IpcServerProxy::registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) +{ + writeCommandBlock.write(QVariant::fromValue(command)); +} + +void IpcServerProxy::unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) +{ + writeCommandBlock.write(QVariant::fromValue(command)); +} + +void IpcServerProxy::registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) +{ + writeCommandBlock.write(QVariant::fromValue(command)); +} + +void IpcServerProxy::unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) +{ + writeCommandBlock.write(QVariant::fromValue(command)); +} + +void IpcServerProxy::completeCode(const CompleteCodeCommand &command) +{ + writeCommandBlock.write(QVariant::fromValue(command)); +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/ipcserverproxy.h b/src/libs/clangbackendipc/ipcserverproxy.h new file mode 100644 index 0000000000..f10a9595bb --- /dev/null +++ b/src/libs/clangbackendipc/ipcserverproxy.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_IPCSERVERPROXY_H +#define CLANGBACKEND_IPCSERVERPROXY_H + +#include +#include + +#include + +#include "ipcserverinterface.h" +#include "writecommandblock.h" +#include "readcommandblock.h" + +QT_BEGIN_NAMESPACE +class QVariant; +class QProcess; +class QLocalServer; +class QLocalSocket; +QT_END_NAMESPACE + +namespace ClangBackEnd { + +class CMBIPC_EXPORT IpcServerProxy : public IpcServerInterface +{ +public: + IpcServerProxy(IpcClientInterface *client, QIODevice *ioDevice); + IpcServerProxy(const IpcServerProxy&) = delete; + IpcServerProxy &operator=(const IpcServerProxy&) = delete; + + void end() override; + void registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) override; + void unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) override; + void registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) override; + void unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) override; + void completeCode(const CompleteCodeCommand &command) override; + + void readCommands(); + + void resetCounter(); + +private: + ClangBackEnd::WriteCommandBlock writeCommandBlock; + ClangBackEnd::ReadCommandBlock readCommandBlock; + IpcClientInterface *client; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_IPCSERVERPROXY_H diff --git a/src/libs/clangbackendipc/projectpartcontainer.cpp b/src/libs/clangbackendipc/projectpartcontainer.cpp new file mode 100644 index 0000000000..cd3f7a98a3 --- /dev/null +++ b/src/libs/clangbackendipc/projectpartcontainer.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "projectpartcontainer.h" + +#include + +#include + +#include + +namespace ClangBackEnd { + +ProjectPartContainer::ProjectPartContainer(const Utf8String &projectPathId, + const Utf8StringVector &arguments) + : projectPartId_(projectPathId), + arguments_(arguments) +{ +} + +const Utf8String &ProjectPartContainer::projectPartId() const +{ + return projectPartId_; +} + +const Utf8StringVector &ProjectPartContainer::arguments() const +{ + return arguments_; +} + + +QDataStream &operator<<(QDataStream &out, const ProjectPartContainer &container) +{ + out << container.projectPartId_; + out << container.arguments_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, ProjectPartContainer &container) +{ + in >> container.projectPartId_; + in >> container.arguments_; + + return in; +} + +bool operator==(const ProjectPartContainer &first, const ProjectPartContainer &second) +{ + return first.projectPartId_ == second.projectPartId_; +} + +bool operator<(const ProjectPartContainer &first, const ProjectPartContainer &second) +{ + return first.projectPartId_ < second.projectPartId_; +} + +QDebug operator<<(QDebug debug, const ProjectPartContainer &container) +{ + debug.nospace() << "ProjectPartContainer(" + << container.projectPartId() + << "," + << container.arguments() + << ")"; + + return debug; +} + +void PrintTo(const ProjectPartContainer &container, ::std::ostream* os) +{ + *os << "ProjectPartContainer(" + << container.projectPartId().constData() + << "," + << container.arguments().constData() + << ")"; +} + + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/projectpartcontainer.h b/src/libs/clangbackendipc/projectpartcontainer.h new file mode 100644 index 0000000000..4fdf26451e --- /dev/null +++ b/src/libs/clangbackendipc/projectpartcontainer.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_PROJECTCONTAINER_H +#define CLANGBACKEND_PROJECTCONTAINER_H + +#include + +#include + +#include + +namespace ClangBackEnd { + +class CMBIPC_EXPORT ProjectPartContainer +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const ProjectPartContainer &container); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, ProjectPartContainer &container); + friend CMBIPC_EXPORT bool operator==(const ProjectPartContainer &first, const ProjectPartContainer &second); + friend CMBIPC_EXPORT bool operator<(const ProjectPartContainer &first, const ProjectPartContainer &second); +public: + ProjectPartContainer() = default; + ProjectPartContainer(const Utf8String &projectPartId, + const Utf8StringVector &arguments = Utf8StringVector()); + + const Utf8String &projectPartId() const; + const Utf8StringVector &arguments() const; + +private: + Utf8String projectPartId_; + Utf8StringVector arguments_; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const ProjectPartContainer &container); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, ProjectPartContainer &container); +CMBIPC_EXPORT bool operator==(const ProjectPartContainer &first, const ProjectPartContainer &second); +CMBIPC_EXPORT bool operator<(const ProjectPartContainer &first, const ProjectPartContainer &second); + +QDebug operator<<(QDebug debug, const ProjectPartContainer &container); +void PrintTo(const ProjectPartContainer &container, ::std::ostream* os); + +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::ProjectPartContainer) + +#endif // CLANGBACKEND_PROJECTCONTAINER_H diff --git a/src/libs/clangbackendipc/projectpartsdonotexistcommand.cpp b/src/libs/clangbackendipc/projectpartsdonotexistcommand.cpp new file mode 100644 index 0000000000..f0f78bf620 --- /dev/null +++ b/src/libs/clangbackendipc/projectpartsdonotexistcommand.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "projectpartsdonotexistcommand.h" + +#include + +#include + +#include + +namespace ClangBackEnd { + +ProjectPartsDoNotExistCommand::ProjectPartsDoNotExistCommand(const Utf8StringVector &projectPartIds) + : projectPartIds_(projectPartIds) +{ +} + + +const Utf8StringVector &ProjectPartsDoNotExistCommand::projectPartIds() const +{ + return projectPartIds_; +} + +QDataStream &operator<<(QDataStream &out, const ProjectPartsDoNotExistCommand &command) +{ + out << command.projectPartIds_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, ProjectPartsDoNotExistCommand &command) +{ + in >> command.projectPartIds_; + + return in; +} + +bool operator==(const ProjectPartsDoNotExistCommand &first, const ProjectPartsDoNotExistCommand &second) +{ + return first.projectPartIds_ == second.projectPartIds_; +} + +bool operator<(const ProjectPartsDoNotExistCommand &first, const ProjectPartsDoNotExistCommand &second) +{ + return first.projectPartIds_ < second.projectPartIds_; +} + +QDebug operator<<(QDebug debug, const ProjectPartsDoNotExistCommand &command) +{ + debug.nospace() << "ProjectPartDoesNotExistCommand("; + + debug.nospace() << command.projectPartIds_; + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const ProjectPartsDoNotExistCommand &command, ::std::ostream* os) +{ + QString output; + QDebug debug(&output); + + debug << command; + + *os << output.toUtf8().constData(); +} + + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/projectpartsdonotexistcommand.h b/src/libs/clangbackendipc/projectpartsdonotexistcommand.h new file mode 100644 index 0000000000..c633f9d6e9 --- /dev/null +++ b/src/libs/clangbackendipc/projectpartsdonotexistcommand.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_PROJECTPARTSDONOTEXISTCOMMAND_H +#define CLANGBACKEND_PROJECTPARTSDONOTEXISTCOMMAND_H + +#include + +#include + +#include "clangbackendipc_global.h" + +namespace ClangBackEnd { + +class CMBIPC_EXPORT ProjectPartsDoNotExistCommand +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const ProjectPartsDoNotExistCommand &command); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, ProjectPartsDoNotExistCommand &command); + friend CMBIPC_EXPORT bool operator==(const ProjectPartsDoNotExistCommand &first, const ProjectPartsDoNotExistCommand &second); + friend CMBIPC_EXPORT bool operator<(const ProjectPartsDoNotExistCommand &first, const ProjectPartsDoNotExistCommand &second); + friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const ProjectPartsDoNotExistCommand &command); + friend void PrintTo(const ProjectPartsDoNotExistCommand &command, ::std::ostream* os); +public: + ProjectPartsDoNotExistCommand() = default; + ProjectPartsDoNotExistCommand(const Utf8StringVector &projectPartIds); + + const Utf8StringVector &projectPartIds() const; + +private: + Utf8StringVector projectPartIds_; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const ProjectPartsDoNotExistCommand &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, ProjectPartsDoNotExistCommand &command); +CMBIPC_EXPORT bool operator==(const ProjectPartsDoNotExistCommand &first, const ProjectPartsDoNotExistCommand &second); +CMBIPC_EXPORT bool operator<(const ProjectPartsDoNotExistCommand &first, const ProjectPartsDoNotExistCommand &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const ProjectPartsDoNotExistCommand &command); +void PrintTo(const ProjectPartsDoNotExistCommand &command, ::std::ostream* os); + +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::ProjectPartsDoNotExistCommand) + +#endif // CLANGBACKEND_PROJECTPARTSDONOTEXISTCOMMAND_H diff --git a/src/libs/clangbackendipc/readcommandblock.cpp b/src/libs/clangbackendipc/readcommandblock.cpp new file mode 100644 index 0000000000..318b318e41 --- /dev/null +++ b/src/libs/clangbackendipc/readcommandblock.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "readcommandblock.h" + +#include +#include +#include +#include + +namespace ClangBackEnd { + +ReadCommandBlock::ReadCommandBlock(QIODevice *ioDevice) + : ioDevice(ioDevice), + commandCounter(0), + blockSize(0) +{ +} + +void ReadCommandBlock::checkIfCommandIsLost(QDataStream &in) +{ + qint64 currentCommandCounter; + + in >> currentCommandCounter; + +#ifndef DONT_CHECK_COMMAND_COUNTER + bool commandLost = !((currentCommandCounter == 0 && commandCounter == 0) || (commandCounter + 1 == currentCommandCounter)); + if (commandLost) + qWarning() << "client command lost: " << commandCounter << currentCommandCounter; +#endif + + commandCounter = currentCommandCounter; +} + +QVariant ReadCommandBlock::read() +{ + QDataStream in(ioDevice); + + QVariant command; + + if (isTheWholeCommandReadable(in)) { + checkIfCommandIsLost(in); + in >> command; + } + + return command; +} + +QVector ReadCommandBlock::readAll() +{ + QVector commands; + + while (true) { + const QVariant command = read(); + if (command.isValid()) + commands.append(command); + else + return commands; + } + + Q_UNREACHABLE(); +} + +void ReadCommandBlock::resetCounter() +{ + commandCounter = 0; +} + +bool ReadCommandBlock::isTheWholeCommandReadable(QDataStream &in) +{ + if (ioDevice->bytesAvailable() == 0) + return false; + + if (blockSize == 0) + in >> blockSize; + + if (ioDevice->bytesAvailable() < blockSize) + return false; + + blockSize = 0; + + return true; +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/readcommandblock.h b/src/libs/clangbackendipc/readcommandblock.h new file mode 100644 index 0000000000..04af1a660d --- /dev/null +++ b/src/libs/clangbackendipc/readcommandblock.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_READCOMMANDBLOCK_H +#define CLANGBACKEND_READCOMMANDBLOCK_H + +#include + +QT_BEGIN_NAMESPACE +class QVariant; +class QDataStream; +class QIODevice; +QT_END_NAMESPACE + +namespace ClangBackEnd { + +class ReadCommandBlock +{ +public: + ReadCommandBlock(QIODevice *ioDevice = nullptr); + + QVariant read(); + QVector readAll(); + + void resetCounter(); + +private: + bool isTheWholeCommandReadable(QDataStream &in); + void checkIfCommandIsLost(QDataStream &in); + +private: + QIODevice *ioDevice; + qint64 commandCounter; + qint32 blockSize; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_READCOMMANDBLOCK_H diff --git a/src/libs/clangbackendipc/translationunitdoesnotexistcommand.cpp b/src/libs/clangbackendipc/translationunitdoesnotexistcommand.cpp new file mode 100644 index 0000000000..5c512dd19e --- /dev/null +++ b/src/libs/clangbackendipc/translationunitdoesnotexistcommand.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "translationunitdoesnotexistcommand.h" + +#include + +#include + +#include + +namespace ClangBackEnd { + +TranslationUnitDoesNotExistCommand::TranslationUnitDoesNotExistCommand(const FileContainer &fileContainer) + : fileContainer_(fileContainer) +{ +} + +TranslationUnitDoesNotExistCommand::TranslationUnitDoesNotExistCommand(const Utf8String &filePath, const Utf8String &projectPartId) + : fileContainer_(filePath, projectPartId) +{ +} + +const FileContainer &TranslationUnitDoesNotExistCommand::fileContainer() const +{ + return fileContainer_; +} + +const Utf8String &TranslationUnitDoesNotExistCommand::filePath() const +{ + return fileContainer_.filePath(); +} + +const Utf8String &TranslationUnitDoesNotExistCommand::projectPartId() const +{ + return fileContainer_.projectPartId(); +} + +QDataStream &operator<<(QDataStream &out, const TranslationUnitDoesNotExistCommand &command) +{ + out << command.fileContainer_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, TranslationUnitDoesNotExistCommand &command) +{ + in >> command.fileContainer_; + + return in; +} + +bool operator==(const TranslationUnitDoesNotExistCommand &first, const TranslationUnitDoesNotExistCommand &second) +{ + return first.fileContainer_ == second.fileContainer_; +} + +bool operator<(const TranslationUnitDoesNotExistCommand &first, const TranslationUnitDoesNotExistCommand &second) +{ + return first.fileContainer_ < second.fileContainer_; +} + +QDebug operator<<(QDebug debug, const TranslationUnitDoesNotExistCommand &command) +{ + debug.nospace() << "TranslationUnitDoesNotExistCommand("; + + debug.nospace() << command.fileContainer_; + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const TranslationUnitDoesNotExistCommand &command, ::std::ostream* os) +{ + QString output; + QDebug debug(&output); + + debug << command; + + *os << output.toUtf8().constData(); +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/translationunitdoesnotexistcommand.h b/src/libs/clangbackendipc/translationunitdoesnotexistcommand.h new file mode 100644 index 0000000000..e6124d56ad --- /dev/null +++ b/src/libs/clangbackendipc/translationunitdoesnotexistcommand.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_TRANSLATIONUNITDOESNOTEXISTSCOMMAND_H +#define CLANGBACKEND_TRANSLATIONUNITDOESNOTEXISTSCOMMAND_H + +#include + +#include "filecontainer.h" + +namespace ClangBackEnd { + +class CMBIPC_EXPORT TranslationUnitDoesNotExistCommand +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const TranslationUnitDoesNotExistCommand &command); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, TranslationUnitDoesNotExistCommand &command); + friend CMBIPC_EXPORT bool operator==(const TranslationUnitDoesNotExistCommand &first, const TranslationUnitDoesNotExistCommand &second); + friend CMBIPC_EXPORT bool operator<(const TranslationUnitDoesNotExistCommand &first, const TranslationUnitDoesNotExistCommand &second); + friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const TranslationUnitDoesNotExistCommand &command); + friend void PrintTo(const TranslationUnitDoesNotExistCommand &command, ::std::ostream* os); +public: + TranslationUnitDoesNotExistCommand() = default; + TranslationUnitDoesNotExistCommand(const FileContainer &fileContainer); + TranslationUnitDoesNotExistCommand(const Utf8String &filePath, const Utf8String &projectPartId); + + const FileContainer &fileContainer() const; + const Utf8String &filePath() const; + const Utf8String &projectPartId() const; + +private: + FileContainer fileContainer_; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const TranslationUnitDoesNotExistCommand &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, TranslationUnitDoesNotExistCommand &command); +CMBIPC_EXPORT bool operator==(const TranslationUnitDoesNotExistCommand &first, const TranslationUnitDoesNotExistCommand &second); +CMBIPC_EXPORT bool operator<(const TranslationUnitDoesNotExistCommand &first, const TranslationUnitDoesNotExistCommand &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const TranslationUnitDoesNotExistCommand &command); +void PrintTo(const TranslationUnitDoesNotExistCommand &command, ::std::ostream* os); + +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::TranslationUnitDoesNotExistCommand) + +#endif // CLANGBACKEND_TRANSLATIONUNITDOESNOTEXISTSCOMMAND_H diff --git a/src/libs/clangbackendipc/writecommandblock.cpp b/src/libs/clangbackendipc/writecommandblock.cpp new file mode 100644 index 0000000000..3d0d2fca07 --- /dev/null +++ b/src/libs/clangbackendipc/writecommandblock.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "writecommandblock.h" + +#include +#include +#include +#include + +namespace ClangBackEnd { + +WriteCommandBlock::WriteCommandBlock(QIODevice *ioDevice) + : commandCounter(0), + ioDevice(ioDevice) +{ +} + +void WriteCommandBlock::write(const QVariant &command) +{ + QByteArray block; + QDataStream out(&block, QIODevice::WriteOnly); + + const qint32 dummyBockSize = 0; + out << dummyBockSize; + + out << commandCounter; + + out << command; + + out.device()->seek(0); + out << qint32(block.size() - sizeof(qint32)); + + ++commandCounter; + + ioDevice->write(block); +} + +qint64 WriteCommandBlock::counter() const +{ + return commandCounter; +} + +void WriteCommandBlock::resetCounter() +{ + commandCounter = 0; +} + + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/writecommandblock.h b/src/libs/clangbackendipc/writecommandblock.h new file mode 100644 index 0000000000..9a35bc0df1 --- /dev/null +++ b/src/libs/clangbackendipc/writecommandblock.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_WRITECOMMANDBLOCK_H +#define CLANGBACKEND_WRITECOMMANDBLOCK_H + +#include + +QT_BEGIN_NAMESPACE +class QVariant; +class QDataStream; +class QIODevice; +QT_END_NAMESPACE + +namespace ClangBackEnd { + +class WriteCommandBlock +{ +public: + WriteCommandBlock(QIODevice *ioDevice = nullptr); + + void write(const QVariant &command); + + qint64 counter() const; + + void resetCounter(); + +private: + qint64 commandCounter; + QIODevice *ioDevice; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_WRITECOMMANDBLOCK_H diff --git a/src/libs/codemodelbackendipc/cmbalivecommand.cpp b/src/libs/codemodelbackendipc/cmbalivecommand.cpp deleted file mode 100644 index 636c801c9c..0000000000 --- a/src/libs/codemodelbackendipc/cmbalivecommand.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "cmbalivecommand.h" - -#include - -#include - -namespace CodeModelBackEnd { - -QDataStream &operator<<(QDataStream &out, const AliveCommand &/*command*/) -{ - return out; -} - -QDataStream &operator>>(QDataStream &in, AliveCommand &/*command*/) -{ - return in; -} - -bool operator==(const AliveCommand &/*first*/, const AliveCommand &/*second*/) -{ - return true; -} - -bool operator<(const AliveCommand &/*first*/, const AliveCommand &/*second*/) -{ - return true; -} - -QDebug operator<<(QDebug debug, const AliveCommand &/*command*/) -{ - return debug.nospace() << "AliveCommand()"; -} - -} diff --git a/src/libs/codemodelbackendipc/cmbalivecommand.h b/src/libs/codemodelbackendipc/cmbalivecommand.h deleted file mode 100644 index 1bfae90b91..0000000000 --- a/src/libs/codemodelbackendipc/cmbalivecommand.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CMBALIVECOMMAND_H -#define CMBALIVECOMMAND_H - -#include "codemodelbackendipc_global.h" - -#include - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT AliveCommand -{ -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const AliveCommand &command); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, AliveCommand &command); -CMBIPC_EXPORT bool operator==(const AliveCommand &first, const AliveCommand &second); -CMBIPC_EXPORT bool operator<(const AliveCommand &first, const AliveCommand &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const AliveCommand &command); - -} - -Q_DECLARE_METATYPE(CodeModelBackEnd::AliveCommand) - -#endif // CMBALIVECOMMAND_H diff --git a/src/libs/codemodelbackendipc/cmbcodecompletedcommand.cpp b/src/libs/codemodelbackendipc/cmbcodecompletedcommand.cpp deleted file mode 100644 index 34b53b6aaa..0000000000 --- a/src/libs/codemodelbackendipc/cmbcodecompletedcommand.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "cmbcodecompletedcommand.h" - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -CodeCompletedCommand::CodeCompletedCommand(const QVector &codeCompletions, quint64 ticketNumber) - : codeCompletions_(codeCompletions), - ticketNumber_(ticketNumber) -{ -} - -const QVector &CodeCompletedCommand::codeCompletions() const -{ - return codeCompletions_; -} - -quint64 CodeCompletedCommand::ticketNumber() const -{ - return ticketNumber_; -} - -QDataStream &operator<<(QDataStream &out, const CodeCompletedCommand &command) -{ - out << command.codeCompletions_; - out << command.ticketNumber_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, CodeCompletedCommand &command) -{ - in >> command.codeCompletions_; - in >> command.ticketNumber_; - - return in; -} - -bool operator==(const CodeCompletedCommand &first, const CodeCompletedCommand &second) -{ - return first.ticketNumber_ == second.ticketNumber_ - && first.codeCompletions_ == second.codeCompletions_; -} - -bool operator<(const CodeCompletedCommand &first, const CodeCompletedCommand &second) -{ - return first.ticketNumber_ < second.ticketNumber_; -} - -QDebug operator<<(QDebug debug, const CodeCompletedCommand &command) -{ - debug.nospace() << "CodeCompletedCommand("; - - debug.nospace() << command.codeCompletions_ << ", " << command.ticketNumber_; - - debug.nospace() << ")"; - - return debug; -} - -void PrintTo(const CodeCompletedCommand &command, ::std::ostream* os) -{ - QString output; - QDebug debug(&output); - - debug << command; - - *os << output.toUtf8().constData(); -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/cmbcodecompletedcommand.h b/src/libs/codemodelbackendipc/cmbcodecompletedcommand.h deleted file mode 100644 index 6e6a70875b..0000000000 --- a/src/libs/codemodelbackendipc/cmbcodecompletedcommand.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_CODECOMPLETEDCOMMAND_H -#define CODEMODELBACKEND_CODECOMPLETEDCOMMAND_H - -#include -#include - -#include "codecompletion.h" - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT CodeCompletedCommand -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletedCommand &command); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CodeCompletedCommand &command); - friend CMBIPC_EXPORT bool operator==(const CodeCompletedCommand &first, const CodeCompletedCommand &second); - friend CMBIPC_EXPORT bool operator<(const CodeCompletedCommand &first, const CodeCompletedCommand &second); - friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CodeCompletedCommand &command); - friend void PrintTo(const CodeCompletedCommand &command, ::std::ostream* os); -public: - CodeCompletedCommand() = default; - CodeCompletedCommand(const QVector &codeCompletions, quint64 ticketNumber); - - const QVector &codeCompletions() const; - - quint64 ticketNumber() const; - -private: - QVector codeCompletions_; - quint64 ticketNumber_ = 0; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletedCommand &command); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CodeCompletedCommand &command); -CMBIPC_EXPORT bool operator==(const CodeCompletedCommand &first, const CodeCompletedCommand &second); -CMBIPC_EXPORT bool operator<(const CodeCompletedCommand &first, const CodeCompletedCommand &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CodeCompletedCommand &command); -void PrintTo(const CodeCompletedCommand &command, ::std::ostream* os); - -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::CodeCompletedCommand) - -#endif // CODEMODELBACKEND_CODECOMPLETEDCOMMAND_H diff --git a/src/libs/codemodelbackendipc/cmbcommands.cpp b/src/libs/codemodelbackendipc/cmbcommands.cpp deleted file mode 100644 index 7a817f09df..0000000000 --- a/src/libs/codemodelbackendipc/cmbcommands.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "cmbcommands.h" - -#include "cmbalivecommand.h" -#include "cmbendcommand.h" -#include "cmbechocommand.h" -#include "cmbregistertranslationunitsforcodecompletioncommand.h" -#include "cmbunregistertranslationunitsforcodecompletioncommand.h" -#include "cmbregisterprojectsforcodecompletioncommand.h" -#include "cmbunregisterprojectsforcodecompletioncommand.h" -#include "cmbcompletecodecommand.h" -#include "cmbcodecompletedcommand.h" -#include "projectpartsdonotexistcommand.h" -#include "translationunitdoesnotexistcommand.h" - -#include - -namespace CodeModelBackEnd { - -void Commands::registerCommands() -{ - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); - - qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); - QMetaType::registerComparators(); -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/cmbcommands.h b/src/libs/codemodelbackendipc/cmbcommands.h deleted file mode 100644 index 08119d9fdf..0000000000 --- a/src/libs/codemodelbackendipc/cmbcommands.h +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_COMMANDS_H -#define CODEMODELBACKEND_COMMANDS_H - -#include - -namespace CodeModelBackEnd { - -namespace Commands -{ -CMBIPC_EXPORT void registerCommands(); -} - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_COMMANDS_H diff --git a/src/libs/codemodelbackendipc/cmbcompletecodecommand.cpp b/src/libs/codemodelbackendipc/cmbcompletecodecommand.cpp deleted file mode 100644 index d41121be5e..0000000000 --- a/src/libs/codemodelbackendipc/cmbcompletecodecommand.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "cmbcompletecodecommand.h" - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -quint64 CompleteCodeCommand::ticketCounter = 0; - -CompleteCodeCommand::CompleteCodeCommand(const Utf8String &filePath, quint32 line, quint32 column, const Utf8String &projectPartId) - : filePath_(filePath), - projectPartId_(projectPartId), - ticketNumber_(++ticketCounter), - line_(line), - column_(column) -{ -} - -const Utf8String &CompleteCodeCommand::filePath() const -{ - return filePath_; -} - -const Utf8String &CompleteCodeCommand::projectPartId() const -{ - return projectPartId_; -} - -quint32 CompleteCodeCommand::line() const -{ - return line_; -} - -quint32 CompleteCodeCommand::column() const -{ - return column_; -} - -quint64 CompleteCodeCommand::ticketNumber() const -{ - return ticketNumber_; -} - -QDataStream &operator<<(QDataStream &out, const CompleteCodeCommand &command) -{ - out << command.filePath_; - out << command.projectPartId_; - out << command.ticketNumber_; - out << command.line_; - out << command.column_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, CompleteCodeCommand &command) -{ - in >> command.filePath_; - in >> command.projectPartId_; - in >> command.ticketNumber_; - in >> command.line_; - in >> command.column_; - - return in; -} - -bool operator==(const CompleteCodeCommand &first, const CompleteCodeCommand &second) -{ - return first.ticketNumber_ == second.ticketNumber_ - && first.filePath_ == second.filePath_ - && first.projectPartId_ == second.projectPartId_ - && first.line_ == second.line_ - && first.column_ == second.column_; -} - -bool operator<(const CompleteCodeCommand &first, const CompleteCodeCommand &second) -{ - return first.ticketNumber_ < second.ticketNumber_ - && first.filePath_ < second.filePath_ - && first.projectPartId_ < second.projectPartId_ - && first.line_ < second.line_ - && first.column_ < second.column_; -} - -QDebug operator<<(QDebug debug, const CompleteCodeCommand &command) -{ - debug.nospace() << "CompleteCodeCommand("; - - debug.nospace() << command.filePath_ << ", "; - debug.nospace() << command.line_<< ", "; - debug.nospace() << command.column_<< ", "; - debug.nospace() << command.projectPartId_ << ", "; - debug.nospace() << command.ticketNumber_; - - debug.nospace() << ")"; - - return debug; -} - -void PrintTo(const CompleteCodeCommand &command, ::std::ostream* os) -{ - *os << "CompleteCodeCommand("; - - *os << command.filePath_.constData() << ", "; - *os << command.line_ << ", "; - *os << command.column_ << ", "; - *os << command.projectPartId_.constData() << ", "; - *os << command.ticketNumber_; - - *os << ")"; -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/cmbcompletecodecommand.h b/src/libs/codemodelbackendipc/cmbcompletecodecommand.h deleted file mode 100644 index c24f9365cc..0000000000 --- a/src/libs/codemodelbackendipc/cmbcompletecodecommand.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_COMPLETECODECOMMAND_H -#define CODEMODELBACKEND_COMPLETECODECOMMAND_H - -#include "codemodelbackendipc_global.h" - -#include -#include - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT CompleteCodeCommand -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CompleteCodeCommand &command); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CompleteCodeCommand &command); - friend CMBIPC_EXPORT bool operator==(const CompleteCodeCommand &first, const CompleteCodeCommand &second); - friend CMBIPC_EXPORT bool operator<(const CompleteCodeCommand &first, const CompleteCodeCommand &second); - friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CompleteCodeCommand &command); - friend void PrintTo(const CompleteCodeCommand &command, ::std::ostream* os); - -public: - CompleteCodeCommand() = default; - CompleteCodeCommand(const Utf8String &filePath, - quint32 line, - quint32 column, - const Utf8String &projectPartId); - - const Utf8String &filePath() const; - const Utf8String &projectPartId() const; - - quint32 line() const; - quint32 column() const; - - quint64 ticketNumber() const; - -private: - Utf8String filePath_; - Utf8String projectPartId_; - static quint64 ticketCounter; - quint64 ticketNumber_; - quint32 line_ = 0; - quint32 column_ = 0; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CompleteCodeCommand &command); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CompleteCodeCommand &command); -CMBIPC_EXPORT bool operator==(const CompleteCodeCommand &first, const CompleteCodeCommand &second); -CMBIPC_EXPORT bool operator<(const CompleteCodeCommand &first, const CompleteCodeCommand &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CompleteCodeCommand &command); -void PrintTo(const CompleteCodeCommand &command, ::std::ostream* os); - -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::CompleteCodeCommand) - -#endif // CODEMODELBACKEND_COMPLETECODECOMMAND_H diff --git a/src/libs/codemodelbackendipc/cmbechocommand.cpp b/src/libs/codemodelbackendipc/cmbechocommand.cpp deleted file mode 100644 index 5db788893c..0000000000 --- a/src/libs/codemodelbackendipc/cmbechocommand.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "cmbechocommand.h" - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -EchoCommand::EchoCommand(const QVariant &command) - : command_(command) -{ - -} - -const QVariant &EchoCommand::command() const -{ - return command_; -} - -QDataStream &operator<<(QDataStream &out, const EchoCommand &command) -{ - out << command.command(); - - return out; -} - -QDataStream &operator>>(QDataStream &in, EchoCommand &command) -{ - in >> command.command_; - - return in; -} - -bool operator==(const EchoCommand &first, const EchoCommand &second) -{ - return first.command_ == second.command_; -} - -bool operator<(const EchoCommand &first, const EchoCommand &second) -{ - return first.command_ < second.command_; -} - -QDebug operator<<(QDebug debug, const EchoCommand &command) -{ - return debug.nospace() << "EchoCommand(" << command.command() << ")"; -} - -void PrintTo(const EchoCommand &command, ::std::ostream* os) -{ - QString output; - QDebug debug(&output); - - debug << command; - - *os << output.toUtf8().constData(); -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/cmbechocommand.h b/src/libs/codemodelbackendipc/cmbechocommand.h deleted file mode 100644 index 3f2c59b41b..0000000000 --- a/src/libs/codemodelbackendipc/cmbechocommand.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_ECHOCOMMAND_H -#define CODEMODELBACKEND_ECHOCOMMAND_H - -#include "codemodelbackendipc_global.h" - -#include -#include - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT EchoCommand -{ - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, EchoCommand &command); - friend CMBIPC_EXPORT bool operator==(const EchoCommand &first, const EchoCommand &second); - friend CMBIPC_EXPORT bool operator<(const EchoCommand &first, const EchoCommand &second); -public: - EchoCommand() = default; - explicit EchoCommand(const QVariant &command); - - const QVariant &command() const; - -private: - QVariant command_; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const EchoCommand &command); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, EchoCommand &command); -CMBIPC_EXPORT bool operator==(const EchoCommand &first, const EchoCommand &second); -CMBIPC_EXPORT bool operator<(const EchoCommand &first, const EchoCommand &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const EchoCommand &command); -void PrintTo(const EchoCommand &command, ::std::ostream* os); - -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::EchoCommand) - -#endif // CODEMODELBACKEND_ECHOCOMMAND_H diff --git a/src/libs/codemodelbackendipc/cmbendcommand.cpp b/src/libs/codemodelbackendipc/cmbendcommand.cpp deleted file mode 100644 index 43df8e20d0..0000000000 --- a/src/libs/codemodelbackendipc/cmbendcommand.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "cmbendcommand.h" - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -QDataStream &operator<<(QDataStream &out, const EndCommand &/*command*/) -{ - return out; -} - -QDataStream &operator>>(QDataStream &in, EndCommand &/*command*/) -{ - return in; -} - -bool operator==(const EndCommand &/*first*/, const EndCommand &/*second*/) -{ - return true; -} - -bool operator<(const EndCommand &/*first*/, const EndCommand &/*second*/) -{ - return true; -} - -QDebug operator<<(QDebug debug, const EndCommand &/*command*/) -{ - return debug.nospace() << "EndCommand()"; -} - -void PrintTo(const EndCommand &/*command*/, ::std::ostream* os) -{ - *os << "EndCommand()"; -} -} - diff --git a/src/libs/codemodelbackendipc/cmbendcommand.h b/src/libs/codemodelbackendipc/cmbendcommand.h deleted file mode 100644 index f5a4e53376..0000000000 --- a/src/libs/codemodelbackendipc/cmbendcommand.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CMBENDCOMMAND_H -#define CMBENDCOMMAND_H - -#include "codemodelbackendipc_global.h" - -#include - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT EndCommand -{ -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const EndCommand &command); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, EndCommand &command); -CMBIPC_EXPORT bool operator==(const EndCommand &first, const EndCommand &second); -CMBIPC_EXPORT bool operator<(const EndCommand &first, const EndCommand &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const EndCommand &command); -void PrintTo(const EndCommand &command, ::std::ostream* os); -} - -Q_DECLARE_METATYPE(CodeModelBackEnd::EndCommand) - -#endif // CMBENDCOMMAND_H diff --git a/src/libs/codemodelbackendipc/cmbregisterprojectsforcodecompletioncommand.cpp b/src/libs/codemodelbackendipc/cmbregisterprojectsforcodecompletioncommand.cpp deleted file mode 100644 index e02997748f..0000000000 --- a/src/libs/codemodelbackendipc/cmbregisterprojectsforcodecompletioncommand.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "cmbregisterprojectsforcodecompletioncommand.h" - -#include - -#include - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -RegisterProjectPartsForCodeCompletionCommand::RegisterProjectPartsForCodeCompletionCommand(const QVector &projectContainers) - :projectContainers_(projectContainers) -{ -} - -const QVector &RegisterProjectPartsForCodeCompletionCommand::projectContainers() const -{ - return projectContainers_; -} - -QDataStream &operator<<(QDataStream &out, const RegisterProjectPartsForCodeCompletionCommand &command) -{ - out << command.projectContainers_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, RegisterProjectPartsForCodeCompletionCommand &command) -{ - in >> command.projectContainers_; - - return in; -} - -bool operator==(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second) -{ - return first.projectContainers_ == second.projectContainers_; -} - -bool operator<(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second) -{ - return compareContainer(first.projectContainers_, second.projectContainers_); -} - -QDebug operator<<(QDebug debug, const RegisterProjectPartsForCodeCompletionCommand &command) -{ - debug.nospace() << "RegisterProjectPartsForCodeCompletion("; - - for (const ProjectPartContainer &projectContainer : command.projectContainers()) - debug.nospace() << projectContainer<< ", "; - - debug.nospace() << ")"; - - return debug; -} - -void PrintTo(const RegisterProjectPartsForCodeCompletionCommand &command, ::std::ostream* os) -{ - *os << "RegisterProjectPartsForCodeCompletion("; - - for (const ProjectPartContainer &projectContainer : command.projectContainers()) - PrintTo(projectContainer, os); - - *os << ")"; -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/cmbregisterprojectsforcodecompletioncommand.h b/src/libs/codemodelbackendipc/cmbregisterprojectsforcodecompletioncommand.h deleted file mode 100644 index 6533ae190b..0000000000 --- a/src/libs/codemodelbackendipc/cmbregisterprojectsforcodecompletioncommand.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_REGISTERPROJECTSFORCODECOMPLETIONCOMAND_H -#define CODEMODELBACKEND_REGISTERPROJECTSFORCODECOMPLETIONCOMAND_H - -#include -#include - -#include "projectpartcontainer.h" - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT RegisterProjectPartsForCodeCompletionCommand -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const RegisterProjectPartsForCodeCompletionCommand &command); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, RegisterProjectPartsForCodeCompletionCommand &command); - friend CMBIPC_EXPORT bool operator==(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second); - friend CMBIPC_EXPORT bool operator<(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second); - friend void PrintTo(const RegisterProjectPartsForCodeCompletionCommand &command, ::std::ostream* os); -public: - RegisterProjectPartsForCodeCompletionCommand() = default; - RegisterProjectPartsForCodeCompletionCommand(const QVector &projectContainers); - - const QVector &projectContainers() const; - -private: - QVector projectContainers_; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const RegisterProjectPartsForCodeCompletionCommand &command); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, RegisterProjectPartsForCodeCompletionCommand &command); -CMBIPC_EXPORT bool operator==(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second); -CMBIPC_EXPORT bool operator<(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const RegisterProjectPartsForCodeCompletionCommand &command); -void PrintTo(const RegisterProjectPartsForCodeCompletionCommand &command, ::std::ostream* os); -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::RegisterProjectPartsForCodeCompletionCommand) - -#endif // CODEMODELBACKEND_REGISTERPROJECTSFORCODECOMPLETIONCOMAND_H diff --git a/src/libs/codemodelbackendipc/cmbregistertranslationunitsforcodecompletioncommand.cpp b/src/libs/codemodelbackendipc/cmbregistertranslationunitsforcodecompletioncommand.cpp deleted file mode 100644 index a21b53f5fa..0000000000 --- a/src/libs/codemodelbackendipc/cmbregistertranslationunitsforcodecompletioncommand.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "cmbregistertranslationunitsforcodecompletioncommand.h" - -#include - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -RegisterTranslationUnitForCodeCompletionCommand::RegisterTranslationUnitForCodeCompletionCommand(const QVector &fileContainers) - : fileContainers_(fileContainers) -{ -} - -const QVector &RegisterTranslationUnitForCodeCompletionCommand::fileContainers() const -{ - return fileContainers_; -} - -QDataStream &operator<<(QDataStream &out, const RegisterTranslationUnitForCodeCompletionCommand &command) -{ - out << command.fileContainers_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, RegisterTranslationUnitForCodeCompletionCommand &command) -{ - in >> command.fileContainers_; - - return in; -} - -bool operator==(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second) -{ - return first.fileContainers_ == second.fileContainers_; -} - -bool operator<(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second) -{ - return compareContainer(first.fileContainers_, second.fileContainers_); -} - -QDebug operator<<(QDebug debug, const RegisterTranslationUnitForCodeCompletionCommand &command) -{ - debug.nospace() << "RegisterTranslationUnitForCodeCompletionCommand("; - - for (const FileContainer &fileContainer : command.fileContainers()) - debug.nospace() << fileContainer<< ", "; - - debug.nospace() << ")"; - - return debug; -} - -void PrintTo(const RegisterTranslationUnitForCodeCompletionCommand &command, ::std::ostream* os) -{ - *os << "RegisterTranslationUnitForCodeCompletionCommand("; - - for (const FileContainer &fileContainer : command.fileContainers()) - PrintTo(fileContainer, os); - - *os << ")"; -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/cmbregistertranslationunitsforcodecompletioncommand.h b/src/libs/codemodelbackendipc/cmbregistertranslationunitsforcodecompletioncommand.h deleted file mode 100644 index 588ad421d7..0000000000 --- a/src/libs/codemodelbackendipc/cmbregistertranslationunitsforcodecompletioncommand.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_REGISTERFILEFORCODECOMPLETION_H -#define CODEMODELBACKEND_REGISTERFILEFORCODECOMPLETION_H - -#include - -#include -#include "filecontainer.h" - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT RegisterTranslationUnitForCodeCompletionCommand -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const RegisterTranslationUnitForCodeCompletionCommand &command); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, RegisterTranslationUnitForCodeCompletionCommand &command); - friend CMBIPC_EXPORT bool operator==(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second); - friend CMBIPC_EXPORT bool operator<(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second); - friend void PrintTo(const RegisterTranslationUnitForCodeCompletionCommand &command, ::std::ostream* os); -public: - RegisterTranslationUnitForCodeCompletionCommand() = default; - RegisterTranslationUnitForCodeCompletionCommand(const QVector &fileContainers); - - const QVector &fileContainers() const; - -private: - QVector fileContainers_; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const RegisterTranslationUnitForCodeCompletionCommand &command); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, RegisterTranslationUnitForCodeCompletionCommand &command); -CMBIPC_EXPORT bool operator==(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second); -CMBIPC_EXPORT bool operator<(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const RegisterTranslationUnitForCodeCompletionCommand &command); -void PrintTo(const RegisterTranslationUnitForCodeCompletionCommand &command, ::std::ostream* os); -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::RegisterTranslationUnitForCodeCompletionCommand) - -#endif // CODEMODELBACKEND_REGISTERFILEFORCODECOMPLITION_H diff --git a/src/libs/codemodelbackendipc/cmbunregisterprojectsforcodecompletioncommand.cpp b/src/libs/codemodelbackendipc/cmbunregisterprojectsforcodecompletioncommand.cpp deleted file mode 100644 index 0d6f2ddea0..0000000000 --- a/src/libs/codemodelbackendipc/cmbunregisterprojectsforcodecompletioncommand.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "cmbunregisterprojectsforcodecompletioncommand.h" - -#include - -#include - -#include - -#include - -namespace CodeModelBackEnd { - - -UnregisterProjectPartsForCodeCompletionCommand::UnregisterProjectPartsForCodeCompletionCommand(const Utf8StringVector &filePaths) - : filePaths_(filePaths) -{ -} - -const Utf8StringVector &UnregisterProjectPartsForCodeCompletionCommand::filePaths() const -{ - return filePaths_; -} - -QDataStream &operator<<(QDataStream &out, const UnregisterProjectPartsForCodeCompletionCommand &command) -{ - out << command.filePaths_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, UnregisterProjectPartsForCodeCompletionCommand &command) -{ - in >> command.filePaths_; - - return in; -} - -bool operator==(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second) -{ - return first.filePaths_ == second.filePaths_; -} - -bool operator<(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second) -{ - return compareContainer(first.filePaths_, second.filePaths_); -} - -QDebug operator<<(QDebug debug, const UnregisterProjectPartsForCodeCompletionCommand &command) -{ - debug.nospace() << "UnregisterProjectPartsForCodeCompletionCommand("; - - for (const Utf8String &fileNames_ : command.filePaths()) - debug.nospace() << fileNames_ << ", "; - - debug.nospace() << ")"; - - return debug; -} - -void PrintTo(const UnregisterProjectPartsForCodeCompletionCommand &command, ::std::ostream* os) -{ - *os << "UnregisterProjectPartsForCodeCompletionCommand("; - - for (const Utf8String &fileNames_ : command.filePaths()) - *os << fileNames_.constData() << ", "; - - *os << ")"; -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/cmbunregisterprojectsforcodecompletioncommand.h b/src/libs/codemodelbackendipc/cmbunregisterprojectsforcodecompletioncommand.h deleted file mode 100644 index a28998afb2..0000000000 --- a/src/libs/codemodelbackendipc/cmbunregisterprojectsforcodecompletioncommand.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_UNREGISTERPROJECTSFORCODECOMPLETION_H -#define CODEMODELBACKEND_UNREGISTERPROJECTSFORCODECOMPLETION_H - -#include "codemodelbackendipc_global.h" - -#include - -#include - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT UnregisterProjectPartsForCodeCompletionCommand -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UnregisterProjectPartsForCodeCompletionCommand &command); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UnregisterProjectPartsForCodeCompletionCommand &command); - friend CMBIPC_EXPORT bool operator==(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second); - friend CMBIPC_EXPORT bool operator<(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second); - friend void PrintTo(const UnregisterProjectPartsForCodeCompletionCommand &command, ::std::ostream* os); - -public: - UnregisterProjectPartsForCodeCompletionCommand() = default; - UnregisterProjectPartsForCodeCompletionCommand(const Utf8StringVector &filePaths); - - const Utf8StringVector &filePaths() const; - -private: - Utf8StringVector filePaths_; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UnregisterProjectPartsForCodeCompletionCommand &command); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UnregisterProjectPartsForCodeCompletionCommand &command); -CMBIPC_EXPORT bool operator==(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second); -CMBIPC_EXPORT bool operator<(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const UnregisterProjectPartsForCodeCompletionCommand &command); -void PrintTo(const UnregisterProjectPartsForCodeCompletionCommand &command, ::std::ostream* os); -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::UnregisterProjectPartsForCodeCompletionCommand) - -#endif // CODEMODELBACKEND_UNREGISTERPROJECTSFORCODECOMPLETION_H diff --git a/src/libs/codemodelbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.cpp b/src/libs/codemodelbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.cpp deleted file mode 100644 index 27d905c00e..0000000000 --- a/src/libs/codemodelbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "cmbunregistertranslationunitsforcodecompletioncommand.h" - -#include - -#ifdef CODEMODELBACKEND_TESTS -#include -#endif - -#include - -#include - -namespace CodeModelBackEnd { - - -UnregisterTranslationUnitsForCodeCompletionCommand::UnregisterTranslationUnitsForCodeCompletionCommand(const QVector &fileContainers) - : fileContainers_(fileContainers) -{ -} - -const QVector &UnregisterTranslationUnitsForCodeCompletionCommand::fileContainers() const -{ - return fileContainers_; -} - -QDataStream &operator<<(QDataStream &out, const UnregisterTranslationUnitsForCodeCompletionCommand &command) -{ - out << command.fileContainers_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, UnregisterTranslationUnitsForCodeCompletionCommand &command) -{ - in >> command.fileContainers_; - - return in; -} - -bool operator==(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second) -{ - return first.fileContainers_ == second.fileContainers_; -} - -bool operator<(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second) -{ - return compareContainer(first.fileContainers_, second.fileContainers_); -} - -QDebug operator<<(QDebug debug, const UnregisterTranslationUnitsForCodeCompletionCommand &command) -{ - debug.nospace() << "UnregisterTranslationUnitsForCodeCompletionCommand("; - - for (const FileContainer &fileContainer : command.fileContainers()) - debug.nospace() << fileContainer << ", "; - - debug.nospace() << ")"; - - return debug; -} - -#ifdef CODEMODELBACKEND_TESTS -void PrintTo(const UnregisterTranslationUnitsForCodeCompletionCommand &command, ::std::ostream* os) -{ - *os << "UnregisterTranslationUnitsForCodeCompletionCommand("; - - for (const FileContainer &fileContainer : command.fileContainers()) - *os << ::testing::PrintToString(fileContainer) << ", "; - - *os << ")"; -} -#endif - - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.h b/src/libs/codemodelbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.h deleted file mode 100644 index e1593aaf04..0000000000 --- a/src/libs/codemodelbackendipc/cmbunregistertranslationunitsforcodecompletioncommand.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_UNRegisterTranslationUnitForCodeCompletionCommand_H -#define CODEMODELBACKEND_UNRegisterTranslationUnitForCodeCompletionCommand_H - -#include "codemodelbackendipc_global.h" - -#include "filecontainer.h" - -#include -#include - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT UnregisterTranslationUnitsForCodeCompletionCommand -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UnregisterTranslationUnitsForCodeCompletionCommand &command); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UnregisterTranslationUnitsForCodeCompletionCommand &command); - friend CMBIPC_EXPORT bool operator==(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second); - friend CMBIPC_EXPORT bool operator<(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second); - friend void PrintTo(const UnregisterTranslationUnitsForCodeCompletionCommand &command, ::std::ostream* os); - -public: - UnregisterTranslationUnitsForCodeCompletionCommand() = default; - UnregisterTranslationUnitsForCodeCompletionCommand(const QVector &fileContainers); - - const QVector &fileContainers() const; - -private: - QVector fileContainers_; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UnregisterTranslationUnitsForCodeCompletionCommand &command); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UnregisterTranslationUnitsForCodeCompletionCommand &command); -CMBIPC_EXPORT bool operator==(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second); -CMBIPC_EXPORT bool operator<(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const UnregisterTranslationUnitsForCodeCompletionCommand &command); -#ifdef CODEMODELBACKEND_TESTS -void PrintTo(const UnregisterTranslationUnitsForCodeCompletionCommand &command, ::std::ostream* os); -#endif -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand) - -#endif // CODEMODELBACKEND_UNRegisterTranslationUnitForCodeCompletionCommand_H diff --git a/src/libs/codemodelbackendipc/codecompletion.cpp b/src/libs/codemodelbackendipc/codecompletion.cpp deleted file mode 100644 index 651a342d23..0000000000 --- a/src/libs/codemodelbackendipc/codecompletion.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "codecompletion.h" - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -CodeCompletion::CodeCompletion(const Utf8String &text, - const Utf8String &hint, - const Utf8String &snippet, - quint32 priority, - Kind completionKind, - Availability availability, - bool hasParameters) - : text_(text), - hint_(hint), - snippet_(snippet), - priority_(priority), - completionKind_(completionKind), - availability_(availability), - hasParameters_(hasParameters) -{ -} - -void CodeCompletion::setText(const Utf8String &text) -{ - text_ = text; -} - -const Utf8String &CodeCompletion::text() const -{ - return text_; -} -const Utf8String &CodeCompletion::hint() const -{ - return hint_; -} - -const Utf8String &CodeCompletion::snippet() const -{ - return snippet_; -} - -void CodeCompletion::setCompletionKind(CodeCompletion::Kind completionKind) -{ - completionKind_ = completionKind; -} - -CodeCompletion::Kind CodeCompletion::completionKind() const -{ - return completionKind_; -} - -void CodeCompletion::setChunks(const QVector &chunks) -{ - chunks_ = chunks; -} - -const QVector &CodeCompletion::chunks() const -{ - return chunks_; -} - -void CodeCompletion::setAvailability(CodeCompletion::Availability availability) -{ - availability_ = availability; -} - -CodeCompletion::Availability CodeCompletion::availability() const -{ - return availability_; -} - -void CodeCompletion::setHasParameters(bool hasParameters) -{ - hasParameters_ = hasParameters; -} - -bool CodeCompletion::hasParameters() const -{ - return hasParameters_; -} - -void CodeCompletion::setPriority(quint32 priority) -{ - priority_ = priority; -} - -quint32 CodeCompletion::priority() const -{ - return priority_; -} - -quint32 &CodeCompletion::completionKindAsInt() -{ - return reinterpret_cast(completionKind_); -} - -quint32 &CodeCompletion::availabilityAsInt() -{ - return reinterpret_cast(availability_); -} - -QDataStream &operator<<(QDataStream &out, const CodeCompletion &command) -{ - out << command.text_; - out << command.hint_; - out << command.snippet_; - out << command.chunks_; - out << command.priority_; - out << command.completionKind_; - out << command.availability_; - out << command.hasParameters_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, CodeCompletion &command) -{ - in >> command.text_; - in >> command.hint_; - in >> command.snippet_; - in >> command.chunks_; - in >> command.priority_; - in >> command.completionKindAsInt(); - in >> command.availabilityAsInt(); - in >> command.hasParameters_; - - return in; -} - -bool operator==(const CodeCompletion &first, const CodeCompletion &second) -{ - return first.text_ == second.text_ - && first.completionKind_ == second.completionKind_; -} - -bool operator<(const CodeCompletion &first, const CodeCompletion &second) -{ - return first.text_ < second.text_; -} - -static const char *completionKindToString(CodeCompletion::Kind kind) -{ - switch (kind) { - case CodeCompletion::Other: return "Other"; - case CodeCompletion::FunctionCompletionKind: return "Function"; - case CodeCompletion::TemplateFunctionCompletionKind: return "TemplateFunction"; - case CodeCompletion::ConstructorCompletionKind: return "Constructor"; - case CodeCompletion::DestructorCompletionKind: return "Destructor"; - case CodeCompletion::VariableCompletionKind: return "Variable"; - case CodeCompletion::ClassCompletionKind: return "Class"; - case CodeCompletion::TemplateClassCompletionKind: return "TemplateClass"; - case CodeCompletion::EnumerationCompletionKind: return "Enumeration"; - case CodeCompletion::EnumeratorCompletionKind: return "Enumerator"; - case CodeCompletion::NamespaceCompletionKind: return "Namespace"; - case CodeCompletion::PreProcessorCompletionKind: return "PreProcessor"; - case CodeCompletion::SignalCompletionKind: return "Signal"; - case CodeCompletion::SlotCompletionKind: return "Slot"; - case CodeCompletion::ObjCMessageCompletionKind: return "ObjCMessage"; - case CodeCompletion::KeywordCompletionKind: return "Keyword"; - case CodeCompletion::ClangSnippetKind: return "ClangSnippet"; - } - - return nullptr; -} - -static const char *availabilityToString(CodeCompletion::Availability availability) -{ - switch (availability) { - case CodeCompletion::Available: return "Available"; - case CodeCompletion::Deprecated: return "Deprecated"; - case CodeCompletion::NotAvailable: return "NotAvailable"; - case CodeCompletion::NotAccessible: return "NotAccessible"; - } - return nullptr; -} - -QDebug operator<<(QDebug debug, const CodeCompletion &command) -{ - debug.nospace() << "CodeCompletion("; - - debug.nospace() << command.text_ << ", "; - debug.nospace() << command.hint_ << ", "; - debug.nospace() << command.snippet_ << ", "; - debug.nospace() << command.priority_ << ", "; - debug.nospace() << completionKindToString(command.completionKind_) << ", "; - debug.nospace() << availabilityToString(command.availability_) << ", "; - debug.nospace() << command.hasParameters_; - - debug.nospace() << ")"; - - return debug; -} - -void PrintTo(const CodeCompletion &command, ::std::ostream* os) -{ - *os << "CodeCompletion("; - - *os << command.text_.constData() << ", "; - *os << command.hint_.constData() << ", "; - *os << command.snippet_.constData() << ", "; - *os << command.priority_ << ", "; - *os << completionKindToString(command.completionKind_) << ", "; - *os << availabilityToString(command.availability_) << ", "; - *os << command.hasParameters_; - - *os << ")"; -} - -void PrintTo(CodeCompletion::Kind kind, ::std::ostream *os) -{ - *os << completionKindToString(kind); -} - -void PrintTo(CodeCompletion::Availability availability, std::ostream *os) -{ - *os << availabilityToString(availability); -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/codecompletion.h b/src/libs/codemodelbackendipc/codecompletion.h deleted file mode 100644 index ba64af485f..0000000000 --- a/src/libs/codemodelbackendipc/codecompletion.h +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_CODECOMPLETION_H -#define CODEMODELBACKEND_CODECOMPLETION_H - -#include -#include - -#include "codecompletionchunk.h" - -#include "codemodelbackendipc_global.h" - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT CodeCompletion -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletion &command); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CodeCompletion &command); - friend CMBIPC_EXPORT bool operator==(const CodeCompletion &first, const CodeCompletion &second); - friend CMBIPC_EXPORT bool operator<(const CodeCompletion &first, const CodeCompletion &second); - friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CodeCompletion &command); - friend void PrintTo(const CodeCompletion &command, ::std::ostream* os); - -public: - enum Kind : quint32 { - Other = 0, - FunctionCompletionKind, - TemplateFunctionCompletionKind, - ConstructorCompletionKind, - DestructorCompletionKind, - VariableCompletionKind, - ClassCompletionKind, - TemplateClassCompletionKind, - EnumerationCompletionKind, - EnumeratorCompletionKind, - NamespaceCompletionKind, - PreProcessorCompletionKind, - SignalCompletionKind, - SlotCompletionKind, - ObjCMessageCompletionKind, - KeywordCompletionKind, - ClangSnippetKind - }; - - enum Availability : quint32 { - Available, - Deprecated, - NotAvailable, - NotAccessible - }; - -public: - CodeCompletion() = default; - CodeCompletion(const Utf8String &text, - const Utf8String &hint = Utf8String(), - const Utf8String &snippet = Utf8String(), - quint32 priority = 0, - Kind completionKind = Other, - Availability availability = Available, - bool hasParameters = false); - - void setText(const Utf8String &text); - const Utf8String &text() const; - - const Utf8String &hint() const; - const Utf8String &snippet() const; - - void setCompletionKind(Kind completionKind); - Kind completionKind() const; - - void setChunks(const QVector &chunks); - const QVector &chunks() const; - - void setAvailability(Availability availability); - Availability availability() const; - - void setHasParameters(bool hasParameters); - bool hasParameters() const; - - void setPriority(quint32 priority); - quint32 priority() const; - -private: - quint32 &completionKindAsInt(); - quint32 &availabilityAsInt(); - -private: - Utf8String text_; - Utf8String hint_; - Utf8String snippet_; - QVector chunks_; - quint32 priority_ = 0; - Kind completionKind_ = Other; - Availability availability_ = NotAvailable; - bool hasParameters_ = false; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletion &command); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CodeCompletion &command); -CMBIPC_EXPORT bool operator==(const CodeCompletion &first, const CodeCompletion &second); -CMBIPC_EXPORT bool operator<(const CodeCompletion &first, const CodeCompletion &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CodeCompletion &command); -CMBIPC_EXPORT QDebug operator<<(QDebug debug, CodeCompletion::Kind kind); - -void PrintTo(const CodeCompletion &command, ::std::ostream* os); -void PrintTo(CodeCompletion::Kind kind, ::std::ostream *os); -void PrintTo(CodeCompletion::Availability availability, ::std::ostream *os); -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::CodeCompletion) - -#endif // CODEMODELBACKEND_CODECOMPLETION_H diff --git a/src/libs/codemodelbackendipc/codecompletionchunk.cpp b/src/libs/codemodelbackendipc/codecompletionchunk.cpp deleted file mode 100644 index 43363d68a4..0000000000 --- a/src/libs/codemodelbackendipc/codecompletionchunk.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "codecompletionchunk.h" - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -CodeCompletionChunk::CodeCompletionChunk() - : kind_(Invalid) -{ -} - -CodeCompletionChunk::CodeCompletionChunk(CodeCompletionChunk::Kind kind, - const Utf8String &text, - const QVector &optionalChunks) - : text_(text), - optionalChunks_(optionalChunks), - kind_(kind) -{ -} - -CodeCompletionChunk::Kind CodeCompletionChunk::kind() const -{ - return kind_; -} - -const Utf8String &CodeCompletionChunk::text() const -{ - return text_; -} - -const QVector &CodeCompletionChunk::optionalChunks() const -{ - return optionalChunks_; -} - -quint32 &CodeCompletionChunk::kindAsInt() -{ - return reinterpret_cast(kind_); -} - -QDataStream &operator<<(QDataStream &out, const CodeCompletionChunk &chunk) -{ - out << chunk.kind_; - out << chunk.text_; - - if (chunk.kind() == CodeCompletionChunk::Optional) - out << chunk.optionalChunks_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, CodeCompletionChunk &chunk) -{ - in >> chunk.kindAsInt(); - in >> chunk.text_; - - if (chunk.kind_ == CodeCompletionChunk::Optional) - in >> chunk.optionalChunks_; - - return in; -} - -bool operator==(const CodeCompletionChunk &first, const CodeCompletionChunk &second) -{ - return first.kind() == second.kind() - && first.text() == second.text() - && first.optionalChunks() == second.optionalChunks(); -} - -static const char *completionChunkKindToString(CodeCompletionChunk::Kind kind) -{ - switch (kind) { - case CodeCompletionChunk::Optional: return "Optional"; - case CodeCompletionChunk::TypedText: return "TypedText"; - case CodeCompletionChunk::Text: return "Text"; - case CodeCompletionChunk::Placeholder: return "Placeholder"; - case CodeCompletionChunk::Informative: return "Informative"; - case CodeCompletionChunk::CurrentParameter: return "CurrentParameter"; - case CodeCompletionChunk::LeftParen: return "LeftParen"; - case CodeCompletionChunk::RightParen: return "RightParen"; - case CodeCompletionChunk::LeftBracket: return "LeftBracket"; - case CodeCompletionChunk::RightBracket: return "RightBracket"; - case CodeCompletionChunk::LeftBrace: return "LeftBrace"; - case CodeCompletionChunk::RightBrace: return "RightBrace"; - case CodeCompletionChunk::LeftAngle: return "LeftAngle"; - case CodeCompletionChunk::RightAngle: return "RightAngle"; - case CodeCompletionChunk::Comma: return "Comma"; - case CodeCompletionChunk::ResultType: return "ResultType"; - case CodeCompletionChunk::Colon: return "Colon"; - case CodeCompletionChunk::SemiColon: return "SemiColon"; - case CodeCompletionChunk::Equal: return "Equal"; - case CodeCompletionChunk::HorizontalSpace: return "HorizontalSpace"; - case CodeCompletionChunk::VerticalSpace: return "VerticalSpace"; - case CodeCompletionChunk::Invalid: return "Invalid"; - } - - return nullptr; -} - -QDebug operator<<(QDebug debug, const CodeCompletionChunk &chunk) -{ - debug.nospace() << "CodeCompletionChunk("; - debug.nospace() << completionChunkKindToString(chunk.kind()) << ", "; - debug.nospace() << chunk.text(); - - if (chunk.kind() == CodeCompletionChunk::Optional) - debug.nospace() << ", " << chunk.optionalChunks(); - - debug.nospace() << ")"; - - return debug; -} - -void PrintTo(const CodeCompletionChunk &chunk, ::std::ostream* os) -{ - *os << "{"; - *os << completionChunkKindToString(chunk.kind()) << ", "; - *os << chunk.text().constData(); - - if (chunk.kind() == CodeCompletionChunk::Optional) { - const auto optionalChunks = chunk.optionalChunks(); - *os << ", {"; - - for (auto optionalChunkPosition = optionalChunks.cbegin(); - optionalChunkPosition != optionalChunks.cend(); - ++optionalChunkPosition) { - PrintTo(*optionalChunkPosition, os); - if (std::next(optionalChunkPosition) != optionalChunks.cend()) - *os << ", "; - } - - *os << "}"; - } - - *os << "}"; -} - -void PrintTo(const CodeCompletionChunk::Kind &kind, ::std::ostream* os) -{ - *os << completionChunkKindToString(kind); -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/codecompletionchunk.h b/src/libs/codemodelbackendipc/codecompletionchunk.h deleted file mode 100644 index 94648e086a..0000000000 --- a/src/libs/codemodelbackendipc/codecompletionchunk.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_CODECOMPLETIONCHUNK_H -#define CODEMODELBACKEND_CODECOMPLETIONCHUNK_H - -#include - -#include - -#include "codemodelbackendipc_global.h" - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT CodeCompletionChunk -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletionChunk &chunk); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CodeCompletionChunk &chunk); - friend CMBIPC_EXPORT bool operator==(const CodeCompletionChunk &first, const CodeCompletionChunk &second); - -public: - enum Kind : quint32 { - Optional, - TypedText, - Text, - Placeholder, - Informative, - CurrentParameter, - LeftParen, - RightParen, - LeftBracket, - RightBracket, - LeftBrace, - RightBrace, - LeftAngle, - RightAngle, - Comma, - ResultType, - Colon, - SemiColon, - Equal, - HorizontalSpace, - VerticalSpace, - Invalid = 255}; - - CodeCompletionChunk(); - CodeCompletionChunk(Kind kind, - const Utf8String &text, - const QVector &optionalChunks = QVector()); - - Kind kind() const; - const Utf8String &text() const; - const QVector &optionalChunks() const; - -private: - quint32 &kindAsInt(); - -private: - Utf8String text_; - QVector optionalChunks_; - Kind kind_ = Invalid; - -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletionChunk &chunk); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, CodeCompletionChunk &chunk); -CMBIPC_EXPORT bool operator==(const CodeCompletionChunk &first, const CodeCompletionChunk &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CodeCompletionChunk &chunk); - -void PrintTo(const CodeCompletionChunk &chunk, ::std::ostream* os); -void PrintTo(const CodeCompletionChunk::Kind &kind, ::std::ostream* os); - -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::CodeCompletionChunk) - -#endif // CODEMODELBACKEND_CODECOMPLETIONCHUNK_H diff --git a/src/libs/codemodelbackendipc/codemodelbackendipc-lib.pri b/src/libs/codemodelbackendipc/codemodelbackendipc-lib.pri deleted file mode 100644 index 8e1ff2fdb9..0000000000 --- a/src/libs/codemodelbackendipc/codemodelbackendipc-lib.pri +++ /dev/null @@ -1,73 +0,0 @@ -contains(CONFIG, dll) { - DEFINES += CODEMODELBACKENDIPC_BUILD_LIB -} else { - DEFINES += CODEMODELBACKENDIPC_BUILD_STATIC_LIB -} - -QT += network - -DEFINES += CODEMODELBACKENDIPC_LIBRARY - -INCLUDEPATH += $$PWD - -SOURCES += $$PWD/ipcserverinterface.cpp \ - $$PWD/ipcserverproxy.cpp \ - $$PWD/ipcserver.cpp \ - $$PWD/ipcclientinterface.cpp \ - $$PWD/cmbendcommand.cpp \ - $$PWD/cmbalivecommand.cpp \ - $$PWD/ipcclientproxy.cpp \ - $$PWD/cmbcommands.cpp \ - $$PWD/writecommandblock.cpp \ - $$PWD/readcommandblock.cpp \ - $$PWD/ipcinterface.cpp \ - $$PWD/connectionserver.cpp \ - $$PWD/connectionclient.cpp \ - $$PWD/cmbechocommand.cpp \ - $$PWD/ipcclientdispatcher.cpp \ - $$PWD/cmbregistertranslationunitsforcodecompletioncommand.cpp \ - $$PWD/filecontainer.cpp \ - $$PWD/cmbunregistertranslationunitsforcodecompletioncommand.cpp \ - $$PWD/cmbcompletecodecommand.cpp \ - $$PWD/cmbcodecompletedcommand.cpp \ - $$PWD/codecompletion.cpp \ - $$PWD/codemodelbackendipc_global.cpp \ - $$PWD/cmbregisterprojectsforcodecompletioncommand.cpp \ - $$PWD/cmbunregisterprojectsforcodecompletioncommand.cpp \ - $$PWD/translationunitdoesnotexistcommand.cpp \ - $$PWD/codecompletionchunk.cpp \ - $$PWD/projectpartcontainer.cpp \ - $$PWD/projectpartsdonotexistcommand.cpp - - -HEADERS += $$PWD/codemodelbackendipc_global.h \ - $$PWD/ipcserverinterface.h \ - $$PWD/ipcserverproxy.h \ - $$PWD/ipcserver.h \ - $$PWD/ipcclientinterface.h \ - $$PWD/cmbendcommand.h \ - $$PWD/cmbalivecommand.h \ - $$PWD/ipcclientproxy.h \ - $$PWD/cmbcommands.h \ - $$PWD/writecommandblock.h \ - $$PWD/readcommandblock.h \ - $$PWD/ipcinterface.h \ - $$PWD/connectionserver.h \ - $$PWD/connectionclient.h \ - $$PWD/cmbechocommand.h \ - $$PWD/ipcclientdispatcher.h \ - $$PWD/cmbregistertranslationunitsforcodecompletioncommand.h \ - $$PWD/filecontainer.h \ - $$PWD/cmbunregistertranslationunitsforcodecompletioncommand.h \ - $$PWD/cmbcompletecodecommand.h \ - $$PWD/cmbcodecompletedcommand.h \ - $$PWD/codecompletion.h \ - $$PWD/cmbregisterprojectsforcodecompletioncommand.h \ - $$PWD/cmbunregisterprojectsforcodecompletioncommand.h \ - $$PWD/translationunitdoesnotexistcommand.h \ - $$PWD/codecompletionchunk.h \ - $$PWD/projectpartcontainer.h \ - $$PWD/projectpartsdonotexistcommand.h \ - $$PWD/container_common.h - -contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols diff --git a/src/libs/codemodelbackendipc/codemodelbackendipc.pro b/src/libs/codemodelbackendipc/codemodelbackendipc.pro deleted file mode 100644 index bc048b4f9d..0000000000 --- a/src/libs/codemodelbackendipc/codemodelbackendipc.pro +++ /dev/null @@ -1,2 +0,0 @@ -include(../../qtcreatorlibrary.pri) -include(codemodelbackendipc-lib.pri) diff --git a/src/libs/codemodelbackendipc/codemodelbackendipc.qbs b/src/libs/codemodelbackendipc/codemodelbackendipc.qbs deleted file mode 100644 index 7d08615586..0000000000 --- a/src/libs/codemodelbackendipc/codemodelbackendipc.qbs +++ /dev/null @@ -1,28 +0,0 @@ -import qbs 1.0 - -QtcLibrary { - name: "CodeModelBackEndIpc" - - Depends { name: "Qt.network" } - Depends { name: "Sqlite" } - - cpp.defines: base.concat("CODEMODELBACKENDIPC_LIBRARY") - cpp.includePaths: base.concat(".") - - Group { - files: [ - "*.h", - "*.cpp" - ] - } - - Export { - Depends { name: "Sqlite" } - Depends { name: "Qt.network" } - cpp.includePaths: [ - "." - ] - } -} - - diff --git a/src/libs/codemodelbackendipc/codemodelbackendipc_dependencies.pri b/src/libs/codemodelbackendipc/codemodelbackendipc_dependencies.pri deleted file mode 100644 index 98a3a2a5d9..0000000000 --- a/src/libs/codemodelbackendipc/codemodelbackendipc_dependencies.pri +++ /dev/null @@ -1,3 +0,0 @@ -QTC_LIB_NAME = Codemodelbackendipc -QTC_LIB_DEPENDS += sqlite -INCLUDEPATH *= $$IDE_SOURCE_TREE/src/libs/codemodelbackendipc diff --git a/src/libs/codemodelbackendipc/codemodelbackendipc_global.cpp b/src/libs/codemodelbackendipc/codemodelbackendipc_global.cpp deleted file mode 100644 index 2ad16d31d7..0000000000 --- a/src/libs/codemodelbackendipc/codemodelbackendipc_global.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "codecompletion.h" - -namespace CodeModelBackEnd { -void registerTypes() -{ -} -} diff --git a/src/libs/codemodelbackendipc/codemodelbackendipc_global.h b/src/libs/codemodelbackendipc/codemodelbackendipc_global.h deleted file mode 100644 index 5a7d6cc382..0000000000 --- a/src/libs/codemodelbackendipc/codemodelbackendipc_global.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKENDIPC_GLOBAL_H -#define CODEMODELBACKENDIPC_GLOBAL_H - -#include - -#if defined(CODEMODELBACKENDIPC_LIBRARY) -# define CMBIPC_EXPORT Q_DECL_EXPORT -#else -# define CMBIPC_EXPORT Q_DECL_IMPORT -#endif - -#ifndef CODEMODELBACKENDPROCESSPATH -# define CODEMODELBACKENDPROCESSPATH "" -#endif - -namespace CodeModelBackEnd { -CMBIPC_EXPORT void registerTypes(); -} - -#endif // CODEMODELBACKENDIPC_GLOBAL_H diff --git a/src/libs/codemodelbackendipc/connectionclient.cpp b/src/libs/codemodelbackendipc/connectionclient.cpp deleted file mode 100644 index d3c9699115..0000000000 --- a/src/libs/codemodelbackendipc/connectionclient.cpp +++ /dev/null @@ -1,288 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "connectionclient.h" - -#include -#include -#include - -#include "cmbregistertranslationunitsforcodecompletioncommand.h" -#include "cmbunregistertranslationunitsforcodecompletioncommand.h" -#include "cmbcompletecodecommand.h" - -namespace CodeModelBackEnd { - -namespace { -QString currentProcessId() -{ - return QString::number(QCoreApplication::applicationPid()); -} - -QString connectionName() -{ - return QStringLiteral("CodeModelBackEnd-") + currentProcessId(); -} -} - -ConnectionClient::ConnectionClient(IpcClientInterface *client) - : serverProxy_(client, &localSocket), - isAliveTimerResetted(false) -{ - processAliveTimer.setInterval(10000); - - connect(&processAliveTimer, &QTimer::timeout, - this, &ConnectionClient::restartProcessIfTimerIsNotResettedAndSocketIsEmpty); - - connect(&localSocket, - static_cast(&QLocalSocket::error), - this, - &ConnectionClient::printLocalSocketError); -} - -ConnectionClient::~ConnectionClient() -{ - finishProcess(); -} - -bool ConnectionClient::connectToServer() -{ - startProcess(); - resetProcessAliveTimer(); - const bool isConnected = connectToLocalSocket(); - - return isConnected; -} - -bool ConnectionClient::disconnectFromServer() -{ - localSocket.disconnectFromServer(); - if (localSocket.state() != QLocalSocket::UnconnectedState) - return localSocket.waitForDisconnected(); - - return true; -} - -bool ConnectionClient::isConnected() const -{ - return localSocket.state() == QLocalSocket::ConnectedState; -} - -void ConnectionClient::sendEndCommand() -{ - serverProxy_.end(); - localSocket.flush(); -} - -void ConnectionClient::resetProcessAliveTimer() -{ - isAliveTimerResetted = true; - processAliveTimer.start(); -} - -void ConnectionClient::setProcessAliveTimerInterval(int processTimerInterval) -{ - processAliveTimer.setInterval(processTimerInterval); -} - -void ConnectionClient::startProcess() -{ - if (!isProcessIsRunning()) { - connectProcessFinished(); - connectStandardOutputAndError(); - process()->start(processPath(), {connectionName()}); - process()->waitForStarted(); - resetProcessAliveTimer(); - } -} - -void ConnectionClient::restartProcess() -{ - finishProcess(); - startProcess(); - - connectToServer(); - - emit processRestarted(); -} - -void ConnectionClient::restartProcessIfTimerIsNotResettedAndSocketIsEmpty() -{ - if (isAliveTimerResetted) { - isAliveTimerResetted = false; - return; // Already reset, but we were scheduled after. - } - - if (localSocket.bytesAvailable() > 0) - return; // We come first, the incoming data was not yet processed. - - restartProcess(); -} - -bool ConnectionClient::connectToLocalSocket() -{ - QThread::msleep(30); - - for (int counter = 0; counter < 1000; counter++) { - localSocket.connectToServer(connectionName()); - bool isConnected = localSocket.waitForConnected(20); - - if (isConnected) - return isConnected; - else - QThread::msleep(30); - } - - qDebug() << "Cannot connect:" <waitForFinished(); - } -} - -void ConnectionClient::terminateProcess() -{ -#ifndef Q_OS_WIN32 - if (isProcessIsRunning()) { - process()->terminate(); - process()->waitForFinished(); - } -#endif -} - -void ConnectionClient::killProcess() -{ - if (isProcessIsRunning()) { - process()->kill(); - process()->waitForFinished(); - } -} - -void ConnectionClient::printLocalSocketError(QLocalSocket::LocalSocketError /*socketError*/) -{ - qWarning() << "ClangCodeModel ConnectionClient LocalSocket Error:" << localSocket.errorString(); -} - -void ConnectionClient::printStandardOutput() -{ - qWarning() << "CodeModelBackEnd:" << process_->readAllStandardOutput(); -} - -void ConnectionClient::printStandardError() -{ - qWarning() << "CodeModelBackEnd Error:" << process_->readAllStandardError(); -} - -void ConnectionClient::finishProcess() -{ - processAliveTimer.stop(); - - disconnectProcessFinished(); - endProcess(); - disconnectFromServer(); - terminateProcess(); - killProcess(); - - process_.reset(); - - serverProxy_.resetCounter(); -} - -bool ConnectionClient::waitForEcho() -{ - return localSocket.waitForReadyRead(); -} - -IpcServerProxy &ConnectionClient::serverProxy() -{ - return serverProxy_; -} - -QProcess *ConnectionClient::processForTestOnly() const -{ - return process_.get(); -} - -bool ConnectionClient::isProcessIsRunning() const -{ - return process_ && process_->state() == QProcess::Running; -} - -QProcess *ConnectionClient::process() const -{ - if (!process_) - process_.reset(new QProcess); - - return process_.get(); -} - -void ConnectionClient::connectProcessFinished() const -{ - connect(process(), - static_cast(&QProcess::finished), - this, - &ConnectionClient::restartProcess); - -} - -void ConnectionClient::disconnectProcessFinished() const -{ - if (process_) { - disconnect(process_.get(), - static_cast(&QProcess::finished), - this, - &ConnectionClient::restartProcess); - } -} - -void ConnectionClient::connectStandardOutputAndError() const -{ - connect(process(), &QProcess::readyReadStandardOutput, this, &ConnectionClient::printStandardOutput); - connect(process(), &QProcess::readyReadStandardError, this, &ConnectionClient::printStandardError); -} - -const QString &ConnectionClient::processPath() const -{ - return processPath_; -} - -void ConnectionClient::setProcessPath(const QString &processPath) -{ - processPath_ = processPath; -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/connectionclient.h b/src/libs/codemodelbackendipc/connectionclient.h deleted file mode 100644 index ea36bfd08b..0000000000 --- a/src/libs/codemodelbackendipc/connectionclient.h +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_CONNECTIONCLIENT_H -#define CODEMODELBACKEND_CONNECTIONCLIENT_H - -#include - -#include - -#include "ipcserverproxy.h" - -QT_BEGIN_NAMESPACE -class QProcess; -QT_END_NAMESPACE - -class Utf8String; -class Utf8StringVector; - -namespace CodeModelBackEnd { - -class FileContainer; - -class CMBIPC_EXPORT ConnectionClient : public QObject -{ - Q_OBJECT - -public: - ConnectionClient(IpcClientInterface *client); - ~ConnectionClient(); - - bool connectToServer(); - bool disconnectFromServer(); - bool isConnected() const; - - void sendEndCommand(); - - void resetProcessAliveTimer(); - void setProcessAliveTimerInterval(int processTimerInterval); - - const QString &processPath() const; - void setProcessPath(const QString &processPath); - - void startProcess(); - void restartProcess(); - void restartProcessIfTimerIsNotResettedAndSocketIsEmpty(); - void finishProcess(); - bool isProcessIsRunning() const; - - bool waitForEcho(); - - IpcServerProxy &serverProxy(); - - QProcess *processForTestOnly() const; - -signals: - void processRestarted(); - -private: - bool connectToLocalSocket(); - void endProcess(); - void terminateProcess(); - void killProcess(); - void printLocalSocketError(QLocalSocket::LocalSocketError socketError); - void printStandardOutput(); - void printStandardError(); - - QProcess *process() const; - void connectProcessFinished() const; - void disconnectProcessFinished() const; - void connectStandardOutputAndError() const; - - void waitUntilSocketIsFlushed() const; - -private: - mutable std::unique_ptr process_; - QLocalSocket localSocket; - IpcServerProxy serverProxy_; - QTimer processAliveTimer; - QString processPath_; - bool isAliveTimerResetted; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_CONNECTIONCLIENT_H diff --git a/src/libs/codemodelbackendipc/connectionserver.cpp b/src/libs/codemodelbackendipc/connectionserver.cpp deleted file mode 100644 index 1c26c6f7c9..0000000000 --- a/src/libs/codemodelbackendipc/connectionserver.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "connectionserver.h" - -#include -#include -#include - -#include - -#include - -namespace CodeModelBackEnd { - -QString ConnectionServer::connectionName; - -ConnectionServer::ConnectionServer(const QString &connectionName) - : aliveTimerId(startTimer(5000)) -{ - this->connectionName = connectionName; - - connect(&localServer, &QLocalServer::newConnection, this, &ConnectionServer::handleNewConnection); - std::atexit(&ConnectionServer::removeServer); -#if defined(_GLIBCXX_HAVE_AT_QUICK_EXIT) - std::at_quick_exit(&ConnectionServer::removeServer); -#endif - std::set_terminate(&ConnectionServer::removeServer); -} - -ConnectionServer::~ConnectionServer() -{ - removeServer(); -} - -void ConnectionServer::start() -{ - QLocalServer::removeServer(connectionName); - localServer.listen(connectionName); -} - -void ConnectionServer::setIpcServer(IpcServerInterface *ipcServer) -{ - this->ipcServer = ipcServer; - -} - -int ConnectionServer::clientProxyCount() const -{ - return ipcClientProxies.size(); -} - -void ConnectionServer::timerEvent(QTimerEvent *timerEvent) -{ - if (aliveTimerId == timerEvent->timerId()) - sendAliveCommand(); -} - -void ConnectionServer::handleNewConnection() -{ - QLocalSocket *localSocket(nextPendingConnection()); - - ipcClientProxies.emplace_back(ipcServer, localSocket); - - ipcServer->addClient(&ipcClientProxies.back()); - - localSockets.push_back(localSocket); - - emit newConnection(); -} - -void ConnectionServer::sendAliveCommand() -{ - ipcServer->client()->alive(); -} - -void ConnectionServer::handleSocketDisconnect() -{ - QLocalSocket *senderLocalSocket = static_cast(sender()); - - removeClientProxyWithLocalSocket(senderLocalSocket); - localSockets.erase(std::remove_if(localSockets.begin(), - localSockets.end(), - [senderLocalSocket](QLocalSocket *localSocketInList) { return localSocketInList == senderLocalSocket;})); - - delayedExitApplicationIfNoSockedIsConnected(); -} - -void ConnectionServer::removeClientProxyWithLocalSocket(QLocalSocket *localSocket) -{ - ipcClientProxies.erase(std::remove_if(ipcClientProxies.begin(), - ipcClientProxies.end(), - [localSocket](const IpcClientProxy &client) { return client.isUsingThatIoDevice(localSocket);})); -} - -QLocalSocket *ConnectionServer::nextPendingConnection() -{ - QLocalSocket *localSocket = localServer.nextPendingConnection(); - - connect(localSocket, &QLocalSocket::disconnected, this, &ConnectionServer::handleSocketDisconnect); - - return localSocket; -} - -void ConnectionServer::removeServer() -{ - QLocalServer::removeServer(connectionName); -} - -void ConnectionServer::delayedExitApplicationIfNoSockedIsConnected() -{ - if (localSockets.size() == 0) - QTimer::singleShot(60000, this, &ConnectionServer::exitApplicationIfNoSockedIsConnected); -} - -void ConnectionServer::exitApplicationIfNoSockedIsConnected() -{ - if (localSockets.size() == 0) - QCoreApplication::exit(); -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/connectionserver.h b/src/libs/codemodelbackendipc/connectionserver.h deleted file mode 100644 index 1e863ba463..0000000000 --- a/src/libs/codemodelbackendipc/connectionserver.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_CONNECTIONSERVER_H -#define CODEMODELBACKEND_CONNECTIONSERVER_H - -#include -#include -#include - -namespace CodeModelBackEnd { - -class IpcServerInterface; -class IpcClientProxy; - -class CMBIPC_EXPORT ConnectionServer : public QObject -{ - Q_OBJECT -public: - ConnectionServer(const QString &connectionName); - ~ConnectionServer(); - - void start(); - void setIpcServer(IpcServerInterface *ipcServer); - - int clientProxyCount() const; - - static void removeServer(); - -signals: - void newConnection(); - -protected: - void timerEvent(QTimerEvent *timerEvent); - -private: - void handleNewConnection(); - void sendAliveCommand(); - void handleSocketDisconnect(); - void removeClientProxyWithLocalSocket(QLocalSocket *localSocket); - QLocalSocket *nextPendingConnection(); - void delayedExitApplicationIfNoSockedIsConnected(); - void exitApplicationIfNoSockedIsConnected(); - -private: - std::vector ipcClientProxies; - std::vector localSockets; - IpcServerInterface *ipcServer; - QLocalServer localServer; - static QString connectionName; - int aliveTimerId; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_CONNECTIONSERVER_H diff --git a/src/libs/codemodelbackendipc/container_common.h b/src/libs/codemodelbackendipc/container_common.h deleted file mode 100644 index 61b078dadd..0000000000 --- a/src/libs/codemodelbackendipc/container_common.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 http://www.qt.io/terms-conditions. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CONTAINER_COMMON_H -#define CONTAINER_COMMON_H - - -namespace CodeModelBackEnd { - -template -bool compareContainer(const Container &first, const Container &second) -{ - if (first.size() != second.size()) - return first.size() < second.size(); - - Container firstCopy = first; - Container secondCopy = second; - - std::sort(firstCopy.begin(), firstCopy.end()); - std::sort(secondCopy.begin(), secondCopy.end()); - - auto isProjectPartContainerSmaller = [] (decltype(*first.cbegin()) &firstElement, - decltype(*second.cbegin()) &secondElement) { - return firstElement < secondElement; - }; - - return std::equal(firstCopy.cbegin(), - firstCopy.cend(), - secondCopy.cbegin(), - isProjectPartContainerSmaller); -} -} - -#endif // CONTAINER_COMMON_H - diff --git a/src/libs/codemodelbackendipc/filecontainer.cpp b/src/libs/codemodelbackendipc/filecontainer.cpp deleted file mode 100644 index a0141d698a..0000000000 --- a/src/libs/codemodelbackendipc/filecontainer.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "filecontainer.h" - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -FileContainer::FileContainer(const Utf8String &fileName, - const Utf8String &projectPartId, - const Utf8String &unsavedFileContent, - bool hasUnsavedFileContent) - : filePath_(fileName), - projectPartId_(projectPartId), - unsavedFileContent_(unsavedFileContent), - hasUnsavedFileContent_(hasUnsavedFileContent) -{ -} - -const Utf8String &FileContainer::filePath() const -{ - return filePath_; -} - -const Utf8String &FileContainer::projectPartId() const -{ - return projectPartId_; -} - -const Utf8String &FileContainer::unsavedFileContent() const -{ - return unsavedFileContent_; -} - -bool FileContainer::hasUnsavedFileContent() const -{ - return hasUnsavedFileContent_; -} - -QDataStream &operator<<(QDataStream &out, const FileContainer &container) -{ - out << container.filePath_; - out << container.projectPartId_; - out << container.unsavedFileContent_; - out << container.hasUnsavedFileContent_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, FileContainer &container) -{ - in >> container.filePath_; - in >> container.projectPartId_; - in >> container.unsavedFileContent_; - in >> container.hasUnsavedFileContent_; - - return in; -} - -bool operator==(const FileContainer &first, const FileContainer &second) -{ - return first.filePath_ == second.filePath_ && first.projectPartId_ == second.projectPartId_; -} - -bool operator<(const FileContainer &first, const FileContainer &second) -{ - if (first.filePath_ == second.filePath_) - return first.projectPartId_ < second.projectPartId_; - - return first.filePath_ < second.filePath_; -} - -QDebug operator<<(QDebug debug, const FileContainer &container) -{ - debug.nospace() << "FileContainer(" - << container.filePath() - << ", " - << container.projectPartId(); - - if (container.hasUnsavedFileContent()) - debug.nospace() << ", " - << container.unsavedFileContent(); - - debug.nospace() << ")"; - - return debug; -} - -void PrintTo(const FileContainer &container, ::std::ostream* os) -{ - *os << "FileContainer(" - << container.filePath().constData() - << ", " - << container.projectPartId().constData(); - - if (container.hasUnsavedFileContent()) - *os << ", " - << container.unsavedFileContent().constData(); - - *os << ")"; -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/filecontainer.h b/src/libs/codemodelbackendipc/filecontainer.h deleted file mode 100644 index 9b353c3d0b..0000000000 --- a/src/libs/codemodelbackendipc/filecontainer.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_FILECONTAINER_H -#define CODEMODELBACKEND_FILECONTAINER_H - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT FileContainer -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const FileContainer &container); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, FileContainer &container); - friend CMBIPC_EXPORT bool operator==(const FileContainer &first, const FileContainer &second); - friend CMBIPC_EXPORT bool operator<(const FileContainer &first, const FileContainer &second); -public: - FileContainer() = default; - FileContainer(const Utf8String &filePath, - const Utf8String &projectPartId, - const Utf8String &unsavedFileContent = Utf8String(), - bool hasUnsavedFileContent = false); - - const Utf8String &filePath() const; - const Utf8String &projectPartId() const; - const Utf8String &unsavedFileContent() const; - bool hasUnsavedFileContent() const; - -private: - Utf8String filePath_; - Utf8String projectPartId_; - Utf8String unsavedFileContent_; - bool hasUnsavedFileContent_ = false; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const FileContainer &container); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, FileContainer &container); -CMBIPC_EXPORT bool operator==(const FileContainer &first, const FileContainer &second); -CMBIPC_EXPORT bool operator<(const FileContainer &first, const FileContainer &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const FileContainer &container); -void PrintTo(const FileContainer &container, ::std::ostream* os); - -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::FileContainer) - -#endif // CODEMODELBACKEND_FILECONTAINER_H diff --git a/src/libs/codemodelbackendipc/ipcclientdispatcher.cpp b/src/libs/codemodelbackendipc/ipcclientdispatcher.cpp deleted file mode 100644 index 8dbf4658bb..0000000000 --- a/src/libs/codemodelbackendipc/ipcclientdispatcher.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "ipcclientdispatcher.h" - -#include - -namespace CodeModelBackEnd { - -void IpcClientDispatcher::addClient(IpcClientInterface *client) -{ - clients.append(client); -} - -void IpcClientDispatcher::removeClient(IpcClientInterface *client) -{ - clients.removeOne(client); -} - -void IpcClientDispatcher::alive() -{ - for (auto *client : clients) - client->alive(); -} - -void IpcClientDispatcher::echo(const EchoCommand &command) -{ - for (auto *client : clients) - client->echo(command); -} - -void IpcClientDispatcher::codeCompleted(const CodeCompletedCommand &command) -{ - for (auto *client : clients) - client->codeCompleted(command); -} - -void IpcClientDispatcher::translationUnitDoesNotExist(const TranslationUnitDoesNotExistCommand &command) -{ - for (auto *client : clients) - client->translationUnitDoesNotExist(command); -} - -void IpcClientDispatcher::projectPartsDoNotExist(const ProjectPartsDoNotExistCommand &command) -{ - for (auto *client : clients) - client->projectPartsDoNotExist(command); -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/ipcclientdispatcher.h b/src/libs/codemodelbackendipc/ipcclientdispatcher.h deleted file mode 100644 index 8409c00524..0000000000 --- a/src/libs/codemodelbackendipc/ipcclientdispatcher.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_IPCCLIENTDISPATCHER_H -#define CODEMODELBACKEND_IPCCLIENTDISPATCHER_H - -#include "ipcclientinterface.h" - -#include - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT IpcClientDispatcher : public CodeModelBackEnd::IpcClientInterface -{ -public: - void addClient(IpcClientInterface *client); - void removeClient(IpcClientInterface *client); - - void alive() override; - void echo(const EchoCommand &command) override; - void codeCompleted(const CodeCompletedCommand &command) override; - void translationUnitDoesNotExist(const TranslationUnitDoesNotExistCommand &command) override; - void projectPartsDoNotExist(const ProjectPartsDoNotExistCommand &command) override; - -private: - QVector clients; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_IPCCLIENTDISPATCHER_H diff --git a/src/libs/codemodelbackendipc/ipcclientinterface.cpp b/src/libs/codemodelbackendipc/ipcclientinterface.cpp deleted file mode 100644 index 87fa32547b..0000000000 --- a/src/libs/codemodelbackendipc/ipcclientinterface.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "ipcclientinterface.h" - -#include -#include - -#include "cmbechocommand.h" -#include "cmbcodecompletedcommand.h" -#include "translationunitdoesnotexistcommand.h" -#include "projectpartsdonotexistcommand.h" - -namespace CodeModelBackEnd { - - -void IpcClientInterface::dispatch(const QVariant &command) -{ - static const int aliveCommandType = QMetaType::type("CodeModelBackEnd::AliveCommand"); - static const int echoCommandType = QMetaType::type("CodeModelBackEnd::EchoCommand"); - static const int codeCompletedCommandType = QMetaType::type("CodeModelBackEnd::CodeCompletedCommand"); - static const int translationUnitDoesNotExistCommand = QMetaType::type("CodeModelBackEnd::TranslationUnitDoesNotExistCommand"); - static const int projectPartsDoNotExistCommand = QMetaType::type("CodeModelBackEnd::ProjectPartsDoNotExistCommand"); - - int type = command.userType(); - - if (type == aliveCommandType) - alive(); - else if (type == echoCommandType) - echo(command.value()); - else if (type == codeCompletedCommandType) - codeCompleted(command.value()); - else if (type == translationUnitDoesNotExistCommand) - translationUnitDoesNotExist(command.value()); - else if (type == projectPartsDoNotExistCommand) - projectPartsDoNotExist(command.value()); - else - qWarning() << "Unknown IpcClientCommand"; -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/ipcclientinterface.h b/src/libs/codemodelbackendipc/ipcclientinterface.h deleted file mode 100644 index 9bf5fe1507..0000000000 --- a/src/libs/codemodelbackendipc/ipcclientinterface.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_IPCCLIENTINTERFACE_H -#define CODEMODELBACKEND_IPCCLIENTINTERFACE_H - -#include "ipcinterface.h" - -namespace CodeModelBackEnd { - -class IpcServerInterface; -class RegisterTranslationUnitForCodeCompletionCommand; -class RegisterProjectPartsForCodeCompletionCommand; -class UnregisterTranslationUnitsForCodeCompletionCommand; -class UnregisterProjectPartsForCodeCompletionCommand; -class EchoCommand; -class CompleteCodeCommand; -class CodeCompletedCommand; -class TranslationUnitDoesNotExistCommand; -class ProjectPartsDoNotExistCommand; - -class CMBIPC_EXPORT IpcClientInterface : public IpcInterface -{ -public: - void dispatch(const QVariant &command) override; - - virtual void alive() = 0; - virtual void echo(const EchoCommand &command) = 0; - virtual void codeCompleted(const CodeCompletedCommand &command) = 0; - virtual void translationUnitDoesNotExist(const TranslationUnitDoesNotExistCommand &command) = 0; - virtual void projectPartsDoNotExist(const ProjectPartsDoNotExistCommand &command) = 0; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_IPCCLIENTINTERFACE_H diff --git a/src/libs/codemodelbackendipc/ipcclientproxy.cpp b/src/libs/codemodelbackendipc/ipcclientproxy.cpp deleted file mode 100644 index 00b41fda83..0000000000 --- a/src/libs/codemodelbackendipc/ipcclientproxy.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "ipcclientproxy.h" - -#include - -#include -#include -#include -#include - -#include "ipcserverinterface.h" -#include "cmbechocommand.h" -#include "cmbregistertranslationunitsforcodecompletioncommand.h" -#include "cmbcodecompletedcommand.h" -#include "translationunitdoesnotexistcommand.h" -#include "projectpartsdonotexistcommand.h" - -namespace CodeModelBackEnd { - -IpcClientProxy::IpcClientProxy(IpcServerInterface *server, QIODevice *ioDevice) - : writeCommandBlock(ioDevice), - readCommandBlock(ioDevice), - server(server), - ioDevice(ioDevice) -{ - QObject::connect(ioDevice, &QIODevice::readyRead, [this] () {IpcClientProxy::readCommands();}); -} - -IpcClientProxy::IpcClientProxy(IpcClientProxy &&other) - : writeCommandBlock(std::move(other.writeCommandBlock)), - readCommandBlock(std::move(other.readCommandBlock)), - server(std::move(other.server)), - ioDevice(std::move(other.ioDevice)) -{ - -} - -IpcClientProxy &IpcClientProxy::operator=(IpcClientProxy &&other) -{ - writeCommandBlock = std::move(other.writeCommandBlock); - readCommandBlock = std::move(other.readCommandBlock); - server = std::move(other.server); - ioDevice = std::move(other.ioDevice); - - return *this; -} - -void IpcClientProxy::alive() -{ - writeCommandBlock.write(QVariant::fromValue(AliveCommand())); -} - -void IpcClientProxy::echo(const EchoCommand &command) -{ - writeCommandBlock.write(QVariant::fromValue(command)); -} - -void IpcClientProxy::codeCompleted(const CodeCompletedCommand &command) -{ - writeCommandBlock.write(QVariant::fromValue(command)); -} - -void IpcClientProxy::translationUnitDoesNotExist(const TranslationUnitDoesNotExistCommand &command) -{ - writeCommandBlock.write(QVariant::fromValue(command)); -} - -void IpcClientProxy::projectPartsDoNotExist(const ProjectPartsDoNotExistCommand &command) -{ - writeCommandBlock.write(QVariant::fromValue(command)); -} - -void IpcClientProxy::readCommands() -{ - for (const QVariant &command : readCommandBlock.readAll()) - server->dispatch(command); -} - -bool IpcClientProxy::isUsingThatIoDevice(QIODevice *ioDevice) const -{ - return this->ioDevice == ioDevice; -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/ipcclientproxy.h b/src/libs/codemodelbackendipc/ipcclientproxy.h deleted file mode 100644 index a829b7e841..0000000000 --- a/src/libs/codemodelbackendipc/ipcclientproxy.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODELMODELBACKEND_IPCCLIENTPROXY_H -#define CODELMODELBACKEND_IPCCLIENTPROXY_H - -#include - -#include - -#include "codemodelbackendipc_global.h" -#include "ipcclientinterface.h" - -#include "writecommandblock.h" -#include "readcommandblock.h" - -QT_BEGIN_NAMESPACE -class QLocalServer; -class QIODevice; -QT_END_NAMESPACE - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT IpcClientProxy : public IpcClientInterface -{ -public: - explicit IpcClientProxy(IpcServerInterface *server, QIODevice *ioDevice); - IpcClientProxy(const IpcClientProxy&) = delete; - const IpcClientProxy &operator=(const IpcClientProxy&) = delete; - - IpcClientProxy(IpcClientProxy&&other); - IpcClientProxy &operator=(IpcClientProxy&&other); - - void alive() override; - void echo(const EchoCommand &command) override; - void codeCompleted(const CodeCompletedCommand &command) override; - void translationUnitDoesNotExist(const TranslationUnitDoesNotExistCommand &command) override; - void projectPartsDoNotExist(const ProjectPartsDoNotExistCommand &command) override; - - void readCommands(); - - bool isUsingThatIoDevice(QIODevice *ioDevice) const; - -private: - CodeModelBackEnd::WriteCommandBlock writeCommandBlock; - CodeModelBackEnd::ReadCommandBlock readCommandBlock; - IpcServerInterface *server = nullptr; - QIODevice *ioDevice = nullptr; -}; - -} // namespace CodeModelBackEnd - -#endif // CODELMODELBACKEND_IPCCLIENTPROXY_H diff --git a/src/libs/codemodelbackendipc/ipcinterface.cpp b/src/libs/codemodelbackendipc/ipcinterface.cpp deleted file mode 100644 index 5576e80476..0000000000 --- a/src/libs/codemodelbackendipc/ipcinterface.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "ipcinterface.h" - -namespace CodeModelBackEnd { - -IpcInterface::~IpcInterface() -{ -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/ipcinterface.h b/src/libs/codemodelbackendipc/ipcinterface.h deleted file mode 100644 index c2b9de5f9e..0000000000 --- a/src/libs/codemodelbackendipc/ipcinterface.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_IPCINTERFACE_H -#define CODEMODELBACKEND_IPCINTERFACE_H - -#include - -QT_BEGIN_NAMESPACE -class QVariant; -QT_END_NAMESPACE - -#include "codemodelbackendipc_global.h" - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT IpcInterface -{ -public: - virtual ~IpcInterface(); - virtual void dispatch(const QVariant &command) = 0; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_IPCINTERFACE_H diff --git a/src/libs/codemodelbackendipc/ipcserver.cpp b/src/libs/codemodelbackendipc/ipcserver.cpp deleted file mode 100644 index dccaa5db4f..0000000000 --- a/src/libs/codemodelbackendipc/ipcserver.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "ipcserver.h" - -namespace CodeModelBackEnd { - -IpcServer::IpcServer() -{ - -} - -IpcServer::~IpcServer() -{ - -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/ipcserver.h b/src/libs/codemodelbackendipc/ipcserver.h deleted file mode 100644 index 23d5c4769f..0000000000 --- a/src/libs/codemodelbackendipc/ipcserver.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_IPCSERVER_H -#define CODEMODELBACKEND_IPCSERVER_H - -#include "ipcserverinterface.h" - -namespace CodeModelBackEnd { - -class IpcServer : public IpcServerInterface -{ -public: - IpcServer(); - ~IpcServer(); -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_IPCSERVER_H diff --git a/src/libs/codemodelbackendipc/ipcserverinterface.cpp b/src/libs/codemodelbackendipc/ipcserverinterface.cpp deleted file mode 100644 index 1ea47c0503..0000000000 --- a/src/libs/codemodelbackendipc/ipcserverinterface.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "ipcserverinterface.h" - -#include -#include - -#include "cmbregistertranslationunitsforcodecompletioncommand.h" -#include "cmbunregistertranslationunitsforcodecompletioncommand.h" -#include "cmbregisterprojectsforcodecompletioncommand.h" -#include "cmbunregisterprojectsforcodecompletioncommand.h" -#include "cmbcompletecodecommand.h" - -namespace CodeModelBackEnd { - -void IpcServerInterface::dispatch(const QVariant &command) -{ - static const int endCommandType = QMetaType::type("CodeModelBackEnd::EndCommand"); - static const int registerTranslationUnitsForCodeCompletionCommandType = QMetaType::type("CodeModelBackEnd::RegisterTranslationUnitForCodeCompletionCommand"); - static const int unregisterTranslationUnitsForCodeCompletionCommandType = QMetaType::type("CodeModelBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand"); - static const int registerProjectPartsForCodeCompletionCommandType = QMetaType::type("CodeModelBackEnd::RegisterProjectPartsForCodeCompletionCommand"); - static const int unregisterProjectPartsForCodeCompletionCommandType = QMetaType::type("CodeModelBackEnd::UnregisterProjectPartsForCodeCompletionCommand"); - static const int completeCodeCommandType = QMetaType::type("CodeModelBackEnd::CompleteCodeCommand"); - - int type = command.userType(); - - if (type == endCommandType) - end(); - else if (type == registerTranslationUnitsForCodeCompletionCommandType) - registerTranslationUnitsForCodeCompletion(command.value()); - else if (type == unregisterTranslationUnitsForCodeCompletionCommandType) - unregisterTranslationUnitsForCodeCompletion(command.value()); - else if (type == registerProjectPartsForCodeCompletionCommandType) - registerProjectPartsForCodeCompletion(command.value()); - else if (type == unregisterProjectPartsForCodeCompletionCommandType) - unregisterProjectPartsForCodeCompletion(command.value()); - else if (type == completeCodeCommandType) - completeCode(command.value()); - else - qWarning() << "Unknown IpcServerCommand"; -} - -void IpcServerInterface::addClient(IpcClientInterface *client) -{ - clientDispatcher.addClient(client); -} - -void IpcServerInterface::removeClient(IpcClientInterface *client) -{ - clientDispatcher.removeClient(client); -} - -IpcClientInterface *IpcServerInterface::client() -{ - return &clientDispatcher; -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/ipcserverinterface.h b/src/libs/codemodelbackendipc/ipcserverinterface.h deleted file mode 100644 index 1fcffcde6f..0000000000 --- a/src/libs/codemodelbackendipc/ipcserverinterface.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_IPCSERVERINTERFACE_H -#define CODEMODELBACKEND_IPCSERVERINTERFACE_H - -#include "ipcinterface.h" - -#include "ipcclientdispatcher.h" - -namespace CodeModelBackEnd { - -class IpcClientInterface; - -class CMBIPC_EXPORT IpcServerInterface : public IpcInterface -{ -public: - void dispatch(const QVariant &command) override; - - virtual void end() = 0; - virtual void registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) = 0; - virtual void unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) = 0; - virtual void registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) = 0; - virtual void unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) = 0; - virtual void completeCode(const CompleteCodeCommand &command) = 0; - - void addClient(IpcClientInterface *client); - void removeClient(IpcClientInterface *client); - - IpcClientInterface *client(); - -private: - IpcClientDispatcher clientDispatcher; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_IPCSERVERINTERFACE_H diff --git a/src/libs/codemodelbackendipc/ipcserverproxy.cpp b/src/libs/codemodelbackendipc/ipcserverproxy.cpp deleted file mode 100644 index 17d95292df..0000000000 --- a/src/libs/codemodelbackendipc/ipcserverproxy.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "ipcserverproxy.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace CodeModelBackEnd { - -IpcServerProxy::IpcServerProxy(IpcClientInterface *client, QIODevice *ioDevice) - : writeCommandBlock(ioDevice), - readCommandBlock(ioDevice), - client(client) -{ - QObject::connect(ioDevice, &QIODevice::readyRead, [this] () {IpcServerProxy::readCommands();}); -} - -void IpcServerProxy::readCommands() -{ - for (const QVariant &command : readCommandBlock.readAll()) - client->dispatch(command); -} - -void IpcServerProxy::resetCounter() -{ - writeCommandBlock.resetCounter(); - readCommandBlock.resetCounter(); -} - -void IpcServerProxy::end() -{ - writeCommandBlock.write(QVariant::fromValue(EndCommand())); -} - -void IpcServerProxy::registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) -{ - writeCommandBlock.write(QVariant::fromValue(command)); -} - -void IpcServerProxy::unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) -{ - writeCommandBlock.write(QVariant::fromValue(command)); -} - -void IpcServerProxy::registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) -{ - writeCommandBlock.write(QVariant::fromValue(command)); -} - -void IpcServerProxy::unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) -{ - writeCommandBlock.write(QVariant::fromValue(command)); -} - -void IpcServerProxy::completeCode(const CompleteCodeCommand &command) -{ - writeCommandBlock.write(QVariant::fromValue(command)); -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/ipcserverproxy.h b/src/libs/codemodelbackendipc/ipcserverproxy.h deleted file mode 100644 index 94f2a340e3..0000000000 --- a/src/libs/codemodelbackendipc/ipcserverproxy.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_IPCSERVERPROXY_H -#define CODEMODELBACKEND_IPCSERVERPROXY_H - -#include -#include - -#include - -#include "ipcserverinterface.h" -#include "writecommandblock.h" -#include "readcommandblock.h" - -QT_BEGIN_NAMESPACE -class QVariant; -class QProcess; -class QLocalServer; -class QLocalSocket; -QT_END_NAMESPACE - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT IpcServerProxy : public IpcServerInterface -{ -public: - IpcServerProxy(IpcClientInterface *client, QIODevice *ioDevice); - IpcServerProxy(const IpcServerProxy&) = delete; - IpcServerProxy &operator=(const IpcServerProxy&) = delete; - - void end() override; - void registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) override; - void unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) override; - void registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) override; - void unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) override; - void completeCode(const CompleteCodeCommand &command) override; - - void readCommands(); - - void resetCounter(); - -private: - CodeModelBackEnd::WriteCommandBlock writeCommandBlock; - CodeModelBackEnd::ReadCommandBlock readCommandBlock; - IpcClientInterface *client; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_IPCSERVERPROXY_H diff --git a/src/libs/codemodelbackendipc/projectpartcontainer.cpp b/src/libs/codemodelbackendipc/projectpartcontainer.cpp deleted file mode 100644 index 4264134c50..0000000000 --- a/src/libs/codemodelbackendipc/projectpartcontainer.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "projectpartcontainer.h" - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -ProjectPartContainer::ProjectPartContainer(const Utf8String &projectPathId, - const Utf8StringVector &arguments) - : projectPartId_(projectPathId), - arguments_(arguments) -{ -} - -const Utf8String &ProjectPartContainer::projectPartId() const -{ - return projectPartId_; -} - -const Utf8StringVector &ProjectPartContainer::arguments() const -{ - return arguments_; -} - - -QDataStream &operator<<(QDataStream &out, const ProjectPartContainer &container) -{ - out << container.projectPartId_; - out << container.arguments_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, ProjectPartContainer &container) -{ - in >> container.projectPartId_; - in >> container.arguments_; - - return in; -} - -bool operator==(const ProjectPartContainer &first, const ProjectPartContainer &second) -{ - return first.projectPartId_ == second.projectPartId_; -} - -bool operator<(const ProjectPartContainer &first, const ProjectPartContainer &second) -{ - return first.projectPartId_ < second.projectPartId_; -} - -QDebug operator<<(QDebug debug, const ProjectPartContainer &container) -{ - debug.nospace() << "ProjectPartContainer(" - << container.projectPartId() - << "," - << container.arguments() - << ")"; - - return debug; -} - -void PrintTo(const ProjectPartContainer &container, ::std::ostream* os) -{ - *os << "ProjectPartContainer(" - << container.projectPartId().constData() - << "," - << container.arguments().constData() - << ")"; -} - - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/projectpartcontainer.h b/src/libs/codemodelbackendipc/projectpartcontainer.h deleted file mode 100644 index b1bc664e55..0000000000 --- a/src/libs/codemodelbackendipc/projectpartcontainer.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_PROJECTCONTAINER_H -#define CODEMODELBACKEND_PROJECTCONTAINER_H - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT ProjectPartContainer -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const ProjectPartContainer &container); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, ProjectPartContainer &container); - friend CMBIPC_EXPORT bool operator==(const ProjectPartContainer &first, const ProjectPartContainer &second); - friend CMBIPC_EXPORT bool operator<(const ProjectPartContainer &first, const ProjectPartContainer &second); -public: - ProjectPartContainer() = default; - ProjectPartContainer(const Utf8String &projectPartId, - const Utf8StringVector &arguments = Utf8StringVector()); - - const Utf8String &projectPartId() const; - const Utf8StringVector &arguments() const; - -private: - Utf8String projectPartId_; - Utf8StringVector arguments_; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const ProjectPartContainer &container); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, ProjectPartContainer &container); -CMBIPC_EXPORT bool operator==(const ProjectPartContainer &first, const ProjectPartContainer &second); -CMBIPC_EXPORT bool operator<(const ProjectPartContainer &first, const ProjectPartContainer &second); - -QDebug operator<<(QDebug debug, const ProjectPartContainer &container); -void PrintTo(const ProjectPartContainer &container, ::std::ostream* os); - -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::ProjectPartContainer) - -#endif // CODEMODELBACKEND_PROJECTCONTAINER_H diff --git a/src/libs/codemodelbackendipc/projectpartsdonotexistcommand.cpp b/src/libs/codemodelbackendipc/projectpartsdonotexistcommand.cpp deleted file mode 100644 index c664b6030b..0000000000 --- a/src/libs/codemodelbackendipc/projectpartsdonotexistcommand.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "projectpartsdonotexistcommand.h" - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -ProjectPartsDoNotExistCommand::ProjectPartsDoNotExistCommand(const Utf8StringVector &projectPartIds) - : projectPartIds_(projectPartIds) -{ -} - - -const Utf8StringVector &ProjectPartsDoNotExistCommand::projectPartIds() const -{ - return projectPartIds_; -} - -QDataStream &operator<<(QDataStream &out, const ProjectPartsDoNotExistCommand &command) -{ - out << command.projectPartIds_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, ProjectPartsDoNotExistCommand &command) -{ - in >> command.projectPartIds_; - - return in; -} - -bool operator==(const ProjectPartsDoNotExistCommand &first, const ProjectPartsDoNotExistCommand &second) -{ - return first.projectPartIds_ == second.projectPartIds_; -} - -bool operator<(const ProjectPartsDoNotExistCommand &first, const ProjectPartsDoNotExistCommand &second) -{ - return first.projectPartIds_ < second.projectPartIds_; -} - -QDebug operator<<(QDebug debug, const ProjectPartsDoNotExistCommand &command) -{ - debug.nospace() << "ProjectPartDoesNotExistCommand("; - - debug.nospace() << command.projectPartIds_; - - debug.nospace() << ")"; - - return debug; -} - -void PrintTo(const ProjectPartsDoNotExistCommand &command, ::std::ostream* os) -{ - QString output; - QDebug debug(&output); - - debug << command; - - *os << output.toUtf8().constData(); -} - - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/projectpartsdonotexistcommand.h b/src/libs/codemodelbackendipc/projectpartsdonotexistcommand.h deleted file mode 100644 index c408fc04bb..0000000000 --- a/src/libs/codemodelbackendipc/projectpartsdonotexistcommand.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_PROJECTPARTSDONOTEXISTCOMMAND_H -#define CODEMODELBACKEND_PROJECTPARTSDONOTEXISTCOMMAND_H - -#include - -#include - -#include "codemodelbackendipc_global.h" - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT ProjectPartsDoNotExistCommand -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const ProjectPartsDoNotExistCommand &command); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, ProjectPartsDoNotExistCommand &command); - friend CMBIPC_EXPORT bool operator==(const ProjectPartsDoNotExistCommand &first, const ProjectPartsDoNotExistCommand &second); - friend CMBIPC_EXPORT bool operator<(const ProjectPartsDoNotExistCommand &first, const ProjectPartsDoNotExistCommand &second); - friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const ProjectPartsDoNotExistCommand &command); - friend void PrintTo(const ProjectPartsDoNotExistCommand &command, ::std::ostream* os); -public: - ProjectPartsDoNotExistCommand() = default; - ProjectPartsDoNotExistCommand(const Utf8StringVector &projectPartIds); - - const Utf8StringVector &projectPartIds() const; - -private: - Utf8StringVector projectPartIds_; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const ProjectPartsDoNotExistCommand &command); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, ProjectPartsDoNotExistCommand &command); -CMBIPC_EXPORT bool operator==(const ProjectPartsDoNotExistCommand &first, const ProjectPartsDoNotExistCommand &second); -CMBIPC_EXPORT bool operator<(const ProjectPartsDoNotExistCommand &first, const ProjectPartsDoNotExistCommand &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const ProjectPartsDoNotExistCommand &command); -void PrintTo(const ProjectPartsDoNotExistCommand &command, ::std::ostream* os); - -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::ProjectPartsDoNotExistCommand) - -#endif // CODEMODELBACKEND_PROJECTPARTSDONOTEXISTCOMMAND_H diff --git a/src/libs/codemodelbackendipc/readcommandblock.cpp b/src/libs/codemodelbackendipc/readcommandblock.cpp deleted file mode 100644 index 90109c0eb3..0000000000 --- a/src/libs/codemodelbackendipc/readcommandblock.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "readcommandblock.h" - -#include -#include -#include -#include - -namespace CodeModelBackEnd { - -ReadCommandBlock::ReadCommandBlock(QIODevice *ioDevice) - : ioDevice(ioDevice), - commandCounter(0), - blockSize(0) -{ -} - -void ReadCommandBlock::checkIfCommandIsLost(QDataStream &in) -{ - qint64 currentCommandCounter; - - in >> currentCommandCounter; - -#ifndef DONT_CHECK_COMMAND_COUNTER - bool commandLost = !((currentCommandCounter == 0 && commandCounter == 0) || (commandCounter + 1 == currentCommandCounter)); - if (commandLost) - qWarning() << "client command lost: " << commandCounter << currentCommandCounter; -#endif - - commandCounter = currentCommandCounter; -} - -QVariant ReadCommandBlock::read() -{ - QDataStream in(ioDevice); - - QVariant command; - - if (isTheWholeCommandReadable(in)) { - checkIfCommandIsLost(in); - in >> command; - } - - return command; -} - -QVector ReadCommandBlock::readAll() -{ - QVector commands; - - while (true) { - const QVariant command = read(); - if (command.isValid()) - commands.append(command); - else - return commands; - } - - Q_UNREACHABLE(); -} - -void ReadCommandBlock::resetCounter() -{ - commandCounter = 0; -} - -bool ReadCommandBlock::isTheWholeCommandReadable(QDataStream &in) -{ - if (ioDevice->bytesAvailable() == 0) - return false; - - if (blockSize == 0) - in >> blockSize; - - if (ioDevice->bytesAvailable() < blockSize) - return false; - - blockSize = 0; - - return true; -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/readcommandblock.h b/src/libs/codemodelbackendipc/readcommandblock.h deleted file mode 100644 index 1d4d93246f..0000000000 --- a/src/libs/codemodelbackendipc/readcommandblock.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_READCOMMANDBLOCK_H -#define CODEMODELBACKEND_READCOMMANDBLOCK_H - -#include - -QT_BEGIN_NAMESPACE -class QVariant; -class QDataStream; -class QIODevice; -QT_END_NAMESPACE - -namespace CodeModelBackEnd { - -class ReadCommandBlock -{ -public: - ReadCommandBlock(QIODevice *ioDevice = nullptr); - - QVariant read(); - QVector readAll(); - - void resetCounter(); - -private: - bool isTheWholeCommandReadable(QDataStream &in); - void checkIfCommandIsLost(QDataStream &in); - -private: - QIODevice *ioDevice; - qint64 commandCounter; - qint32 blockSize; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_READCOMMANDBLOCK_H diff --git a/src/libs/codemodelbackendipc/translationunitdoesnotexistcommand.cpp b/src/libs/codemodelbackendipc/translationunitdoesnotexistcommand.cpp deleted file mode 100644 index 0a2ce033f0..0000000000 --- a/src/libs/codemodelbackendipc/translationunitdoesnotexistcommand.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "translationunitdoesnotexistcommand.h" - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -TranslationUnitDoesNotExistCommand::TranslationUnitDoesNotExistCommand(const FileContainer &fileContainer) - : fileContainer_(fileContainer) -{ -} - -TranslationUnitDoesNotExistCommand::TranslationUnitDoesNotExistCommand(const Utf8String &filePath, const Utf8String &projectPartId) - : fileContainer_(filePath, projectPartId) -{ -} - -const FileContainer &TranslationUnitDoesNotExistCommand::fileContainer() const -{ - return fileContainer_; -} - -const Utf8String &TranslationUnitDoesNotExistCommand::filePath() const -{ - return fileContainer_.filePath(); -} - -const Utf8String &TranslationUnitDoesNotExistCommand::projectPartId() const -{ - return fileContainer_.projectPartId(); -} - -QDataStream &operator<<(QDataStream &out, const TranslationUnitDoesNotExistCommand &command) -{ - out << command.fileContainer_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, TranslationUnitDoesNotExistCommand &command) -{ - in >> command.fileContainer_; - - return in; -} - -bool operator==(const TranslationUnitDoesNotExistCommand &first, const TranslationUnitDoesNotExistCommand &second) -{ - return first.fileContainer_ == second.fileContainer_; -} - -bool operator<(const TranslationUnitDoesNotExistCommand &first, const TranslationUnitDoesNotExistCommand &second) -{ - return first.fileContainer_ < second.fileContainer_; -} - -QDebug operator<<(QDebug debug, const TranslationUnitDoesNotExistCommand &command) -{ - debug.nospace() << "TranslationUnitDoesNotExistCommand("; - - debug.nospace() << command.fileContainer_; - - debug.nospace() << ")"; - - return debug; -} - -void PrintTo(const TranslationUnitDoesNotExistCommand &command, ::std::ostream* os) -{ - QString output; - QDebug debug(&output); - - debug << command; - - *os << output.toUtf8().constData(); -} - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/translationunitdoesnotexistcommand.h b/src/libs/codemodelbackendipc/translationunitdoesnotexistcommand.h deleted file mode 100644 index 62f08a1b24..0000000000 --- a/src/libs/codemodelbackendipc/translationunitdoesnotexistcommand.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_TRANSLATIONUNITDOESNOTEXISTSCOMMAND_H -#define CODEMODELBACKEND_TRANSLATIONUNITDOESNOTEXISTSCOMMAND_H - -#include - -#include "filecontainer.h" - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT TranslationUnitDoesNotExistCommand -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const TranslationUnitDoesNotExistCommand &command); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, TranslationUnitDoesNotExistCommand &command); - friend CMBIPC_EXPORT bool operator==(const TranslationUnitDoesNotExistCommand &first, const TranslationUnitDoesNotExistCommand &second); - friend CMBIPC_EXPORT bool operator<(const TranslationUnitDoesNotExistCommand &first, const TranslationUnitDoesNotExistCommand &second); - friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const TranslationUnitDoesNotExistCommand &command); - friend void PrintTo(const TranslationUnitDoesNotExistCommand &command, ::std::ostream* os); -public: - TranslationUnitDoesNotExistCommand() = default; - TranslationUnitDoesNotExistCommand(const FileContainer &fileContainer); - TranslationUnitDoesNotExistCommand(const Utf8String &filePath, const Utf8String &projectPartId); - - const FileContainer &fileContainer() const; - const Utf8String &filePath() const; - const Utf8String &projectPartId() const; - -private: - FileContainer fileContainer_; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const TranslationUnitDoesNotExistCommand &command); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, TranslationUnitDoesNotExistCommand &command); -CMBIPC_EXPORT bool operator==(const TranslationUnitDoesNotExistCommand &first, const TranslationUnitDoesNotExistCommand &second); -CMBIPC_EXPORT bool operator<(const TranslationUnitDoesNotExistCommand &first, const TranslationUnitDoesNotExistCommand &second); - -CMBIPC_EXPORT QDebug operator<<(QDebug debug, const TranslationUnitDoesNotExistCommand &command); -void PrintTo(const TranslationUnitDoesNotExistCommand &command, ::std::ostream* os); - -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::TranslationUnitDoesNotExistCommand) - -#endif // CODEMODELBACKEND_TRANSLATIONUNITDOESNOTEXISTSCOMMAND_H diff --git a/src/libs/codemodelbackendipc/writecommandblock.cpp b/src/libs/codemodelbackendipc/writecommandblock.cpp deleted file mode 100644 index 505567fc75..0000000000 --- a/src/libs/codemodelbackendipc/writecommandblock.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "writecommandblock.h" - -#include -#include -#include -#include - -namespace CodeModelBackEnd { - -WriteCommandBlock::WriteCommandBlock(QIODevice *ioDevice) - : commandCounter(0), - ioDevice(ioDevice) -{ -} - -void WriteCommandBlock::write(const QVariant &command) -{ - QByteArray block; - QDataStream out(&block, QIODevice::WriteOnly); - - const qint32 dummyBockSize = 0; - out << dummyBockSize; - - out << commandCounter; - - out << command; - - out.device()->seek(0); - out << qint32(block.size() - sizeof(qint32)); - - ++commandCounter; - - ioDevice->write(block); -} - -qint64 WriteCommandBlock::counter() const -{ - return commandCounter; -} - -void WriteCommandBlock::resetCounter() -{ - commandCounter = 0; -} - - -} // namespace CodeModelBackEnd - diff --git a/src/libs/codemodelbackendipc/writecommandblock.h b/src/libs/codemodelbackendipc/writecommandblock.h deleted file mode 100644 index 18ee35b7c1..0000000000 --- a/src/libs/codemodelbackendipc/writecommandblock.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_WRITECOMMANDBLOCK_H -#define CODEMODELBACKEND_WRITECOMMANDBLOCK_H - -#include - -QT_BEGIN_NAMESPACE -class QVariant; -class QDataStream; -class QIODevice; -QT_END_NAMESPACE - -namespace CodeModelBackEnd { - -class WriteCommandBlock -{ -public: - WriteCommandBlock(QIODevice *ioDevice = nullptr); - - void write(const QVariant &command); - - qint64 counter() const; - - void resetCounter(); - -private: - qint64 commandCounter; - QIODevice *ioDevice; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_WRITECOMMANDBLOCK_H diff --git a/src/libs/libs.pro b/src/libs/libs.pro index 8b0d7554aa..eba9c31b8c 100644 --- a/src/libs/libs.pro +++ b/src/libs/libs.pro @@ -15,7 +15,7 @@ SUBDIRS = \ ssh \ timeline \ sqlite \ - codemodelbackendipc + clangbackendipc for(l, SUBDIRS) { QTC_LIB_DEPENDS = diff --git a/src/libs/libs.qbs b/src/libs/libs.qbs index ae2c1d0303..bd17e19553 100644 --- a/src/libs/libs.qbs +++ b/src/libs/libs.qbs @@ -4,7 +4,7 @@ Project { name: "Libs" references: [ "aggregation/aggregation.qbs", - "codemodelbackendipc/codemodelbackendipc.qbs", + "clangbackendipc/clangbackendipc.qbs", "cplusplus/cplusplus.qbs", "extensionsystem/extensionsystem.qbs", "glsl/glsl.qbs", diff --git a/src/plugins/clangcodemodel/clangbackendipcintegration.cpp b/src/plugins/clangcodemodel/clangbackendipcintegration.cpp new file mode 100644 index 0000000000..7374cfddbf --- /dev/null +++ b/src/plugins/clangcodemodel/clangbackendipcintegration.cpp @@ -0,0 +1,455 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "clangbackendipcintegration.h" + +#include "clangcompletion.h" +#include "clangmodelmanagersupport.h" +#include "clangutils.h" +#include "pchmanager.h" + +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +static Q_LOGGING_CATEGORY(log, "qtc.clangcodemodel.ipc") + +using namespace CPlusPlus; +using namespace ClangCodeModel; +using namespace ClangCodeModel::Internal; +using namespace ClangBackEnd; +using namespace TextEditor; + +namespace { + +QString backendProcessPath() +{ + return Core::ICore::libexecPath() + + QStringLiteral("/clangbackend") + + QStringLiteral(QTC_HOST_EXE_SUFFIX); +} + +} // anonymous namespace + +IpcReceiver::IpcReceiver() +{ +} + +IpcReceiver::~IpcReceiver() +{ + deleteAndClearWaitingAssistProcessors(); +} + +void IpcReceiver::setAliveHandler(const IpcReceiver::AliveHandler &handler) +{ + m_aliveHandler = handler; +} + +void IpcReceiver::addExpectedCodeCompletedCommand( + quint64 ticket, + ClangCompletionAssistProcessor *processor) +{ + QTC_ASSERT(processor, return); + QTC_CHECK(!m_assistProcessorsTable.contains(ticket)); + m_assistProcessorsTable.insert(ticket, processor); +} + +void IpcReceiver::deleteAndClearWaitingAssistProcessors() +{ + qDeleteAll(m_assistProcessorsTable.begin(), m_assistProcessorsTable.end()); + m_assistProcessorsTable.clear(); +} + +void IpcReceiver::deleteProcessorsOfEditorWidget(TextEditor::TextEditorWidget *textEditorWidget) +{ + QMutableHashIterator it(m_assistProcessorsTable); + while (it.hasNext()) { + it.next(); + ClangCompletionAssistProcessor *assistProcessor = it.value(); + if (assistProcessor->textEditorWidget() == textEditorWidget) { + delete assistProcessor; + it.remove(); + } + } +} + +void IpcReceiver::alive() +{ + qCDebug(log) << "<<< AliveCommand"; + QTC_ASSERT(m_aliveHandler, return); + m_aliveHandler(); +} + +void IpcReceiver::echo(const EchoCommand &command) +{ + qCDebug(log) << "<<<" << command; +} + +void IpcReceiver::codeCompleted(const CodeCompletedCommand &command) +{ + qCDebug(log) << "<<< CodeCompletedCommand with" << command.codeCompletions().size() << "items"; + + const quint64 ticket = command.ticketNumber(); + QScopedPointer processor(m_assistProcessorsTable.take(ticket)); + if (processor) + processor->asyncCompletionsAvailable(command.codeCompletions()); +} + +void IpcReceiver::translationUnitDoesNotExist(const TranslationUnitDoesNotExistCommand &command) +{ + QTC_CHECK(!"Got TranslationUnitDoesNotExistCommand"); + qCDebug(log) << "<<< ERROR:" << command; +} + +void IpcReceiver::projectPartsDoNotExist(const ProjectPartsDoNotExistCommand &command) +{ + QTC_CHECK(!"Got ProjectDoesNotExistCommand"); + qCDebug(log) << "<<< ERROR:" << command; +} + +class IpcSender : public IpcSenderInterface +{ +public: + IpcSender(ClangBackEnd::ConnectionClient &connectionClient) + : m_connection(connectionClient) + {} + + void end() override; + void registerTranslationUnitsForCodeCompletion(const ClangBackEnd::RegisterTranslationUnitForCodeCompletionCommand &command) override; + void unregisterTranslationUnitsForCodeCompletion(const ClangBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand &command) override; + void registerProjectPartsForCodeCompletion(const ClangBackEnd::RegisterProjectPartsForCodeCompletionCommand &command) override; + void unregisterProjectPartsForCodeCompletion(const ClangBackEnd::UnregisterProjectPartsForCodeCompletionCommand &command) override; + void completeCode(const ClangBackEnd::CompleteCodeCommand &command) override; + +private: + ClangBackEnd::ConnectionClient &m_connection; +}; + +void IpcSender::end() +{ + QTC_CHECK(m_connection.isConnected()); + m_connection.sendEndCommand(); +} + +void IpcSender::registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) +{ + QTC_CHECK(m_connection.isConnected()); + m_connection.serverProxy().registerTranslationUnitsForCodeCompletion(command); +} + +void IpcSender::unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) +{ + QTC_CHECK(m_connection.isConnected()); + m_connection.serverProxy().unregisterTranslationUnitsForCodeCompletion(command); +} + +void IpcSender::registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) +{ + QTC_CHECK(m_connection.isConnected()); + m_connection.serverProxy().registerProjectPartsForCodeCompletion(command); +} + +void IpcSender::unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) +{ + QTC_CHECK(m_connection.isConnected()); + m_connection.serverProxy().unregisterProjectPartsForCodeCompletion(command); +} + +void IpcSender::completeCode(const CompleteCodeCommand &command) +{ + QTC_CHECK(m_connection.isConnected()); + m_connection.serverProxy().completeCode(command); +} + +IpcCommunicator::IpcCommunicator() + : m_connection(&m_ipcReceiver) + , m_ipcSender(new IpcSender(m_connection)) +{ + m_ipcReceiver.setAliveHandler([this]() { m_connection.resetProcessAliveTimer(); }); + + connect(Core::EditorManager::instance(), &Core::EditorManager::editorAboutToClose, + this, &IpcCommunicator::onEditorAboutToClose); + + connect(Core::ICore::instance(), &Core::ICore::coreAboutToClose, [this]() { + m_sendMode = IgnoreSendRequests; + }); + + initializeBackend(); +} + +static bool areCommandsRegistered = false; + +void IpcCommunicator::initializeBackend() +{ + // TODO: Add a asynchron API to ConnectionClient, otherwise we might hang here + + if (!areCommandsRegistered) { + areCommandsRegistered = true; + Commands::registerCommands(); + } + QElapsedTimer timer; timer.start(); + + const QString clangBackEndProcessPath = backendProcessPath(); + qCDebug(log) << "Starting" << clangBackEndProcessPath; + QTC_ASSERT(QFileInfo(clangBackEndProcessPath).exists(), return); + + m_connection.setProcessAliveTimerInterval(10 * 1000); + m_connection.setProcessPath(clangBackEndProcessPath); + + connect(&m_connection, &ConnectionClient::processRestarted, + this, &IpcCommunicator::onBackendRestarted); + + if (m_connection.connectToServer()) { + qCDebug(log) << "...started and connected in" << timer.elapsed() << "ms."; + initializeBackendWithCurrentData(); + } else { + qCDebug(log) << "...failed."; + } +} + +void IpcCommunicator::registerEmptyProjectForProjectLessFiles() +{ + QTC_CHECK(m_connection.isConnected()); + registerProjectPartsForCodeCompletion({ClangBackEnd::ProjectPartContainer( + Utf8String(), + Utf8StringVector())}); +} + +void IpcCommunicator::registerCurrentProjectParts() +{ + using namespace CppTools; + + const QList projectInfos = CppModelManager::instance()->projectInfos(); + foreach (const ProjectInfo &projectInfo, projectInfos) + registerProjectsParts(projectInfo.projectParts()); +} + +void IpcCommunicator::registerCurrentUnsavedFiles() +{ + using namespace CppTools; + + const auto cppEditorDocuments = CppModelManager::instance()->cppEditorDocuments(); + foreach (const CppEditorDocumentHandle *cppEditorDocument, cppEditorDocuments) { + if (cppEditorDocument->processor()->baseTextDocument()->isModified()) + updateUnsavedFileFromCppEditorDocument(cppEditorDocument->filePath()); + } + +} + +void IpcCommunicator::registerCurrrentCodeModelUiHeaders() +{ + using namespace CppTools; + + const auto editorSupports = CppModelManager::instance()->abstractEditorSupports(); + foreach (const AbstractEditorSupport *es, editorSupports) + updateUnsavedFile(es->fileName(), es->contents()); +} + +static QStringList projectPartCommandLine(const CppTools::ProjectPart::Ptr &projectPart) +{ + QStringList options = ClangCodeModel::Utils::createClangOptions(projectPart, + CppTools::ProjectFile::Unclassified); // No language option + if (PchInfo::Ptr pchInfo = PchManager::instance()->pchInfo(projectPart)) + options += ClangCodeModel::Utils::createPCHInclusionOptions(pchInfo->fileName()); + return options; +} + +static ClangBackEnd::ProjectPartContainer toProjectPartContainer( + const CppTools::ProjectPart::Ptr &projectPart) +{ + const QStringList arguments = projectPartCommandLine(projectPart); + return ClangBackEnd::ProjectPartContainer(projectPart->projectFile, + Utf8StringVector(arguments)); +} + +static QVector toProjectPartContainers( + const QList projectParts) +{ + QVector projectPartContainers; + projectPartContainers.reserve(projectParts.size()); + foreach (const CppTools::ProjectPart::Ptr &projectPart, projectParts) + projectPartContainers << toProjectPartContainer(projectPart); + return projectPartContainers; +} + +void IpcCommunicator::registerProjectsParts(const QList projectParts) +{ + const auto projectPartContainers = toProjectPartContainers(projectParts); + registerProjectPartsForCodeCompletion(projectPartContainers); +} + +void IpcCommunicator::updateUnsavedFileFromCppEditorDocument(const QString &filePath) +{ + const QByteArray unsavedContent = CppTools::CppModelManager::instance() + ->cppEditorDocument(filePath)->contents(); + updateUnsavedFile(filePath, unsavedContent); +} + +void IpcCommunicator::updateUnsavedFile(const QString &filePath, const QByteArray &contents) +{ + const QString projectFilePath = Utils::projectFilePathForFile(filePath); + const bool hasUnsavedContent = true; + + // TODO: Send new only if changed + registerFilesForCodeCompletion({ + ClangBackEnd::FileContainer(filePath, + projectFilePath, + Utf8String::fromByteArray(contents), + hasUnsavedContent) + }); +} + +void IpcCommunicator::updateUnsavedFileIfNotCurrentDocument(Core::IDocument *document) +{ + QTC_ASSERT(document, return); + + if (Core::EditorManager::currentDocument() != document) + updateUnsavedFileFromCppEditorDocument(document->filePath().toString()); +} + +void IpcCommunicator::onBackendRestarted() +{ + qWarning("Clang back end finished unexpectedly, restarted."); + qCDebug(log) << "Backend restarted, re-initializing with project data and unsaved files."; + + m_ipcReceiver.deleteAndClearWaitingAssistProcessors(); + initializeBackendWithCurrentData(); +} + +void IpcCommunicator::onEditorAboutToClose(Core::IEditor *editor) +{ + if (auto *textEditor = qobject_cast(editor)) + m_ipcReceiver.deleteProcessorsOfEditorWidget(textEditor->editorWidget()); +} + +void IpcCommunicator::initializeBackendWithCurrentData() +{ + registerEmptyProjectForProjectLessFiles(); + registerCurrentProjectParts(); + registerCurrentUnsavedFiles(); + registerCurrrentCodeModelUiHeaders(); + + emit backendReinitialized(); +} + +IpcSenderInterface *IpcCommunicator::setIpcSender(IpcSenderInterface *ipcSender) +{ + IpcSenderInterface *previousCommandSender = m_ipcSender.take(); + m_ipcSender.reset(ipcSender); + return previousCommandSender; +} + +void IpcCommunicator::killBackendProcess() +{ + m_connection.processForTestOnly()->kill(); +} + +void IpcCommunicator::registerFilesForCodeCompletion(const FileContainers &fileContainers) +{ + if (m_sendMode == IgnoreSendRequests) + return; + + const RegisterTranslationUnitForCodeCompletionCommand command(fileContainers); + qCDebug(log) << ">>>" << command; + m_ipcSender->registerTranslationUnitsForCodeCompletion(command); +} + +void IpcCommunicator::unregisterFilesForCodeCompletion(const FileContainers &fileContainers) +{ + if (m_sendMode == IgnoreSendRequests) + return; + + const UnregisterTranslationUnitsForCodeCompletionCommand command(fileContainers); + qCDebug(log) << ">>>" << command; + m_ipcSender->unregisterTranslationUnitsForCodeCompletion(command); +} + +void IpcCommunicator::registerProjectPartsForCodeCompletion( + const ProjectPartContainers &projectPartContainers) +{ + if (m_sendMode == IgnoreSendRequests) + return; + + const RegisterProjectPartsForCodeCompletionCommand command(projectPartContainers); + qCDebug(log) << ">>>" << command; + m_ipcSender->registerProjectPartsForCodeCompletion(command); +} + +void IpcCommunicator::unregisterProjectPartsForCodeCompletion(const QStringList &filePaths) +{ + if (m_sendMode == IgnoreSendRequests) + return; + + const UnregisterProjectPartsForCodeCompletionCommand command((Utf8StringVector(filePaths))); + qCDebug(log) << ">>>" << command; + m_ipcSender->unregisterProjectPartsForCodeCompletion(command); +} + +void IpcCommunicator::completeCode(ClangCompletionAssistProcessor *assistProcessor, + const QString &filePath, + quint32 line, + quint32 column, + const QString &projectFilePath) +{ + if (m_sendMode == IgnoreSendRequests) + return; + + const CompleteCodeCommand command(filePath, line, column, projectFilePath); + qCDebug(log) << ">>>" << command; + m_ipcSender->completeCode(command); + m_ipcReceiver.addExpectedCodeCompletedCommand(command.ticketNumber(), assistProcessor); +} diff --git a/src/plugins/clangcodemodel/clangbackendipcintegration.h b/src/plugins/clangcodemodel/clangbackendipcintegration.h new file mode 100644 index 0000000000..365654fd92 --- /dev/null +++ b/src/plugins/clangcodemodel/clangbackendipcintegration.h @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGCODEMODEL_INTERNAL_CLANGBACKENDIPCINTEGRATION_H +#define CLANGCODEMODEL_INTERNAL_CLANGBACKENDIPCINTEGRATION_H + +#include + +#include +#include +#include +#include + +#include +#include +#include + +namespace Core { +class IEditor; +class IDocument; +} + +namespace TextEditor { +class TextEditorWidget; +} + +namespace ClangCodeModel { +namespace Internal { + +class ModelManagerSupportClang; + +class ClangCompletionAssistProcessor; + +class IpcReceiver : public ClangBackEnd::IpcClientInterface +{ +public: + IpcReceiver(); + ~IpcReceiver(); + + using AliveHandler = std::function; + void setAliveHandler(const AliveHandler &handler); + + void addExpectedCodeCompletedCommand(quint64 ticket, ClangCompletionAssistProcessor *processor); + void deleteAndClearWaitingAssistProcessors(); + void deleteProcessorsOfEditorWidget(TextEditor::TextEditorWidget *textEditorWidget); + +private: + void alive() override; + void echo(const ClangBackEnd::EchoCommand &command) override; + void codeCompleted(const ClangBackEnd::CodeCompletedCommand &command) override; + + void translationUnitDoesNotExist(const ClangBackEnd::TranslationUnitDoesNotExistCommand &command) override; + void projectPartsDoNotExist(const ClangBackEnd::ProjectPartsDoNotExistCommand &command) override; + +private: + AliveHandler m_aliveHandler; + QHash m_assistProcessorsTable; +}; + +class IpcSenderInterface +{ +public: + virtual ~IpcSenderInterface() {} + + virtual void end() = 0; + virtual void registerTranslationUnitsForCodeCompletion(const ClangBackEnd::RegisterTranslationUnitForCodeCompletionCommand &command) = 0; + virtual void unregisterTranslationUnitsForCodeCompletion(const ClangBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand &command) = 0; + virtual void registerProjectPartsForCodeCompletion(const ClangBackEnd::RegisterProjectPartsForCodeCompletionCommand &command) = 0; + virtual void unregisterProjectPartsForCodeCompletion(const ClangBackEnd::UnregisterProjectPartsForCodeCompletionCommand &command) = 0; + virtual void completeCode(const ClangBackEnd::CompleteCodeCommand &command) = 0; +}; + +class IpcCommunicator : public QObject +{ + Q_OBJECT + +public: + using Ptr = QSharedPointer; + using FileContainers = QVector; + using ProjectPartContainers = QVector; + +public: + IpcCommunicator(); + + void registerFilesForCodeCompletion(const FileContainers &fileContainers); + void unregisterFilesForCodeCompletion(const FileContainers &fileContainers); + void registerProjectPartsForCodeCompletion(const ProjectPartContainers &projectPartContainers); + void unregisterProjectPartsForCodeCompletion(const QStringList &filePaths); + void completeCode(ClangCompletionAssistProcessor *assistProcessor, const QString &filePath, + quint32 line, + quint32 column, + const QString &projectFilePath); + + void registerProjectsParts(const QList projectParts); + + void updateUnsavedFileIfNotCurrentDocument(Core::IDocument *document); + void updateUnsavedFileFromCppEditorDocument(const QString &filePath); + void updateUnsavedFile(const QString &filePath, const QByteArray &contents); + +public: // for tests + IpcSenderInterface *setIpcSender(IpcSenderInterface *ipcSender); + void killBackendProcess(); + +signals: // for tests + void backendReinitialized(); + +private: + enum SendMode { RespectSendRequests, IgnoreSendRequests }; + + void initializeBackend(); + void initializeBackendWithCurrentData(); + void registerEmptyProjectForProjectLessFiles(); + void registerCurrentProjectParts(); + void registerCurrentUnsavedFiles(); + void registerCurrrentCodeModelUiHeaders(); + + void onBackendRestarted(); + void onEditorAboutToClose(Core::IEditor *editor); + + IpcReceiver m_ipcReceiver; + ClangBackEnd::ConnectionClient m_connection; + QScopedPointer m_ipcSender; + + SendMode m_sendMode = RespectSendRequests; +}; + +} // namespace Internal +} // namespace ClangCodeModel + +#endif // CLANGCODEMODEL_INTERNAL_CLANGBACKENDIPCINTEGRATION_H diff --git a/src/plugins/clangcodemodel/clangcodemodel.pro b/src/plugins/clangcodemodel/clangcodemodel.pro index 9fe02700fa..6165b78fbf 100644 --- a/src/plugins/clangcodemodel/clangcodemodel.pro +++ b/src/plugins/clangcodemodel/clangcodemodel.pro @@ -22,7 +22,7 @@ SOURCES += \ $$PWD/clangprojectsettings.cpp \ $$PWD/clangprojectsettingspropertiespage.cpp \ $$PWD/clangutils.cpp \ - $$PWD/codemodelbackendipcintegration.cpp \ + $$PWD/clangbackendipcintegration.cpp \ $$PWD/completionchunkstotextconverter.cpp \ $$PWD/completionproposalsbuilder.cpp \ $$PWD/cppcreatemarkers.cpp \ @@ -53,7 +53,7 @@ HEADERS += \ $$PWD/clangprojectsettings.h \ $$PWD/clangprojectsettingspropertiespage.h \ $$PWD/clangutils.h \ - $$PWD/codemodelbackendipcintegration.h \ + $$PWD/clangbackendipcintegration.h \ $$PWD/completionchunkstotextconverter.h \ $$PWD/completionproposalsbuilder.h \ $$PWD/constants.h \ diff --git a/src/plugins/clangcodemodel/clangcodemodel.qbs b/src/plugins/clangcodemodel/clangcodemodel.qbs index ea0a46f0a5..8e3e2c2418 100644 --- a/src/plugins/clangcodemodel/clangcodemodel.qbs +++ b/src/plugins/clangcodemodel/clangcodemodel.qbs @@ -12,7 +12,7 @@ QtcPlugin { Depends { name: "ProjectExplorer" } Depends { name: "TextEditor" } Depends { name: "Utils" } - Depends { name: "CodeModelBackEndIpc" } + Depends { name: "ClangBackEndIpc" } pluginTestDepends: [ "CppEditor", @@ -152,8 +152,8 @@ QtcPlugin { "clangprojectsettingspropertiespage.ui", "clangutils.cpp", "clangutils.h", - "codemodelbackendipcintegration.cpp", - "codemodelbackendipcintegration.h", + "clangbackendipcintegration.cpp", + "clangbackendipcintegration.h", "completionchunkstotextconverter.cpp", "completionchunkstotextconverter.h", "constants.h", diff --git a/src/plugins/clangcodemodel/clangcodemodel_dependencies.pri b/src/plugins/clangcodemodel/clangcodemodel_dependencies.pri index e5025980de..335569d766 100644 --- a/src/plugins/clangcodemodel/clangcodemodel_dependencies.pri +++ b/src/plugins/clangcodemodel/clangcodemodel_dependencies.pri @@ -1,7 +1,7 @@ QTC_PLUGIN_NAME = ClangCodeModel QTC_LIB_DEPENDS += \ utils \ - codemodelbackendipc + clangbackendipc QTC_PLUGIN_DEPENDS += \ coreplugin \ cpptools \ diff --git a/src/plugins/clangcodemodel/clangcompletion.cpp b/src/plugins/clangcodemodel/clangcompletion.cpp index e1edeb5097..9d358231c6 100644 --- a/src/plugins/clangcodemodel/clangcompletion.cpp +++ b/src/plugins/clangcodemodel/clangcompletion.cpp @@ -68,7 +68,7 @@ #include #include -using namespace CodeModelBackEnd; +using namespace ClangBackEnd; using namespace ClangCodeModel; using namespace ClangCodeModel::Internal; using namespace CPlusPlus; diff --git a/src/plugins/clangcodemodel/clangcompletion.h b/src/plugins/clangcodemodel/clangcompletion.h index 11166f4378..09f551a2f0 100644 --- a/src/plugins/clangcodemodel/clangcompletion.h +++ b/src/plugins/clangcodemodel/clangcompletion.h @@ -32,7 +32,7 @@ #define CPPEDITOR_INTERNAL_CLANGCOMPLETION_H #include "clangcompleter.h" -#include "codemodelbackendipcintegration.h" +#include "clangbackendipcintegration.h" #include #include @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include @@ -51,7 +51,7 @@ namespace ClangCodeModel { namespace Internal { -using CodeCompletions = QVector; +using CodeCompletions = QVector; class ClangAssistProposalModel; @@ -87,16 +87,16 @@ public: void keepCompletionOperator(unsigned compOp) { m_completionOperator = compOp; } bool isOverloaded() const; - void addOverload(const CodeModelBackEnd::CodeCompletion &ccr); + void addOverload(const ClangBackEnd::CodeCompletion &ccr); - CodeModelBackEnd::CodeCompletion originalItem() const; + ClangBackEnd::CodeCompletion originalItem() const; bool isCodeCompletion() const; private: unsigned m_completionOperator; mutable QChar m_typedChar; - QList m_overloads; + QList m_overloads; }; class ClangFunctionHintModel : public TextEditor::IFunctionHintProposalModel diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp index 5f7a0ccf1a..bae1ac3e2f 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp @@ -138,7 +138,7 @@ ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor() QTC_ASSERT(m_modelManagerSupport, return); m_modelManagerSupport->ipcCommunicator()->unregisterFilesForCodeCompletion( - {CodeModelBackEnd::FileContainer(filePath(), projectFilePath)}); + {ClangBackEnd::FileContainer(filePath(), projectFilePath)}); } void ClangEditorDocumentProcessor::run() diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index 113090bfad..5a15dad80f 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -40,9 +40,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -160,7 +160,7 @@ void ModelManagerSupportClang::onAbstractEditorSupportRemoved(const QString &fil if (!cppModelManager()->cppEditorDocument(filePath)) { const QString projectFilePath = Utils::projectFilePathForFile(filePath); m_ipcCommunicator->unregisterFilesForCodeCompletion( - {CodeModelBackEnd::FileContainer(filePath, projectFilePath)}); + {ClangBackEnd::FileContainer(filePath, projectFilePath)}); } } diff --git a/src/plugins/clangcodemodel/codemodelbackendipcintegration.cpp b/src/plugins/clangcodemodel/codemodelbackendipcintegration.cpp deleted file mode 100644 index b93b0c2cf6..0000000000 --- a/src/plugins/clangcodemodel/codemodelbackendipcintegration.cpp +++ /dev/null @@ -1,455 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 http://www.qt.io/terms-conditions. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "codemodelbackendipcintegration.h" - -#include "clangcompletion.h" -#include "clangmodelmanagersupport.h" -#include "clangutils.h" -#include "pchmanager.h" - -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -static Q_LOGGING_CATEGORY(log, "qtc.clangcodemodel.ipc") - -using namespace CPlusPlus; -using namespace ClangCodeModel; -using namespace ClangCodeModel::Internal; -using namespace CodeModelBackEnd; -using namespace TextEditor; - -namespace { - -QString backendProcessPath() -{ - return Core::ICore::libexecPath() - + QStringLiteral("/codemodelbackend") - + QStringLiteral(QTC_HOST_EXE_SUFFIX); -} - -} // anonymous namespace - -IpcReceiver::IpcReceiver() -{ -} - -IpcReceiver::~IpcReceiver() -{ - deleteAndClearWaitingAssistProcessors(); -} - -void IpcReceiver::setAliveHandler(const IpcReceiver::AliveHandler &handler) -{ - m_aliveHandler = handler; -} - -void IpcReceiver::addExpectedCodeCompletedCommand( - quint64 ticket, - ClangCompletionAssistProcessor *processor) -{ - QTC_ASSERT(processor, return); - QTC_CHECK(!m_assistProcessorsTable.contains(ticket)); - m_assistProcessorsTable.insert(ticket, processor); -} - -void IpcReceiver::deleteAndClearWaitingAssistProcessors() -{ - qDeleteAll(m_assistProcessorsTable.begin(), m_assistProcessorsTable.end()); - m_assistProcessorsTable.clear(); -} - -void IpcReceiver::deleteProcessorsOfEditorWidget(TextEditor::TextEditorWidget *textEditorWidget) -{ - QMutableHashIterator it(m_assistProcessorsTable); - while (it.hasNext()) { - it.next(); - ClangCompletionAssistProcessor *assistProcessor = it.value(); - if (assistProcessor->textEditorWidget() == textEditorWidget) { - delete assistProcessor; - it.remove(); - } - } -} - -void IpcReceiver::alive() -{ - qCDebug(log) << "<<< AliveCommand"; - QTC_ASSERT(m_aliveHandler, return); - m_aliveHandler(); -} - -void IpcReceiver::echo(const EchoCommand &command) -{ - qCDebug(log) << "<<<" << command; -} - -void IpcReceiver::codeCompleted(const CodeCompletedCommand &command) -{ - qCDebug(log) << "<<< CodeCompletedCommand with" << command.codeCompletions().size() << "items"; - - const quint64 ticket = command.ticketNumber(); - QScopedPointer processor(m_assistProcessorsTable.take(ticket)); - if (processor) - processor->asyncCompletionsAvailable(command.codeCompletions()); -} - -void IpcReceiver::translationUnitDoesNotExist(const TranslationUnitDoesNotExistCommand &command) -{ - QTC_CHECK(!"Got TranslationUnitDoesNotExistCommand"); - qCDebug(log) << "<<< ERROR:" << command; -} - -void IpcReceiver::projectPartsDoNotExist(const ProjectPartsDoNotExistCommand &command) -{ - QTC_CHECK(!"Got ProjectDoesNotExistCommand"); - qCDebug(log) << "<<< ERROR:" << command; -} - -class IpcSender : public IpcSenderInterface -{ -public: - IpcSender(CodeModelBackEnd::ConnectionClient &connectionClient) - : m_connection(connectionClient) - {} - - void end() override; - void registerTranslationUnitsForCodeCompletion(const CodeModelBackEnd::RegisterTranslationUnitForCodeCompletionCommand &command) override; - void unregisterTranslationUnitsForCodeCompletion(const CodeModelBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand &command) override; - void registerProjectPartsForCodeCompletion(const CodeModelBackEnd::RegisterProjectPartsForCodeCompletionCommand &command) override; - void unregisterProjectPartsForCodeCompletion(const CodeModelBackEnd::UnregisterProjectPartsForCodeCompletionCommand &command) override; - void completeCode(const CodeModelBackEnd::CompleteCodeCommand &command) override; - -private: - CodeModelBackEnd::ConnectionClient &m_connection; -}; - -void IpcSender::end() -{ - QTC_CHECK(m_connection.isConnected()); - m_connection.sendEndCommand(); -} - -void IpcSender::registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) -{ - QTC_CHECK(m_connection.isConnected()); - m_connection.serverProxy().registerTranslationUnitsForCodeCompletion(command); -} - -void IpcSender::unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) -{ - QTC_CHECK(m_connection.isConnected()); - m_connection.serverProxy().unregisterTranslationUnitsForCodeCompletion(command); -} - -void IpcSender::registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) -{ - QTC_CHECK(m_connection.isConnected()); - m_connection.serverProxy().registerProjectPartsForCodeCompletion(command); -} - -void IpcSender::unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) -{ - QTC_CHECK(m_connection.isConnected()); - m_connection.serverProxy().unregisterProjectPartsForCodeCompletion(command); -} - -void IpcSender::completeCode(const CompleteCodeCommand &command) -{ - QTC_CHECK(m_connection.isConnected()); - m_connection.serverProxy().completeCode(command); -} - -IpcCommunicator::IpcCommunicator() - : m_connection(&m_ipcReceiver) - , m_ipcSender(new IpcSender(m_connection)) -{ - m_ipcReceiver.setAliveHandler([this]() { m_connection.resetProcessAliveTimer(); }); - - connect(Core::EditorManager::instance(), &Core::EditorManager::editorAboutToClose, - this, &IpcCommunicator::onEditorAboutToClose); - - connect(Core::ICore::instance(), &Core::ICore::coreAboutToClose, [this]() { - m_sendMode = IgnoreSendRequests; - }); - - initializeBackend(); -} - -static bool areCommandsRegistered = false; - -void IpcCommunicator::initializeBackend() -{ - // TODO: Add a asynchron API to ConnectionClient, otherwise we might hang here - - if (!areCommandsRegistered) { - areCommandsRegistered = true; - Commands::registerCommands(); - } - QElapsedTimer timer; timer.start(); - - const QString codeModelBackEndProcessPath = backendProcessPath(); - qCDebug(log) << "Starting" << codeModelBackEndProcessPath; - QTC_ASSERT(QFileInfo(codeModelBackEndProcessPath).exists(), return); - - m_connection.setProcessAliveTimerInterval(10 * 1000); - m_connection.setProcessPath(codeModelBackEndProcessPath); - - connect(&m_connection, &ConnectionClient::processRestarted, - this, &IpcCommunicator::onBackendRestarted); - - if (m_connection.connectToServer()) { - qCDebug(log) << "...started and connected in" << timer.elapsed() << "ms."; - initializeBackendWithCurrentData(); - } else { - qCDebug(log) << "...failed."; - } -} - -void IpcCommunicator::registerEmptyProjectForProjectLessFiles() -{ - QTC_CHECK(m_connection.isConnected()); - registerProjectPartsForCodeCompletion({CodeModelBackEnd::ProjectPartContainer( - Utf8String(), - Utf8StringVector())}); -} - -void IpcCommunicator::registerCurrentProjectParts() -{ - using namespace CppTools; - - const QList projectInfos = CppModelManager::instance()->projectInfos(); - foreach (const ProjectInfo &projectInfo, projectInfos) - registerProjectsParts(projectInfo.projectParts()); -} - -void IpcCommunicator::registerCurrentUnsavedFiles() -{ - using namespace CppTools; - - const auto cppEditorDocuments = CppModelManager::instance()->cppEditorDocuments(); - foreach (const CppEditorDocumentHandle *cppEditorDocument, cppEditorDocuments) { - if (cppEditorDocument->processor()->baseTextDocument()->isModified()) - updateUnsavedFileFromCppEditorDocument(cppEditorDocument->filePath()); - } - -} - -void IpcCommunicator::registerCurrrentCodeModelUiHeaders() -{ - using namespace CppTools; - - const auto editorSupports = CppModelManager::instance()->abstractEditorSupports(); - foreach (const AbstractEditorSupport *es, editorSupports) - updateUnsavedFile(es->fileName(), es->contents()); -} - -static QStringList projectPartCommandLine(const CppTools::ProjectPart::Ptr &projectPart) -{ - QStringList options = ClangCodeModel::Utils::createClangOptions(projectPart, - CppTools::ProjectFile::Unclassified); // No language option - if (PchInfo::Ptr pchInfo = PchManager::instance()->pchInfo(projectPart)) - options += ClangCodeModel::Utils::createPCHInclusionOptions(pchInfo->fileName()); - return options; -} - -static CodeModelBackEnd::ProjectPartContainer toProjectPartContainer( - const CppTools::ProjectPart::Ptr &projectPart) -{ - const QStringList arguments = projectPartCommandLine(projectPart); - return CodeModelBackEnd::ProjectPartContainer(projectPart->projectFile, - Utf8StringVector(arguments)); -} - -static QVector toProjectPartContainers( - const QList projectParts) -{ - QVector projectPartContainers; - projectPartContainers.reserve(projectParts.size()); - foreach (const CppTools::ProjectPart::Ptr &projectPart, projectParts) - projectPartContainers << toProjectPartContainer(projectPart); - return projectPartContainers; -} - -void IpcCommunicator::registerProjectsParts(const QList projectParts) -{ - const auto projectPartContainers = toProjectPartContainers(projectParts); - registerProjectPartsForCodeCompletion(projectPartContainers); -} - -void IpcCommunicator::updateUnsavedFileFromCppEditorDocument(const QString &filePath) -{ - const QByteArray unsavedContent = CppTools::CppModelManager::instance() - ->cppEditorDocument(filePath)->contents(); - updateUnsavedFile(filePath, unsavedContent); -} - -void IpcCommunicator::updateUnsavedFile(const QString &filePath, const QByteArray &contents) -{ - const QString projectFilePath = Utils::projectFilePathForFile(filePath); - const bool hasUnsavedContent = true; - - // TODO: Send new only if changed - registerFilesForCodeCompletion({ - CodeModelBackEnd::FileContainer(filePath, - projectFilePath, - Utf8String::fromByteArray(contents), - hasUnsavedContent) - }); -} - -void IpcCommunicator::updateUnsavedFileIfNotCurrentDocument(Core::IDocument *document) -{ - QTC_ASSERT(document, return); - - if (Core::EditorManager::currentDocument() != document) - updateUnsavedFileFromCppEditorDocument(document->filePath().toString()); -} - -void IpcCommunicator::onBackendRestarted() -{ - qWarning("Codemodelbackend finished unexpectedly, restarted."); - qCDebug(log) << "Backend restarted, re-initializing with project data and unsaved files."; - - m_ipcReceiver.deleteAndClearWaitingAssistProcessors(); - initializeBackendWithCurrentData(); -} - -void IpcCommunicator::onEditorAboutToClose(Core::IEditor *editor) -{ - if (auto *textEditor = qobject_cast(editor)) - m_ipcReceiver.deleteProcessorsOfEditorWidget(textEditor->editorWidget()); -} - -void IpcCommunicator::initializeBackendWithCurrentData() -{ - registerEmptyProjectForProjectLessFiles(); - registerCurrentProjectParts(); - registerCurrentUnsavedFiles(); - registerCurrrentCodeModelUiHeaders(); - - emit backendReinitialized(); -} - -IpcSenderInterface *IpcCommunicator::setIpcSender(IpcSenderInterface *ipcSender) -{ - IpcSenderInterface *previousCommandSender = m_ipcSender.take(); - m_ipcSender.reset(ipcSender); - return previousCommandSender; -} - -void IpcCommunicator::killBackendProcess() -{ - m_connection.processForTestOnly()->kill(); -} - -void IpcCommunicator::registerFilesForCodeCompletion(const FileContainers &fileContainers) -{ - if (m_sendMode == IgnoreSendRequests) - return; - - const RegisterTranslationUnitForCodeCompletionCommand command(fileContainers); - qCDebug(log) << ">>>" << command; - m_ipcSender->registerTranslationUnitsForCodeCompletion(command); -} - -void IpcCommunicator::unregisterFilesForCodeCompletion(const FileContainers &fileContainers) -{ - if (m_sendMode == IgnoreSendRequests) - return; - - const UnregisterTranslationUnitsForCodeCompletionCommand command(fileContainers); - qCDebug(log) << ">>>" << command; - m_ipcSender->unregisterTranslationUnitsForCodeCompletion(command); -} - -void IpcCommunicator::registerProjectPartsForCodeCompletion( - const ProjectPartContainers &projectPartContainers) -{ - if (m_sendMode == IgnoreSendRequests) - return; - - const RegisterProjectPartsForCodeCompletionCommand command(projectPartContainers); - qCDebug(log) << ">>>" << command; - m_ipcSender->registerProjectPartsForCodeCompletion(command); -} - -void IpcCommunicator::unregisterProjectPartsForCodeCompletion(const QStringList &filePaths) -{ - if (m_sendMode == IgnoreSendRequests) - return; - - const UnregisterProjectPartsForCodeCompletionCommand command((Utf8StringVector(filePaths))); - qCDebug(log) << ">>>" << command; - m_ipcSender->unregisterProjectPartsForCodeCompletion(command); -} - -void IpcCommunicator::completeCode(ClangCompletionAssistProcessor *assistProcessor, - const QString &filePath, - quint32 line, - quint32 column, - const QString &projectFilePath) -{ - if (m_sendMode == IgnoreSendRequests) - return; - - const CompleteCodeCommand command(filePath, line, column, projectFilePath); - qCDebug(log) << ">>>" << command; - m_ipcSender->completeCode(command); - m_ipcReceiver.addExpectedCodeCompletedCommand(command.ticketNumber(), assistProcessor); -} diff --git a/src/plugins/clangcodemodel/codemodelbackendipcintegration.h b/src/plugins/clangcodemodel/codemodelbackendipcintegration.h deleted file mode 100644 index 8891bc91aa..0000000000 --- a/src/plugins/clangcodemodel/codemodelbackendipcintegration.h +++ /dev/null @@ -1,157 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 http://www.qt.io/terms-conditions. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CLANGCODEMODEL_INTERNAL_CODEMODELBACKENDIPCINTEGRATION_H -#define CLANGCODEMODEL_INTERNAL_CODEMODELBACKENDIPCINTEGRATION_H - -#include - -#include -#include -#include -#include - -#include -#include -#include - -namespace Core { -class IEditor; -class IDocument; -} - -namespace TextEditor { -class TextEditorWidget; -} - -namespace ClangCodeModel { -namespace Internal { - -class ModelManagerSupportClang; - -class ClangCompletionAssistProcessor; - -class IpcReceiver : public CodeModelBackEnd::IpcClientInterface -{ -public: - IpcReceiver(); - ~IpcReceiver(); - - using AliveHandler = std::function; - void setAliveHandler(const AliveHandler &handler); - - void addExpectedCodeCompletedCommand(quint64 ticket, ClangCompletionAssistProcessor *processor); - void deleteAndClearWaitingAssistProcessors(); - void deleteProcessorsOfEditorWidget(TextEditor::TextEditorWidget *textEditorWidget); - -private: - void alive() override; - void echo(const CodeModelBackEnd::EchoCommand &command) override; - void codeCompleted(const CodeModelBackEnd::CodeCompletedCommand &command) override; - - void translationUnitDoesNotExist(const CodeModelBackEnd::TranslationUnitDoesNotExistCommand &command) override; - void projectPartsDoNotExist(const CodeModelBackEnd::ProjectPartsDoNotExistCommand &command) override; - -private: - AliveHandler m_aliveHandler; - QHash m_assistProcessorsTable; -}; - -class IpcSenderInterface -{ -public: - virtual ~IpcSenderInterface() {} - - virtual void end() = 0; - virtual void registerTranslationUnitsForCodeCompletion(const CodeModelBackEnd::RegisterTranslationUnitForCodeCompletionCommand &command) = 0; - virtual void unregisterTranslationUnitsForCodeCompletion(const CodeModelBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand &command) = 0; - virtual void registerProjectPartsForCodeCompletion(const CodeModelBackEnd::RegisterProjectPartsForCodeCompletionCommand &command) = 0; - virtual void unregisterProjectPartsForCodeCompletion(const CodeModelBackEnd::UnregisterProjectPartsForCodeCompletionCommand &command) = 0; - virtual void completeCode(const CodeModelBackEnd::CompleteCodeCommand &command) = 0; -}; - -class IpcCommunicator : public QObject -{ - Q_OBJECT - -public: - using Ptr = QSharedPointer; - using FileContainers = QVector; - using ProjectPartContainers = QVector; - -public: - IpcCommunicator(); - - void registerFilesForCodeCompletion(const FileContainers &fileContainers); - void unregisterFilesForCodeCompletion(const FileContainers &fileContainers); - void registerProjectPartsForCodeCompletion(const ProjectPartContainers &projectPartContainers); - void unregisterProjectPartsForCodeCompletion(const QStringList &filePaths); - void completeCode(ClangCompletionAssistProcessor *assistProcessor, const QString &filePath, - quint32 line, - quint32 column, - const QString &projectFilePath); - - void registerProjectsParts(const QList projectParts); - - void updateUnsavedFileIfNotCurrentDocument(Core::IDocument *document); - void updateUnsavedFileFromCppEditorDocument(const QString &filePath); - void updateUnsavedFile(const QString &filePath, const QByteArray &contents); - -public: // for tests - IpcSenderInterface *setIpcSender(IpcSenderInterface *ipcSender); - void killBackendProcess(); - -signals: // for tests - void backendReinitialized(); - -private: - enum SendMode { RespectSendRequests, IgnoreSendRequests }; - - void initializeBackend(); - void initializeBackendWithCurrentData(); - void registerEmptyProjectForProjectLessFiles(); - void registerCurrentProjectParts(); - void registerCurrentUnsavedFiles(); - void registerCurrrentCodeModelUiHeaders(); - - void onBackendRestarted(); - void onEditorAboutToClose(Core::IEditor *editor); - - IpcReceiver m_ipcReceiver; - CodeModelBackEnd::ConnectionClient m_connection; - QScopedPointer m_ipcSender; - - SendMode m_sendMode = RespectSendRequests; -}; - -} // namespace Internal -} // namespace ClangCodeModel - -#endif // CLANGCODEMODEL_INTERNAL_CODEMODELBACKENDIPCINTEGRATION_H diff --git a/src/plugins/clangcodemodel/completionchunkstotextconverter.cpp b/src/plugins/clangcodemodel/completionchunkstotextconverter.cpp index 507c4d6939..3027039603 100644 --- a/src/plugins/clangcodemodel/completionchunkstotextconverter.cpp +++ b/src/plugins/clangcodemodel/completionchunkstotextconverter.cpp @@ -33,7 +33,7 @@ namespace ClangCodeModel { namespace Internal { -void CompletionChunksToTextConverter::parseChunks(const QVector &codeCompletionChunks) +void CompletionChunksToTextConverter::parseChunks(const QVector &codeCompletionChunks) { m_text.clear(); @@ -46,7 +46,7 @@ const QString &CompletionChunksToTextConverter::text() const return m_text; } -QString CompletionChunksToTextConverter::convert(const QVector &codeCompletionChunks) +QString CompletionChunksToTextConverter::convert(const QVector &codeCompletionChunks) { CompletionChunksToTextConverter converter; @@ -55,9 +55,9 @@ QString CompletionChunksToTextConverter::convert(const QVector"); diff --git a/src/plugins/clangcodemodel/completionchunkstotextconverter.h b/src/plugins/clangcodemodel/completionchunkstotextconverter.h index fbb78929fe..41940f51e1 100644 --- a/src/plugins/clangcodemodel/completionchunkstotextconverter.h +++ b/src/plugins/clangcodemodel/completionchunkstotextconverter.h @@ -31,7 +31,7 @@ #ifndef CLANGCODEMODEL_INTERNAL_COMPLETIONCHUNKSTOTEXTCONVERTER_H #define CLANGCODEMODEL_INTERNAL_COMPLETIONCHUNKSTOTEXTCONVERTER_H -#include +#include #include @@ -43,17 +43,17 @@ namespace Internal { class CompletionChunksToTextConverter { public: - void parseChunks(const QVector &codeCompletionChunks); + void parseChunks(const QVector &codeCompletionChunks); const QString &text() const; - static QString convert(const QVector &codeCompletionChunks); + static QString convert(const QVector &codeCompletionChunks); private: - void parse(const CodeModelBackEnd::CodeCompletionChunk & codeCompletionChunk); + void parse(const ClangBackEnd::CodeCompletionChunk & codeCompletionChunk); void parseResultType(const Utf8String &text); void parseText(const Utf8String &text); - void parseOptional(const CodeModelBackEnd::CodeCompletionChunk & optionalCodeCompletionChunk); + void parseOptional(const ClangBackEnd::CodeCompletionChunk & optionalCodeCompletionChunk); private: QString m_text; diff --git a/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp b/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp index 7d196068fc..29b74815dd 100644 --- a/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp +++ b/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp @@ -30,7 +30,7 @@ #include "clangcodecompletion_test.h" -#include "../codemodelbackendipcintegration.h" +#include "../clangbackendipcintegration.h" #include "../clangmodelmanagersupport.h" #include @@ -52,19 +52,19 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include #include #include -using namespace CodeModelBackEnd; +using namespace ClangBackEnd; using namespace ClangCodeModel; using namespace ClangCodeModel::Internal; diff --git a/src/tools/clangbackend/clangbackend.pri b/src/tools/clangbackend/clangbackend.pri new file mode 100644 index 0000000000..099c969089 --- /dev/null +++ b/src/tools/clangbackend/clangbackend.pri @@ -0,0 +1,26 @@ +QTC_LIB_DEPENDS += \ + sqlite \ + clangbackendipc + +QT += core network +QT -= gui + +TARGET = clangbackend +CONFIG += console +CONFIG -= app_bundle C++-14 + +TEMPLATE = app + +include(ipcsource/clangbackendclangipc-source.pri) +include(../../../qtcreator.pri) +include(../../shared/clang/clang_installation.pri) +include(../../rpath.pri) + +LIBS += $$LLVM_LIBS +INCLUDEPATH += $$LLVM_INCLUDEPATH + +SOURCES += clangbackendmain.cpp + +osx { + QMAKE_LFLAGS += -Wl,-rpath,$${LLVM_LIBDIR} +} diff --git a/src/tools/clangbackend/clangbackend.pro b/src/tools/clangbackend/clangbackend.pro new file mode 100644 index 0000000000..eae95c5d92 --- /dev/null +++ b/src/tools/clangbackend/clangbackend.pro @@ -0,0 +1,5 @@ +include(clangbackend.pri) + +DESTDIR = $$IDE_LIBEXEC_PATH +target.path = $$QTC_PREFIX/bin # FIXME: libexec, more or less +INSTALLS += target diff --git a/src/tools/clangbackend/clangbackend.qbs b/src/tools/clangbackend/clangbackend.qbs new file mode 100644 index 0000000000..04499e75d0 --- /dev/null +++ b/src/tools/clangbackend/clangbackend.qbs @@ -0,0 +1,30 @@ +import qbs 1.0 +import QtcClangInstallation as Clang +import QtcProcessOutputReader + +QtcTool { + name: "clangbackend" + + Depends { name: "ClangBackEndIpc" } + + Group { + prefix: "ipcsource/" + files: [ + "*.h", + "*.cpp" + ] + } + + files: [ "clangbackendmain.cpp" ] + + property string llvmConfig: Clang.llvmConfig(qbs) + property string llvmIncludeDir: Clang.includeDir(llvmConfig, QtcProcessOutputReader) + property string llvmLibDir: Clang.libDir(llvmConfig, QtcProcessOutputReader) + property string llvmLibs: Clang.libraries(qbs.targetOS) + + condition: llvmConfig + + cpp.includePaths: base.concat(["ipcsource", llvmIncludeDir]) + cpp.libraryPaths: base.concat(llvmLibDir) + cpp.dynamicLibraries: base.concat(llvmLibs) +} diff --git a/src/tools/clangbackend/clangbackendmain.cpp b/src/tools/clangbackend/clangbackendmain.cpp new file mode 100644 index 0000000000..500515f51f --- /dev/null +++ b/src/tools/clangbackend/clangbackendmain.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication::setOrganizationName(QStringLiteral("QtProject")); + QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org")); + QCoreApplication::setApplicationName(QStringLiteral("ClangBackend")); + QCoreApplication::setApplicationVersion(QStringLiteral("1.0.0")); + + QCoreApplication application(argc, argv); + + if (application.arguments().count() != 2) { + qWarning() << "wrong argument count"; + return 1; + } + + ClangBackEnd::Commands::registerCommands(); + + ClangBackEnd::ClangIpcServer clangIpcServer; + ClangBackEnd::ConnectionServer connectionServer(application.arguments()[1]); + connectionServer.start(); + connectionServer.setIpcServer(&clangIpcServer); + + return application.exec(); +} + + diff --git a/src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri b/src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri new file mode 100644 index 0000000000..4e8800de02 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri @@ -0,0 +1,37 @@ +INCLUDEPATH += $$PWD + +HEADERS += $$PWD/clangipcserver.h \ + $$PWD/codecompleter.h \ + $$PWD/clangstring.h \ + $$PWD/translationunit.h \ + $$PWD/translationunitisnullexception.h \ + $$PWD/codecompletefailedexception.h \ + $$PWD/clangcodecompleteresults.h \ + $$PWD/codecompletionsextractor.h \ + $$PWD/unsavedfiles.h \ + $$PWD/projects.h \ + $$PWD/translationunits.h \ + $$PWD/translationunitparseerrorexception.h \ + $$PWD/projectpart.h \ + $$PWD/translationunitfilenotexitexception.h \ + $$PWD/translationunitdoesnotexistexception.h \ + $$PWD/projectpartsdonotexistexception.h \ + $$PWD/codecompletionchunkconverter.h + +SOURCES += $$PWD/clangipcserver.cpp \ + $$PWD/codecompleter.cpp \ + $$PWD/clangstring.cpp \ + $$PWD/translationunit.cpp \ + $$PWD/translationunitisnullexception.cpp \ + $$PWD/codecompletefailedexception.cpp \ + $$PWD/clangcodecompleteresults.cpp \ + $$PWD/codecompletionsextractor.cpp \ + $$PWD/unsavedfiles.cpp \ + $$PWD/projects.cpp \ + $$PWD/translationunits.cpp \ + $$PWD/translationunitparseerrorexception.cpp \ + $$PWD/projectpart.cpp \ + $$PWD/translationunitfilenotexitexception.cpp \ + $$PWD/translationunitdoesnotexistexception.cpp \ + $$PWD/projectpartsdonotexistexception.cpp \ + $$PWD/codecompletionchunkconverter.cpp diff --git a/src/tools/clangbackend/ipcsource/clangcodecompleteresults.cpp b/src/tools/clangbackend/ipcsource/clangcodecompleteresults.cpp new file mode 100644 index 0000000000..210a6a7199 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/clangcodecompleteresults.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "clangcodecompleteresults.h" + +#include + +namespace ClangBackEnd { + +using std::swap; + +ClangCodeCompleteResults::ClangCodeCompleteResults(CXCodeCompleteResults *cxCodeCompleteResults) + : cxCodeCompleteResults(cxCodeCompleteResults) +{ +} + +ClangCodeCompleteResults::~ClangCodeCompleteResults() +{ + clang_disposeCodeCompleteResults(cxCodeCompleteResults); +} + +bool ClangCodeCompleteResults::isNull() const +{ + return cxCodeCompleteResults == nullptr; +} + +CXCodeCompleteResults *ClangCodeCompleteResults::data() const +{ + return cxCodeCompleteResults; +} + +ClangCodeCompleteResults &ClangCodeCompleteResults::operator=(ClangCodeCompleteResults &&clangCodeCompleteResults) +{ + swap(cxCodeCompleteResults, clangCodeCompleteResults.cxCodeCompleteResults); + + return *this; +} + +ClangCodeCompleteResults::ClangCodeCompleteResults(ClangCodeCompleteResults &&clangCodeCompleteResults) +{ + swap(cxCodeCompleteResults, clangCodeCompleteResults.cxCodeCompleteResults); +} + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/clangcodecompleteresults.h b/src/tools/clangbackend/ipcsource/clangcodecompleteresults.h new file mode 100644 index 0000000000..1f3fdca084 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/clangcodecompleteresults.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_CLANGCODECOMPLETERESULTS_H +#define CLANGBACKEND_CLANGCODECOMPLETERESULTS_H + + +#include + +#include + +namespace ClangBackEnd { + +class ClangCodeCompleteResults +{ +public: + ClangCodeCompleteResults(CXCodeCompleteResults *cxCodeCompleteResults); + ~ClangCodeCompleteResults(); + + ClangCodeCompleteResults(const ClangCodeCompleteResults &ClangCodeCompleteResults) = delete; + const ClangCodeCompleteResults &operator=(const ClangCodeCompleteResults &ClangCodeCompleteResults) = delete; + + ClangCodeCompleteResults(ClangCodeCompleteResults &&ClangCodeCompleteResults); + ClangCodeCompleteResults &operator=(ClangCodeCompleteResults &&ClangCodeCompleteResults); + + bool isNull() const; + + CXCodeCompleteResults *data() const; + +private: + CXCodeCompleteResults *cxCodeCompleteResults = nullptr; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_CLANGCODECOMPLETERESULTS_H diff --git a/src/tools/clangbackend/ipcsource/clangipcserver.cpp b/src/tools/clangbackend/ipcsource/clangipcserver.cpp new file mode 100644 index 0000000000..11805928d1 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/clangipcserver.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "clangipcserver.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "translationunits.h" +#include "codecompleter.h" +#include "translationunitdoesnotexistexception.h" +#include "translationunitisnullexception.h" +#include "translationunitfilenotexitexception.h" +#include "projectpartsdonotexistexception.h" +#include "translationunitparseerrorexception.h" + +#include + +namespace ClangBackEnd { + +ClangIpcServer::ClangIpcServer() + : translationUnits(projects, unsavedFiles) +{ +} + +void ClangIpcServer::end() +{ + QCoreApplication::exit(); +} + +void ClangIpcServer::registerTranslationUnitsForCodeCompletion(const ClangBackEnd::RegisterTranslationUnitForCodeCompletionCommand &command) +{ + try { + translationUnits.createOrUpdate(command.fileContainers()); + unsavedFiles.createOrUpdate(command.fileContainers()); + } catch (const ProjectPartDoNotExistException &exception) { + client()->projectPartsDoNotExist(ProjectPartsDoNotExistCommand(exception.projectPartIds())); + } catch (const std::exception &exception) { + qWarning() << "Error in ClangIpcServer::registerTranslationUnitsForCodeCompletion:" << exception.what(); + } +} + +void ClangIpcServer::unregisterTranslationUnitsForCodeCompletion(const ClangBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand &command) +{ + try { + translationUnits.remove(command.fileContainers()); + } catch (const TranslationUnitDoesNotExistException &exception) { + client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistCommand(exception.fileContainer())); + } catch (const ProjectPartDoNotExistException &exception) { + client()->projectPartsDoNotExist(ProjectPartsDoNotExistCommand(exception.projectPartIds())); + } catch (const std::exception &exception) { + qWarning() << "Error in ClangIpcServer::unregisterTranslationUnitsForCodeCompletion:" << exception.what(); + } +} + +void ClangIpcServer::registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) +{ + try { + projects.createOrUpdate(command.projectContainers()); + } catch (const std::exception &exception) { + qWarning() << "Error in ClangIpcServer::registerProjectPartsForCodeCompletion:" << exception.what(); + } +} + +void ClangIpcServer::unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) +{ + try { + projects.remove(command.filePaths()); + } catch (const ProjectPartDoNotExistException &exception) { + client()->projectPartsDoNotExist(ProjectPartsDoNotExistCommand(exception.projectPartIds())); + } catch (const std::exception &exception) { + qWarning() << "Error in ClangIpcServer::unregisterProjectPartsForCodeCompletion:" << exception.what(); + } +} + +void ClangIpcServer::completeCode(const ClangBackEnd::CompleteCodeCommand &command) +{ + try { + CodeCompleter codeCompleter(translationUnits.translationUnit(command.filePath(), command.projectPartId())); + + const auto codeCompletions = codeCompleter.complete(command.line(), command.column()); + + client()->codeCompleted(CodeCompletedCommand(codeCompletions, command.ticketNumber())); + } catch (const TranslationUnitDoesNotExistException &exception) { + client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistCommand(exception.fileContainer())); + } catch (const ProjectPartDoNotExistException &exception) { + client()->projectPartsDoNotExist(ProjectPartsDoNotExistCommand(exception.projectPartIds())); + } catch (const std::exception &exception) { + qWarning() << "Error in ClangIpcServer::unregisterProjectPartsForCodeCompletion:" << exception.what(); + } +} + +} diff --git a/src/tools/clangbackend/ipcsource/clangipcserver.h b/src/tools/clangbackend/ipcsource/clangipcserver.h new file mode 100644 index 0000000000..4f2418da43 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/clangipcserver.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGIPCSERVER_H +#define CLANGIPCSERVER_H + +#include "ipcserverinterface.h" + +#include "translationunit.h" +#include "projectpart.h" +#include "unsavedfiles.h" +#include "projects.h" +#include "translationunits.h" + +#include + +#include + +namespace ClangBackEnd { + +class ClangIpcServer : public IpcServerInterface +{ +public: + ClangIpcServer(); + + void end() override; + void registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) override; + void unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) override; + void registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) override; + void unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) override; + void completeCode(const CompleteCodeCommand &command) override; + +private: + ProjectParts projects; + UnsavedFiles unsavedFiles; + TranslationUnits translationUnits; +}; + +} // namespace ClangBackEnd +#endif // CLANGIPCSERVER_H diff --git a/src/tools/clangbackend/ipcsource/clangstring.cpp b/src/tools/clangbackend/ipcsource/clangstring.cpp new file mode 100644 index 0000000000..00bd83a3a3 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/clangstring.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "clangstring.h" + +#include + +namespace ClangBackEnd { + +ClangString::ClangString(CXString cxString) + : cxString(cxString) +{ +} + +ClangString::~ClangString() +{ + clang_disposeString(cxString); +} + +bool ClangString::isNull() const +{ + return cxString.data == nullptr; +} + +ClangString &ClangString::operator=(ClangString &&clangString) +{ + cxString = std::move(clangString.cxString); + clangString.cxString.data = nullptr; + clangString.cxString.private_flags = 0; + + return *this; +} + +ClangString::ClangString(ClangString &&clangString) + : cxString(std::move(clangString.cxString)) +{ + clangString.cxString.data = nullptr; + clangString.cxString.private_flags = 0; +} + +ClangString::operator Utf8String() const +{ + return Utf8String(clang_getCString(cxString), -1); +} + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/clangstring.h b/src/tools/clangbackend/ipcsource/clangstring.h new file mode 100644 index 0000000000..d0b1055a03 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/clangstring.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_CLANGSTRING_H +#define CLANGBACKEND_CLANGSTRING_H + +#include + +#include + +namespace ClangBackEnd { + +class ClangString +{ +public: + ClangString(CXString cxString); + ~ClangString(); + + ClangString(const ClangString &clangString) = delete; + const ClangString &operator=(const ClangString &clangString) = delete; + + ClangString(ClangString &&clangString); + ClangString &operator=(ClangString &&clangString); + + operator Utf8String() const; + + bool isNull() const; + +private: + CXString cxString; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_CLANGSTRING_H diff --git a/src/tools/clangbackend/ipcsource/codecompletefailedexception.cpp b/src/tools/clangbackend/ipcsource/codecompletefailedexception.cpp new file mode 100644 index 0000000000..f9b4231bbd --- /dev/null +++ b/src/tools/clangbackend/ipcsource/codecompletefailedexception.cpp @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "codecompletefailedexception.h" + +CodeCompleteFailedException::CodeCompleteFailedException() +{ + +} + diff --git a/src/tools/clangbackend/ipcsource/codecompletefailedexception.h b/src/tools/clangbackend/ipcsource/codecompletefailedexception.h new file mode 100644 index 0000000000..b792afd907 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/codecompletefailedexception.h @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CODECOMPLETEFAILEDEXCEPTION_H +#define CODECOMPLETEFAILEDEXCEPTION_H + + +class CodeCompleteFailedException +{ +public: + CodeCompleteFailedException(); +}; + +#endif // CODECOMPLETEFAILEDEXCEPTION_H diff --git a/src/tools/clangbackend/ipcsource/codecompleter.cpp b/src/tools/clangbackend/ipcsource/codecompleter.cpp new file mode 100644 index 0000000000..6aebe1a5f1 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/codecompleter.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "codecompleter.h" + +#include "clangstring.h" +#include "clangcodecompleteresults.h" +#include "translationunit.h" +#include "codecompletefailedexception.h" + +#include "codecompletionsextractor.h" + +#include + +#include + +namespace ClangBackEnd { + +CodeCompleter::CodeCompleter(TranslationUnit translationUnit) + : translationUnit(std::move(translationUnit)) +{ +} + +QVector CodeCompleter::complete(uint line, uint column) +{ + ClangCodeCompleteResults completeResults(clang_codeCompleteAt(translationUnit.cxTranslationUnit(), + translationUnit.filePath().constData(), + line, + column, + translationUnit.cxUnsavedFiles(), + translationUnit.unsavedFilesCount(), + CXCodeComplete_IncludeMacros | CXCodeComplete_IncludeCodePatterns)); + + CodeCompletionsExtractor extractor(completeResults.data()); + + return extractor.extractAll(); +} + +Utf8String CodeCompleter::filePath() const +{ + return translationUnit.filePath(); +} + +void CodeCompleter::checkCodeCompleteResult(CXCodeCompleteResults *completeResults) +{ + if (!completeResults) + throw CodeCompleteFailedException(); +} + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/codecompleter.h b/src/tools/clangbackend/ipcsource/codecompleter.h new file mode 100644 index 0000000000..cf9f0aba6b --- /dev/null +++ b/src/tools/clangbackend/ipcsource/codecompleter.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_CODECOMPLETER_H +#define CLANGBACKEND_CODECOMPLETER_H + +#include +#include + +#include "translationunit.h" + +namespace ClangBackEnd { + +class TranslationUnit; + +class CodeCompleter +{ +public: + CodeCompleter() = default; + CodeCompleter(TranslationUnit translationUnit); + + QVector complete(uint line, uint column); + +private: + Utf8String filePath() const; + static void checkCodeCompleteResult(CXCodeCompleteResults *completeResults); + +private: + TranslationUnit translationUnit; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_CODECOMPLETER_H diff --git a/src/tools/clangbackend/ipcsource/codecompletionchunkconverter.cpp b/src/tools/clangbackend/ipcsource/codecompletionchunkconverter.cpp new file mode 100644 index 0000000000..7fb2429c25 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/codecompletionchunkconverter.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "codecompletionchunkconverter.h" + +#include "clangstring.h" + +namespace ClangBackEnd { + +void CodeCompletionChunkConverter::extractCompletionChunks(CXCompletionString completionString) +{ + const uint completionChunkCount = clang_getNumCompletionChunks(completionString); + + for (uint chunkIndex = 0; chunkIndex < completionChunkCount; ++chunkIndex) { + const CodeCompletionChunk::Kind kind = chunkKind(completionString, chunkIndex); + + if (kind == CodeCompletionChunk::Optional) + chunks.append(CodeCompletionChunk(kind, + chunkText(completionString, chunkIndex), + optionalChunks(completionString, chunkIndex))); + else + chunks.append(CodeCompletionChunk(kind, + chunkText(completionString, chunkIndex))); + } +} + +void CodeCompletionChunkConverter::extractOptionalCompletionChunks(CXCompletionString completionString) +{ + const uint completionChunkCount = clang_getNumCompletionChunks(completionString); + + for (uint chunkIndex = 0; chunkIndex < completionChunkCount; ++chunkIndex) { + const CodeCompletionChunk::Kind kind = chunkKind(completionString, chunkIndex); + + if (kind == CodeCompletionChunk::Optional) + extractOptionalCompletionChunks(clang_getCompletionChunkCompletionString(completionString, chunkIndex)); + else + chunks.append(CodeCompletionChunk(kind, chunkText(completionString, chunkIndex))); + } +} + +CodeCompletionChunk::Kind CodeCompletionChunkConverter::chunkKind(CXCompletionString completionString, uint chunkIndex) +{ + return CodeCompletionChunk::Kind(clang_getCompletionChunkKind(completionString, chunkIndex)); +} + +QVector CodeCompletionChunkConverter::extract(CXCompletionString completionString) +{ + CodeCompletionChunkConverter converter; + + converter.extractCompletionChunks(completionString); + + return converter.chunks; +} + +Utf8String CodeCompletionChunkConverter::chunkText(CXCompletionString completionString, uint chunkIndex) +{ + return ClangString(clang_getCompletionChunkText(completionString, chunkIndex)); +} + +QVector CodeCompletionChunkConverter::optionalChunks(CXCompletionString completionString, uint chunkIndex) +{ + CodeCompletionChunkConverter converter; + + converter.extractOptionalCompletionChunks(clang_getCompletionChunkCompletionString(completionString, chunkIndex)); + + return converter.chunks; +} + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/codecompletionchunkconverter.h b/src/tools/clangbackend/ipcsource/codecompletionchunkconverter.h new file mode 100644 index 0000000000..a3b92de62b --- /dev/null +++ b/src/tools/clangbackend/ipcsource/codecompletionchunkconverter.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_CODECOMPLETIONCHUNKCONVERTER_H +#define CLANGBACKEND_CODECOMPLETIONCHUNKCONVERTER_H + +#include + +#include + +#include + +namespace ClangBackEnd { + +class CodeCompletionChunkConverter +{ +public: + static QVector extract(CXCompletionString completionString); + + static Utf8String chunkText(CXCompletionString completionString, uint chunkIndex); + +private: + QVector optionalChunks(CXCompletionString completionString, uint chunkIndex); + static CodeCompletionChunk::Kind chunkKind(CXCompletionString completionString, uint chunkIndex); + void extractCompletionChunks(CXCompletionString completionString); + void extractOptionalCompletionChunks(CXCompletionString completionString); + +private: + QVector chunks; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_CODECOMPLETIONCHUNKCONVERTER_H diff --git a/src/tools/clangbackend/ipcsource/codecompletionsextractor.cpp b/src/tools/clangbackend/ipcsource/codecompletionsextractor.cpp new file mode 100644 index 0000000000..4621cbcf53 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/codecompletionsextractor.cpp @@ -0,0 +1,285 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "codecompletionsextractor.h" + +#include "clangstring.h" +#include "codecompletionchunkconverter.h" + +#ifdef CLANGBACKEND_TESTS +#include +#endif + +#include + +namespace ClangBackEnd { + +CodeCompletionsExtractor::CodeCompletionsExtractor(CXCodeCompleteResults *cxCodeCompleteResults) + : cxCodeCompleteResults(cxCodeCompleteResults) +{ + +} + +bool CodeCompletionsExtractor::next() +{ + const uint cxCodeCompleteResultCount = cxCodeCompleteResults->NumResults; + + ++cxCodeCompleteResultIndex; + + if (cxCodeCompleteResultIndex < cxCodeCompleteResultCount) { + currentCxCodeCompleteResult = cxCodeCompleteResults->Results[cxCodeCompleteResultIndex]; + + currentCodeCompletion_ = CodeCompletion(); + + extractCompletionKind(); + extractText(); + extractPriority(); + extractAvailability(); + extractHasParameters(); + extractCompletionChunks(); + + return true; + } + + return false; +} + +bool CodeCompletionsExtractor::peek(const Utf8String &name) +{ + const uint cxCodeCompleteResultCount = cxCodeCompleteResults->NumResults; + + uint peekCxCodeCompleteResultIndex = cxCodeCompleteResultIndex + 1; + + while (peekCxCodeCompleteResultIndex < cxCodeCompleteResultCount) { + if (hasText(name, cxCodeCompleteResults->Results[peekCxCodeCompleteResultIndex].CompletionString)) + return true; + + ++peekCxCodeCompleteResultIndex; + } + + return false; +} + +QVector CodeCompletionsExtractor::extractAll() +{ + QVector codeCompletions; + + while (next()) + codeCompletions.append(currentCodeCompletion_); + + return codeCompletions; +} + +void CodeCompletionsExtractor::extractCompletionKind() +{ + switch (currentCxCodeCompleteResult.CursorKind) { + case CXCursor_FunctionTemplate: + currentCodeCompletion_.setCompletionKind(CodeCompletion::TemplateFunctionCompletionKind); + break; + case CXCursor_CXXMethod: + extractMethodCompletionKind(); + break; + case CXCursor_FunctionDecl: + currentCodeCompletion_.setCompletionKind(CodeCompletion::FunctionCompletionKind); + break; + case CXCursor_VariableRef: + case CXCursor_VarDecl: + case CXCursor_FieldDecl: + case CXCursor_ParmDecl: + case CXCursor_NonTypeTemplateParameter: + currentCodeCompletion_.setCompletionKind(CodeCompletion::VariableCompletionKind); + break; + case CXCursor_StructDecl: + case CXCursor_UnionDecl: + case CXCursor_ClassDecl: + case CXCursor_TemplateTypeParameter: + currentCodeCompletion_.setCompletionKind(CodeCompletion::ClassCompletionKind); + break; + case CXCursor_ClassTemplatePartialSpecialization: + case CXCursor_ClassTemplate: + case CXCursor_TemplateTemplateParameter: + currentCodeCompletion_.setCompletionKind(CodeCompletion::TemplateClassCompletionKind); + break; + case CXCursor_Namespace: + case CXCursor_NamespaceAlias: + currentCodeCompletion_.setCompletionKind(CodeCompletion::NamespaceCompletionKind); + break; + case CXCursor_EnumDecl: + currentCodeCompletion_.setCompletionKind(CodeCompletion::EnumerationCompletionKind); + break; + case CXCursor_EnumConstantDecl: + currentCodeCompletion_.setCompletionKind(CodeCompletion::EnumeratorCompletionKind); + break; + case CXCursor_Constructor: + currentCodeCompletion_.setCompletionKind(CodeCompletion::ConstructorCompletionKind); + break; + case CXCursor_Destructor: + currentCodeCompletion_.setCompletionKind(CodeCompletion::DestructorCompletionKind); + break; + case CXCursor_MacroDefinition: + extractMacroCompletionKind(); + break; + case CXCursor_NotImplemented: + currentCodeCompletion_.setCompletionKind(CodeCompletion::KeywordCompletionKind); + break; + default: + currentCodeCompletion_.setCompletionKind(CodeCompletion::Other); + } +} + +void CodeCompletionsExtractor::extractText() +{ + const uint completionChunkCount = clang_getNumCompletionChunks(currentCxCodeCompleteResult.CompletionString); + for (uint chunkIndex = 0; chunkIndex < completionChunkCount; ++chunkIndex) { + const CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(currentCxCodeCompleteResult.CompletionString, chunkIndex); + if (chunkKind == CXCompletionChunk_TypedText) { + currentCodeCompletion_.setText(CodeCompletionChunkConverter::chunkText(currentCxCodeCompleteResult.CompletionString, chunkIndex)); + break; + } + } +} + +void CodeCompletionsExtractor::extractMethodCompletionKind() +{ + CXCompletionString cxCompletionString = cxCodeCompleteResults->Results[cxCodeCompleteResultIndex].CompletionString; + const uint annotationCount = clang_getCompletionNumAnnotations(cxCompletionString); + + for (uint annotationIndex = 0; annotationIndex < annotationCount; ++annotationIndex) { + ClangString annotation = clang_getCompletionAnnotation(cxCompletionString, annotationIndex); + + if (annotation == Utf8StringLiteral("qt_signal")) { + currentCodeCompletion_.setCompletionKind(CodeCompletion::SignalCompletionKind); + return; + } + + if (annotation == Utf8StringLiteral("qt_slot")) { + currentCodeCompletion_.setCompletionKind(CodeCompletion::SlotCompletionKind); + return; + } + } + + currentCodeCompletion_.setCompletionKind(CodeCompletion::FunctionCompletionKind); +} + +void CodeCompletionsExtractor::extractMacroCompletionKind() +{ + CXCompletionString cxCompletionString = cxCodeCompleteResults->Results[cxCodeCompleteResultIndex].CompletionString; + + const uint completionChunkCount = clang_getNumCompletionChunks(cxCompletionString); + + for (uint chunkIndex = 0; chunkIndex < completionChunkCount; ++chunkIndex) { + CXCompletionChunkKind kind = clang_getCompletionChunkKind(cxCompletionString, chunkIndex); + if (kind == CXCompletionChunk_Placeholder) { + currentCodeCompletion_.setCompletionKind(CodeCompletion::FunctionCompletionKind); + return; + } + } + + currentCodeCompletion_.setCompletionKind(CodeCompletion::PreProcessorCompletionKind); +} + +void CodeCompletionsExtractor::extractPriority() +{ + CXCompletionString cxCompletionString = cxCodeCompleteResults->Results[cxCodeCompleteResultIndex].CompletionString; + quint32 priority = clang_getCompletionPriority(cxCompletionString); + currentCodeCompletion_.setPriority(priority); +} + +void CodeCompletionsExtractor::extractAvailability() +{ + CXCompletionString cxCompletionString = cxCodeCompleteResults->Results[cxCodeCompleteResultIndex].CompletionString; + CXAvailabilityKind cxAvailabilityKind = clang_getCompletionAvailability(cxCompletionString); + + switch (cxAvailabilityKind) { + case CXAvailability_Available: + currentCodeCompletion_.setAvailability(CodeCompletion::Available); + break; + case CXAvailability_Deprecated: + currentCodeCompletion_.setAvailability(CodeCompletion::Deprecated); + break; + case CXAvailability_NotAvailable: + currentCodeCompletion_.setAvailability(CodeCompletion::NotAvailable); + break; + case CXAvailability_NotAccessible: + currentCodeCompletion_.setAvailability(CodeCompletion::NotAccessible); + break; + } +} + +void CodeCompletionsExtractor::extractHasParameters() +{ + const uint completionChunkCount = clang_getNumCompletionChunks(currentCxCodeCompleteResult.CompletionString); + for (uint chunkIndex = 0; chunkIndex < completionChunkCount; ++chunkIndex) { + const CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(currentCxCodeCompleteResult.CompletionString, chunkIndex); + if (chunkKind == CXCompletionChunk_LeftParen) { + const CXCompletionChunkKind nextChunkKind = clang_getCompletionChunkKind(currentCxCodeCompleteResult.CompletionString, chunkIndex + 1); + currentCodeCompletion_.setHasParameters(nextChunkKind != CXCompletionChunk_RightParen); + return; + } + } +} + +void CodeCompletionsExtractor::extractCompletionChunks() +{ + currentCodeCompletion_.setChunks(CodeCompletionChunkConverter::extract(currentCxCodeCompleteResult.CompletionString)); +} + +bool CodeCompletionsExtractor::hasText(const Utf8String &text, CXCompletionString cxCompletionString) const +{ + const uint completionChunkCount = clang_getNumCompletionChunks(cxCompletionString); + + for (uint chunkIndex = 0; chunkIndex < completionChunkCount; ++chunkIndex) { + const CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(cxCompletionString, chunkIndex); + if (chunkKind == CXCompletionChunk_TypedText) { + const ClangString currentText(clang_getCompletionChunkText(cxCompletionString, chunkIndex)); + return text == currentText; + } + } + + return false; +} + +const CodeCompletion &CodeCompletionsExtractor::currentCodeCompletion() const +{ + return currentCodeCompletion_; +} + +#ifdef CLANGBACKEND_TESTS +void PrintTo(const CodeCompletionsExtractor &extractor, std::ostream *os) +{ + *os << "name: " << ::testing::PrintToString(extractor.currentCodeCompletion().text()) + << ", kind: " << ::testing::PrintToString(extractor.currentCodeCompletion().completionKind()) + << ", priority: " << extractor.currentCodeCompletion().priority() + << ", kind: " << ::testing::PrintToString(extractor.currentCodeCompletion().availability()); +} +#endif + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/codecompletionsextractor.h b/src/tools/clangbackend/ipcsource/codecompletionsextractor.h new file mode 100644 index 0000000000..efeae11485 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/codecompletionsextractor.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_CODECOMPLETIONSEXTRACTOR_H +#define CLANGBACKEND_CODECOMPLETIONSEXTRACTOR_H + +#include + +#include + +#include + +namespace ClangBackEnd { + +class CodeCompletionsExtractor +{ +public: + CodeCompletionsExtractor(CXCodeCompleteResults *cxCodeCompleteResults); + + CodeCompletionsExtractor(CodeCompletionsExtractor&) = delete; + CodeCompletionsExtractor &operator=(CodeCompletionsExtractor&) = delete; + + CodeCompletionsExtractor(CodeCompletionsExtractor&&) = delete; + CodeCompletionsExtractor &operator=(CodeCompletionsExtractor&&) = delete; + + bool next(); + bool peek(const Utf8String &name); + + QVector extractAll(); + + const CodeCompletion ¤tCodeCompletion() const; + +private: + void extractCompletionKind(); + void extractText(); + void extractMethodCompletionKind(); + void extractMacroCompletionKind(); + void extractPriority(); + void extractAvailability(); + void extractHasParameters(); + void extractCompletionChunks(); + + bool hasText(const Utf8String &text, CXCompletionString cxCompletionString) const; + +private: + CodeCompletion currentCodeCompletion_; + CXCompletionResult currentCxCodeCompleteResult; + CXCodeCompleteResults *cxCodeCompleteResults; + uint cxCodeCompleteResultIndex = -1; +}; + +#ifdef CLANGBACKEND_TESTS +void PrintTo(const CodeCompletionsExtractor &extractor, ::std::ostream* os); +#endif +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_CODECOMPLETIONSEXTRACTOR_H diff --git a/src/tools/clangbackend/ipcsource/projectpart.cpp b/src/tools/clangbackend/ipcsource/projectpart.cpp new file mode 100644 index 0000000000..24828cc965 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/projectpart.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "projectpart.h" + +#include + +#include + +#include + +namespace ClangBackEnd { + +class ProjectPartData { +public: + ProjectPartData(const Utf8String &projectPartId); + ~ProjectPartData(); + +public: + void clearArguments(); + +public: + time_point lastChangeTimePoint; + std::vector arguments; + Utf8String projectPartId; +}; + +void ProjectPartData::clearArguments() +{ + for (auto argument : arguments) + delete [] argument; + + arguments.clear(); +} + +ProjectPartData::ProjectPartData(const Utf8String &projectPartId) + : lastChangeTimePoint(std::chrono::steady_clock::now()), + projectPartId(projectPartId) +{ +} + +ProjectPartData::~ProjectPartData() +{ + clearArguments(); +} + +ProjectPart::ProjectPart(const Utf8String &projectPartId) + : d(std::make_shared(projectPartId)) +{ +} + +ProjectPart::ProjectPart(const ProjectPartContainer &projectContainer) + : d(std::make_shared(projectContainer.projectPartId())) +{ + setArguments(projectContainer.arguments()); +} + +ProjectPart::~ProjectPart() = default; +ProjectPart::ProjectPart(const ProjectPart &) = default; +ProjectPart &ProjectPart::operator=(const ProjectPart &) = default; + +ProjectPart::ProjectPart(ProjectPart &&other) + : d(std::move(other.d)) +{ +} + +ProjectPart &ProjectPart::operator=(ProjectPart &&other) +{ + d = std::move(other.d); + + return *this; +} + +void ProjectPart::clearProjectPartId() +{ + d->projectPartId.clear(); +} + +const Utf8String &ProjectPart::projectPartId() const +{ + return d->projectPartId; +} + +static const char *strdup(const Utf8String &utf8String) +{ + char *cxArgument = new char[utf8String.byteSize() + 1]; + std::memcpy(cxArgument, utf8String.constData(), utf8String.byteSize() + 1); + + return cxArgument; +} + +void ProjectPart::setArguments(const Utf8StringVector &arguments) +{ + d->clearArguments(); + d->arguments.resize(arguments.size()); + std::transform(arguments.cbegin(), arguments.cend(), d->arguments.begin(), strdup); + updateLastChangeTimePoint(); +} + +const std::vector &ProjectPart::arguments() const +{ + return d->arguments; +} + +int ProjectPart::argumentCount() const +{ + return d->arguments.size(); +} + +const char * const *ProjectPart::cxArguments() const +{ + return arguments().data(); +} + +const time_point &ProjectPart::lastChangeTimePoint() const +{ + return d->lastChangeTimePoint; +} + +void ProjectPart::updateLastChangeTimePoint() +{ + d->lastChangeTimePoint = std::chrono::steady_clock::now(); +} + +bool operator==(const ProjectPart &first, const ProjectPart &second) +{ + return first.projectPartId() == second.projectPartId(); +} + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/projectpart.h b/src/tools/clangbackend/ipcsource/projectpart.h new file mode 100644 index 0000000000..3b5419986b --- /dev/null +++ b/src/tools/clangbackend/ipcsource/projectpart.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_PROJECT_H +#define CLANGBACKEND_PROJECT_H + +#include +#include +#include + +class Utf8String; +class Utf8StringVector; + +namespace ClangBackEnd { + +class ProjectPartContainer; +class ProjectPartData; + +using time_point = std::chrono::steady_clock::time_point; + +class ProjectPart +{ +public: + ProjectPart(const Utf8String &projectPartId); + ProjectPart(const ProjectPartContainer &projectContainer); + ~ProjectPart(); + + ProjectPart(const ProjectPart &project); + ProjectPart &operator=(const ProjectPart &project); + + ProjectPart(ProjectPart &&project); + ProjectPart &operator=(ProjectPart &&project); + + void clearProjectPartId(); + + const Utf8String &projectPartId() const; + + void setArguments(const Utf8StringVector &arguments_); + + const std::vector &arguments() const; + + int argumentCount() const; + const char *const *cxArguments() const; + + const time_point &lastChangeTimePoint() const; + +private: + void updateLastChangeTimePoint(); + +private: + std::shared_ptr d; +}; + +bool operator==(const ProjectPart &first, const ProjectPart &second); + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_PROJECT_H diff --git a/src/tools/clangbackend/ipcsource/projectpartsdonotexistexception.cpp b/src/tools/clangbackend/ipcsource/projectpartsdonotexistexception.cpp new file mode 100644 index 0000000000..4bdeea9bbf --- /dev/null +++ b/src/tools/clangbackend/ipcsource/projectpartsdonotexistexception.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "projectpartsdonotexistexception.h" + +namespace ClangBackEnd { + +ProjectPartDoNotExistException::ProjectPartDoNotExistException(const Utf8StringVector &projectPartIds) + : projectPartIds_(projectPartIds) +{ +} + +const Utf8StringVector &ProjectPartDoNotExistException::projectPartIds() const +{ + return projectPartIds_; +} + +const char *ProjectPartDoNotExistException::what() const Q_DECL_NOEXCEPT +{ + if (what_.isEmpty()) + what_ += Utf8StringLiteral("ProjectPart files ") + + projectPartIds().join(Utf8StringLiteral(", ")) + + Utf8StringLiteral(" does not exist!"); + + return what_.constData(); +} + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/projectpartsdonotexistexception.h b/src/tools/clangbackend/ipcsource/projectpartsdonotexistexception.h new file mode 100644 index 0000000000..da10dba890 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/projectpartsdonotexistexception.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_PROJECTDONOTEXISTSEXCEPTION_H +#define CLANGBACKEND_PROJECTDONOTEXISTSEXCEPTION_H + +#include + +#include + +namespace ClangBackEnd { + +class ProjectPartDoNotExistException : public std::exception +{ +public: + ProjectPartDoNotExistException(const Utf8StringVector &projectPartIds); + + const Utf8StringVector &projectPartIds() const; + + const char *what() const Q_DECL_NOEXCEPT override; + +#if defined(__GNUC__) && !defined(__clang__) +# if !__GNUC_PREREQ(4,8) + ~ProjectPartDoNotExistException() noexcept {} +# endif +#endif + +private: + Utf8StringVector projectPartIds_; + mutable Utf8String what_; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_PROJECTDONOTEXISTSEXCEPTION_H diff --git a/src/tools/clangbackend/ipcsource/projects.cpp b/src/tools/clangbackend/ipcsource/projects.cpp new file mode 100644 index 0000000000..cd6d4d0488 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/projects.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "projects.h" + +#include + +#include "projectpartsdonotexistexception.h" + +namespace ClangBackEnd { + +void ProjectParts::createOrUpdate(const QVector &projectContainers) +{ + for (const ProjectPartContainer &projectContainer : projectContainers) + createOrUpdateProjectPart(projectContainer); +} + +void ProjectParts::remove(const Utf8StringVector &projectPartIds) +{ + Utf8StringVector processedProjectPartFilePaths = projectPartIds; + + auto removeBeginIterator = std::remove_if(projects_.begin(), projects_.end(), [&processedProjectPartFilePaths] (const ProjectPart &project) { + return processedProjectPartFilePaths.removeFast(project.projectPartId()); + }); + + std::for_each(removeBeginIterator, projects_.end(), [](ProjectPart &project) { project.clearProjectPartId(); }); + projects_.erase(removeBeginIterator, projects_.end()); + + if (!processedProjectPartFilePaths.isEmpty()) + throw ProjectPartDoNotExistException(processedProjectPartFilePaths); +} + +bool ProjectParts::hasProjectPart(const Utf8String &projectPartId) const +{ + return findProjectPart(projectPartId) != projects_.cend(); +} + +const ProjectPart &ProjectParts::project(const Utf8String &projectPartId) const +{ + const auto findIterator = findProjectPart(projectPartId); + + if (findIterator == projects_.cend()) + throw ProjectPartDoNotExistException({projectPartId}); + + return *findIterator; +} + +std::vector::const_iterator ProjectParts::findProjectPart(const Utf8String &projectPartId) const +{ + return std::find_if(projects_.begin(), projects_.end(), [projectPartId] (const ProjectPart &project) { + return project.projectPartId() == projectPartId; + }); +} + +std::vector::iterator ProjectParts::findProjectPart(const Utf8String &projectPartId) +{ + return std::find_if(projects_.begin(), projects_.end(), [projectPartId] (const ProjectPart &project) { + return project.projectPartId() == projectPartId; + }); +} + +const std::vector &ProjectParts::projects() const +{ + return projects_; +} + +void ProjectParts::createOrUpdateProjectPart(const ProjectPartContainer &projectContainer) +{ + auto findIterator = findProjectPart(projectContainer.projectPartId()); + if (findIterator == projects_.cend()) + projects_.push_back(ProjectPart(projectContainer)); + else + findIterator->setArguments(projectContainer.arguments()); +} + + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/projects.h b/src/tools/clangbackend/ipcsource/projects.h new file mode 100644 index 0000000000..1058036566 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/projects.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_PROJECTS_H +#define CLANGBACKEND_PROJECTS_H + +#include + +#include "projectpart.h" + +#include + +namespace ClangBackEnd { + +class ProjectParts +{ +public: + void createOrUpdate(const QVector &projectConainers); + void remove(const Utf8StringVector &projectPartIds); + + bool hasProjectPart(const Utf8String &projectPartId) const; + + const ProjectPart &project(const Utf8String &projectPartId) const; + + std::vector::const_iterator findProjectPart(const Utf8String &projectPartId) const; + std::vector::iterator findProjectPart(const Utf8String &projectPartId); + + const std::vector &projects() const; + +private: + void createOrUpdateProjectPart(const ProjectPartContainer &projectConainer); + +private: + std::vector projects_; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_PROJECTS_H diff --git a/src/tools/clangbackend/ipcsource/translationunit.cpp b/src/tools/clangbackend/ipcsource/translationunit.cpp new file mode 100644 index 0000000000..63e173b342 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunit.cpp @@ -0,0 +1,230 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "translationunit.h" + +#include + +#include + +#include "codecompleter.h" + +#include "translationunitisnullexception.h" +#include "translationunitfilenotexitexception.h" +#include "translationunitparseerrorexception.h" +#include "unsavedfiles.h" +#include "projectpart.h" + +namespace ClangBackEnd { + +class TranslationUnitData +{ +public: + TranslationUnitData(const Utf8String &filePath, + const UnsavedFiles &unsavedFiles, + const ProjectPart &projectPart); + ~TranslationUnitData(); + +public: + time_point lastChangeTimePoint; + ProjectPart projectPart; + Utf8String filePath; + CXTranslationUnit translationUnit = nullptr; + CXIndex index = nullptr; + UnsavedFiles unsavedFiles; +}; + +TranslationUnitData::TranslationUnitData(const Utf8String &filePath, + const UnsavedFiles &unsavedFiles, + const ProjectPart &projectPart) + : lastChangeTimePoint(std::chrono::steady_clock::now()), + projectPart(projectPart), + filePath(filePath), + unsavedFiles(unsavedFiles) +{ +} + +TranslationUnitData::~TranslationUnitData() +{ + clang_disposeTranslationUnit(translationUnit); + clang_disposeIndex(index); +} + +TranslationUnit::TranslationUnit(const Utf8String &filePath, + const UnsavedFiles &unsavedFiles, + const ProjectPart &project, + FileExistsCheck fileExistsCheck) + : d(std::make_shared(filePath, unsavedFiles, project)) +{ + if (fileExistsCheck == CheckIfFileExists) + checkIfFileExists(); +} + +bool TranslationUnit::isNull() const +{ + return !d; +} + +void TranslationUnit::reset() +{ + d.reset(); +} + +CXIndex TranslationUnit::index() const +{ + checkIfNull(); + + if (!d->index) + d->index = clang_createIndex(1, 1); + + return d->index; +} + +CXTranslationUnit TranslationUnit::cxTranslationUnit() const +{ + checkIfNull(); + + removeOutdatedTranslationUnit(); + + createTranslationUnitIfNeeded(); + + return d->translationUnit; +} + +const Utf8String &TranslationUnit::filePath() const +{ + checkIfNull(); + + return d->filePath; +} + +const Utf8String &TranslationUnit::projectPartId() const +{ + checkIfNull(); + + return d->projectPart.projectPartId(); +} + +const time_point &TranslationUnit::lastChangeTimePoint() const +{ + return d->lastChangeTimePoint; +} + +void TranslationUnit::checkIfNull() const +{ + if (isNull()) + throw TranslationUnitIsNullException(); +} + +void TranslationUnit::checkIfFileExists() const +{ + if (!QFileInfo::exists(d->filePath.toString())) + throw TranslationUnitFileNotExitsException(d->filePath); +} + +void TranslationUnit::updateLastChangeTimePoint() const +{ + d->lastChangeTimePoint = std::chrono::steady_clock::now(); +} + +void TranslationUnit::removeOutdatedTranslationUnit() const +{ + if (d->projectPart.lastChangeTimePoint() >= d->lastChangeTimePoint) { + clang_disposeTranslationUnit(d->translationUnit); + d->translationUnit = nullptr; + } +} + +void TranslationUnit::createTranslationUnitIfNeeded() const +{ + const auto options = CXTranslationUnit_DetailedPreprocessingRecord + | CXTranslationUnit_CacheCompletionResults + | CXTranslationUnit_PrecompiledPreamble + | CXTranslationUnit_SkipFunctionBodies; + + if (!d->translationUnit) { + d->translationUnit = CXTranslationUnit(); + CXErrorCode errorCode = clang_parseTranslationUnit2(index(), + d->filePath.constData(), + d->projectPart.cxArguments(), + d->projectPart.argumentCount(), + d->unsavedFiles.cxUnsavedFiles(), + d->unsavedFiles.count(), + options, + &d->translationUnit); + + checkTranslationUnitErrorCode(errorCode); + + updateLastChangeTimePoint(); + } +} + +void TranslationUnit::checkTranslationUnitErrorCode(CXErrorCode errorCode) const +{ + switch (errorCode) { + case CXError_Success: break; + default: throw TranslationUnitParseErrorException(d->filePath, d->projectPart.projectPartId()); + } +} + +uint TranslationUnit::unsavedFilesCount() const +{ + return d->unsavedFiles.count(); +} + +CXUnsavedFile *TranslationUnit::cxUnsavedFiles() const +{ + return d->unsavedFiles.cxUnsavedFiles(); +} + +TranslationUnit::~TranslationUnit() = default; + +TranslationUnit::TranslationUnit(const TranslationUnit &) = default; +TranslationUnit &TranslationUnit::operator=(const TranslationUnit &) = default; + +TranslationUnit::TranslationUnit(TranslationUnit &&other) + : d(std::move(other.d)) +{ +} + +TranslationUnit &TranslationUnit::operator=(TranslationUnit &&other) +{ + d = std::move(other.d); + + return *this; +} + +bool operator==(const TranslationUnit &first, const TranslationUnit &second) +{ + return first.filePath() == second.filePath() && first.projectPartId() == second.projectPartId(); +} + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/translationunit.h b/src/tools/clangbackend/ipcsource/translationunit.h new file mode 100644 index 0000000000..5f7bc475d7 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunit.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_TRANSLATIONUNIT_H +#define CLANGBACKEND_TRANSLATIONUNIT_H + +#include + +#include +#include + +#include + +class Utf8String; + +namespace ClangBackEnd { + +class TranslationUnitData; +class CodeCompleter; +class UnsavedFiles; +class ProjectPart; + +using time_point = std::chrono::steady_clock::time_point; + +class TranslationUnit +{ +public: + enum FileExistsCheck { + CheckIfFileExists, + DoNotCheckIfFileExists + }; + + TranslationUnit() = default; + TranslationUnit(const Utf8String &filePath, + const UnsavedFiles &unsavedFiles, + const ProjectPart &projectPart, + FileExistsCheck fileExistsCheck = CheckIfFileExists); + ~TranslationUnit(); + + TranslationUnit(const TranslationUnit &cxTranslationUnit); + TranslationUnit &operator=(const TranslationUnit &cxTranslationUnit); + + TranslationUnit(TranslationUnit &&cxTranslationUnit); + TranslationUnit &operator=(TranslationUnit &&cxTranslationUnit); + + bool isNull() const; + + void reset(); + + CXIndex index() const; + CXTranslationUnit cxTranslationUnit() const; + CXUnsavedFile * cxUnsavedFiles() const; + uint unsavedFilesCount() const; + + const Utf8String &filePath() const; + const Utf8String &projectPartId() const; + + const time_point &lastChangeTimePoint() const; + +private: + void checkIfNull() const; + void checkIfFileExists() const; + void updateLastChangeTimePoint() const; + void removeOutdatedTranslationUnit() const; + void createTranslationUnitIfNeeded() const; + void checkTranslationUnitErrorCode(CXErrorCode errorCode) const; + +private: + mutable std::shared_ptr d; +}; + +bool operator==(const TranslationUnit &first, const TranslationUnit &second); + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_TRANSLATIONUNIT_H diff --git a/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.cpp b/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.cpp new file mode 100644 index 0000000000..e06bb85f3f --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "translationunitdoesnotexistexception.h" + +namespace ClangBackEnd { + +TranslationUnitDoesNotExistException::TranslationUnitDoesNotExistException(const FileContainer &fileContainer) + : fileContainer_(fileContainer) +{ +} + +TranslationUnitDoesNotExistException::TranslationUnitDoesNotExistException(const Utf8String filePath, const Utf8String projectPartId) + : fileContainer_(filePath, projectPartId) +{ +} + +const FileContainer &TranslationUnitDoesNotExistException::fileContainer() const +{ + return fileContainer_; +} + +const char *TranslationUnitDoesNotExistException::what() const Q_DECL_NOEXCEPT +{ + if (what_.isEmpty()) + what_ += Utf8StringLiteral("Parse error for file ") + + fileContainer_.filePath() + + Utf8StringLiteral(" in project ") + + fileContainer_.projectPartId() + + Utf8StringLiteral("!"); + + return what_.constData(); +} + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.h b/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.h new file mode 100644 index 0000000000..c4b539bc92 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_TRANSLATIONUNITDONOTEXISTS_H +#define CLANGBACKEND_TRANSLATIONUNITDONOTEXISTS_H + +#include + +namespace ClangBackEnd { + +class TranslationUnitDoesNotExistException : public std::exception +{ +public: + TranslationUnitDoesNotExistException(const FileContainer &fileContainer); + TranslationUnitDoesNotExistException(const Utf8String filePath, const Utf8String projectPartId); + + const FileContainer &fileContainer() const; + + const char *what() const Q_DECL_NOEXCEPT override; + +#if defined(__GNUC__) && !defined(__clang__) +# if !__GNUC_PREREQ(4,8) + ~TranslationUnitDoesNotExistException() noexcept {} +# endif +#endif + +private: + FileContainer fileContainer_; + mutable Utf8String what_; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_TRANSLATIONUNITDONOTEXISTS_H diff --git a/src/tools/clangbackend/ipcsource/translationunitfilenotexitexception.cpp b/src/tools/clangbackend/ipcsource/translationunitfilenotexitexception.cpp new file mode 100644 index 0000000000..1a94d612d9 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunitfilenotexitexception.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "translationunitfilenotexitexception.h" + +namespace ClangBackEnd { + +TranslationUnitFileNotExitsException::TranslationUnitFileNotExitsException(const Utf8String &filePath) + : filePath_(filePath) +{ +} + +const Utf8String &TranslationUnitFileNotExitsException::filePath() const +{ + return filePath_; +} + +const char *TranslationUnitFileNotExitsException::what() const Q_DECL_NOEXCEPT +{ + if (what_.isEmpty()) + what_ += Utf8StringLiteral("File ") + + filePath() + + Utf8StringLiteral(" in project does not exist!"); + + return what_.constData(); +} + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/translationunitfilenotexitexception.h b/src/tools/clangbackend/ipcsource/translationunitfilenotexitexception.h new file mode 100644 index 0000000000..7bef6092f8 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunitfilenotexitexception.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_TRANSLATIONUNITFILENOTEXITS_H +#define CLANGBACKEND_TRANSLATIONUNITFILENOTEXITS_H + +#include + +#include + +namespace ClangBackEnd { + +class TranslationUnitFileNotExitsException : public std::exception +{ +public: + TranslationUnitFileNotExitsException(const Utf8String &filePath); + + const Utf8String &filePath() const; + + const char *what() const Q_DECL_NOEXCEPT override; + +#if defined(__GNUC__) && !defined(__clang__) +# if !__GNUC_PREREQ(4,8) + ~TranslationUnitFileNotExitsException() noexcept {} +# endif +#endif + +private: + Utf8String filePath_; + mutable Utf8String what_; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_TRANSLATIONUNITFILENOTEXITS_H diff --git a/src/tools/clangbackend/ipcsource/translationunitisnullexception.cpp b/src/tools/clangbackend/ipcsource/translationunitisnullexception.cpp new file mode 100644 index 0000000000..2afd8896f7 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunitisnullexception.cpp @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "translationunitisnullexception.h" + +namespace ClangBackEnd { + +const char *TranslationUnitIsNullException::what() const Q_DECL_NOEXCEPT +{ + return "Tried to access a null TranslationUnit!"; +} + + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/translationunitisnullexception.h b/src/tools/clangbackend/ipcsource/translationunitisnullexception.h new file mode 100644 index 0000000000..d92e22b5c4 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunitisnullexception.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_TRANSLATIONUNITISNULLEXCEPTION_H +#define CLANGBACKEND_TRANSLATIONUNITISNULLEXCEPTION_H + +#include + +#include + +namespace ClangBackEnd { + +class TranslationUnitIsNullException : public std::exception +{ +public: + const char *what() const Q_DECL_NOEXCEPT override; + +#if defined(__GNUC__) && !defined(__clang__) +# if !__GNUC_PREREQ(4,8) + ~TranslationUnitIsNullException() noexcept {} +# endif +#endif +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_TRANSLATIONUNITISNULLEXCEPTION_H diff --git a/src/tools/clangbackend/ipcsource/translationunitparseerrorexception.cpp b/src/tools/clangbackend/ipcsource/translationunitparseerrorexception.cpp new file mode 100644 index 0000000000..c4a5b9389f --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunitparseerrorexception.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "translationunitparseerrorexception.h" + + + +namespace ClangBackEnd { + +TranslationUnitParseErrorException::TranslationUnitParseErrorException(const Utf8String &filePath, const Utf8String &projectPartId) + : filePath_(filePath), + projectPartId_(projectPartId) +{ +} + +const Utf8String &TranslationUnitParseErrorException::filePath() const +{ + return filePath_; +} + +const Utf8String &TranslationUnitParseErrorException::projectPartId() const +{ + return projectPartId_; +} + +const char *TranslationUnitParseErrorException::what() const Q_DECL_NOEXCEPT +{ + if (what_.isEmpty()) + what_ += Utf8StringLiteral("Parse error for file ") + + filePath() + + Utf8StringLiteral(" in project ") + + projectPartId() + + Utf8StringLiteral("!"); + + return what_.constData(); +} + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/translationunitparseerrorexception.h b/src/tools/clangbackend/ipcsource/translationunitparseerrorexception.h new file mode 100644 index 0000000000..1b36b5a14e --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunitparseerrorexception.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_TRANSLATIONUNITPARSEERROREXCEPTION_H +#define CLANGBACKEND_TRANSLATIONUNITPARSEERROREXCEPTION_H + +#include + +#include + +namespace ClangBackEnd { + +class TranslationUnitParseErrorException : public std::exception +{ +public: + TranslationUnitParseErrorException(const Utf8String &filePath, const Utf8String &projectPartId); + + const Utf8String &filePath() const; + const Utf8String &projectPartId() const; + + const char *what() const Q_DECL_NOEXCEPT override; + +#if defined(__GNUC__) && !defined(__clang__) +# if !__GNUC_PREREQ(4,8) + ~TranslationUnitParseErrorException() noexcept {} +# endif +#endif + +private: + Utf8String filePath_; + Utf8String projectPartId_; + mutable Utf8String what_; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_TRANSLATIONUNITPARSEERROREXCEPTION_H diff --git a/src/tools/clangbackend/ipcsource/translationunits.cpp b/src/tools/clangbackend/ipcsource/translationunits.cpp new file mode 100644 index 0000000000..a9eb585bc4 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunits.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "translationunits.h" + +#include +#include +#include + +namespace ClangBackEnd { + +bool operator==(const FileContainer &fileContainer, const TranslationUnit &translationUnit) +{ + return fileContainer.filePath() == translationUnit.filePath() && fileContainer.projectPartId() == translationUnit.projectPartId(); +} + +bool operator==(const TranslationUnit &translationUnit, const FileContainer &fileContainer) +{ + return fileContainer == translationUnit; +} + + +TranslationUnits::TranslationUnits(ProjectParts &projects, UnsavedFiles &unsavedFiles) + : projects(projects), + unsavedFiles(unsavedFiles) +{ +} + +void TranslationUnits::createOrUpdate(const QVector &fileContainers) +{ + for (const FileContainer &fileContainer : fileContainers) + createOrUpdateTranslationUnit(fileContainer); +} + +static bool removeFromFileContainer(QVector &fileContainers, const TranslationUnit &translationUnit) +{ + auto position = std::remove(fileContainers.begin(), fileContainers.end(), translationUnit); + + bool entryIsRemoved = position != fileContainers.end(); + + fileContainers.erase(position, fileContainers.end()); + + return entryIsRemoved; +} + + +void TranslationUnits::remove(const QVector &fileContainers) +{ + checkIfProjectPartsExists(fileContainers); + + QVector processedFileContainers = fileContainers; + + auto removeBeginIterator = std::remove_if(translationUnits_.begin(), translationUnits_.end(), [&processedFileContainers] (const TranslationUnit &translationUnit) { + return removeFromFileContainer(processedFileContainers, translationUnit); + }); + + translationUnits_.erase(removeBeginIterator, translationUnits_.end()); + + if (!processedFileContainers.isEmpty()) + throw TranslationUnitDoesNotExistException(processedFileContainers.first()); + +} + +const TranslationUnit &TranslationUnits::translationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const +{ + checkIfProjectPartExists(projectPartId); + + auto findIterator = findTranslationUnit(filePath, projectPartId); + + if (findIterator == translationUnits_.end()) + throw TranslationUnitDoesNotExistException(FileContainer(filePath, projectPartId)); + + return *findIterator; +} + +const std::vector &TranslationUnits::translationUnits() const +{ + return translationUnits_; +} + +void TranslationUnits::createOrUpdateTranslationUnit(const FileContainer &fileContainer) +{ + TranslationUnit::FileExistsCheck checkIfFileExists = fileContainer.hasUnsavedFileContent() ? TranslationUnit::DoNotCheckIfFileExists : TranslationUnit::CheckIfFileExists; + auto findIterator = findTranslationUnit(fileContainer); + if (findIterator == translationUnits_.end()) + translationUnits_.push_back(TranslationUnit(fileContainer.filePath(), + unsavedFiles, + projects.project(fileContainer.projectPartId()), + checkIfFileExists)); +} + +std::vector::iterator TranslationUnits::findTranslationUnit(const FileContainer &fileContainer) +{ + return std::find(translationUnits_.begin(), translationUnits_.end(), fileContainer); +} + +std::vector::const_iterator TranslationUnits::findTranslationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const +{ + FileContainer fileContainer(filePath, projectPartId); + return std::find(translationUnits_.begin(), translationUnits_.end(), fileContainer); +} + +void TranslationUnits::checkIfProjectPartExists(const Utf8String &projectFileName) const +{ + projects.project(projectFileName); +} + +void TranslationUnits::checkIfProjectPartsExists(const QVector &fileContainers) const +{ + Utf8StringVector notExistingProjectParts; + + for (const FileContainer &fileContainer : fileContainers) { + if (!projects.hasProjectPart(fileContainer.projectPartId())) + notExistingProjectParts.push_back(fileContainer.projectPartId()); + } + + if (!notExistingProjectParts.isEmpty()) + throw ProjectPartDoNotExistException(notExistingProjectParts); + +} + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/translationunits.h b/src/tools/clangbackend/ipcsource/translationunits.h new file mode 100644 index 0000000000..9a1478ad3b --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunits.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_TRANSLATIONUNITS_H +#define CLANGBACKEND_TRANSLATIONUNITS_H + +#include +#include + +#include + +#include "translationunit.h" + +namespace ClangBackEnd { + +class ProjectParts; +class UnsavedFiles; + +class TranslationUnits +{ +public: + TranslationUnits(ProjectParts &projects, UnsavedFiles &unsavedFiles); + + void createOrUpdate(const QVector &fileContainers); + void remove(const QVector &fileContainers); + + const TranslationUnit &translationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const; + + const std::vector &translationUnits() const; + +private: + void createOrUpdateTranslationUnit(const FileContainer &fileContainer); + std::vector::iterator findTranslationUnit(const FileContainer &fileContainer); + std::vector::const_iterator findTranslationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const; + void checkIfProjectPartExists(const Utf8String &projectFileName) const; + void checkIfProjectPartsExists(const QVector &fileContainers) const; + + +private: + std::vector translationUnits_; + ProjectParts &projects; + UnsavedFiles &unsavedFiles; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_TRANSLATIONUNITS_H diff --git a/src/tools/clangbackend/ipcsource/unsavedfiles.cpp b/src/tools/clangbackend/ipcsource/unsavedfiles.cpp new file mode 100644 index 0000000000..5e9c0f99df --- /dev/null +++ b/src/tools/clangbackend/ipcsource/unsavedfiles.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "unsavedfiles.h" + + +#include + +namespace ClangBackEnd { + +class UnsavedFilesData +{ +public: + UnsavedFilesData(); + ~UnsavedFilesData(); + +public: + time_point lastChangeTimePoint; + std::vector cxUnsavedFiles; +}; + +UnsavedFilesData::UnsavedFilesData() + : lastChangeTimePoint(std::chrono::steady_clock::now()) +{ +} + +UnsavedFilesData::~UnsavedFilesData() +{ + for (const CXUnsavedFile &cxUnsavedFile : cxUnsavedFiles) + UnsavedFiles::deleteCXUnsavedFile(cxUnsavedFile); + + cxUnsavedFiles.clear(); +} + +UnsavedFiles::UnsavedFiles() + : d(std::make_shared()) +{ +} + +UnsavedFiles::~UnsavedFiles() = default; + +UnsavedFiles::UnsavedFiles(const UnsavedFiles &) = default; +UnsavedFiles &UnsavedFiles::operator=(const UnsavedFiles &) = default; + +UnsavedFiles::UnsavedFiles(UnsavedFiles &&other) + : d(std::move(other.d)) +{ +} + +UnsavedFiles &UnsavedFiles::operator=(UnsavedFiles &&other) +{ + d = std::move(other.d); + + return *this; +} + +void UnsavedFiles::createOrUpdate(const QVector &fileContainers) +{ + for (const FileContainer &fileContainer : fileContainers) + updateCXUnsavedFileWithFileContainer(fileContainer); + + updateLastChangeTimePoint(); +} + +void UnsavedFiles::remove(const QVector &fileContainers) +{ + for (const FileContainer &fileContainer : fileContainers) + removeCXUnsavedFile(fileContainer); + + updateLastChangeTimePoint(); +} + +void UnsavedFiles::clear() +{ + for (const CXUnsavedFile &cxUnsavedFile : d->cxUnsavedFiles) + deleteCXUnsavedFile(cxUnsavedFile); + + d->cxUnsavedFiles.clear(); + updateLastChangeTimePoint(); +} + +int UnsavedFiles::count() const +{ + return d->cxUnsavedFiles.size(); +} + +CXUnsavedFile *UnsavedFiles::cxUnsavedFiles() const +{ + return d->cxUnsavedFiles.data(); +} + +const std::vector &UnsavedFiles::cxUnsavedFileVector() const +{ + return d->cxUnsavedFiles; +} + +const time_point &UnsavedFiles::lastChangeTimePoint() const +{ + return d->lastChangeTimePoint; +} + +CXUnsavedFile UnsavedFiles::createCxUnsavedFile(const Utf8String &filePath, const Utf8String &fileContent) +{ + char *cxUnsavedFilePath = new char[filePath.byteSize() + 1]; + char *cxUnsavedFileContent = new char[fileContent.byteSize() + 1]; + + std::memcpy(cxUnsavedFilePath, filePath.constData(), filePath.byteSize() + 1); + std::memcpy(cxUnsavedFileContent, fileContent.constData(), fileContent.byteSize() + 1); + + return CXUnsavedFile { cxUnsavedFilePath, cxUnsavedFileContent, ulong(fileContent.byteSize())}; +} + +void UnsavedFiles::deleteCXUnsavedFile(const CXUnsavedFile &cxUnsavedFile) +{ + delete [] cxUnsavedFile.Contents; + delete [] cxUnsavedFile.Filename; +} + +void UnsavedFiles::updateCXUnsavedFileWithFileContainer(const FileContainer &fileContainer) +{ + if (fileContainer.hasUnsavedFileContent()) { + addOrUpdateCXUnsavedFile(fileContainer); + } else { + removeCXUnsavedFile(fileContainer); + } +} + +void UnsavedFiles::removeCXUnsavedFile(const FileContainer &fileContainer) +{ + const Utf8String filePath = fileContainer.filePath(); + auto removeBeginIterator = std::remove_if(d->cxUnsavedFiles.begin(), + d->cxUnsavedFiles.end(), + [filePath] (const CXUnsavedFile &cxUnsavedFile) { return filePath == cxUnsavedFile.Filename; }); + + std::for_each(removeBeginIterator, d->cxUnsavedFiles.end(), UnsavedFiles::deleteCXUnsavedFile); + d->cxUnsavedFiles.erase( removeBeginIterator, d->cxUnsavedFiles.end()); +} + +void UnsavedFiles::addOrUpdateCXUnsavedFile(const FileContainer &fileContainer) +{ + const Utf8String filePath = fileContainer.filePath(); + const Utf8String fileContent = fileContainer.unsavedFileContent(); + auto isSameFile = [filePath] (const CXUnsavedFile &cxUnsavedFile) { return filePath == cxUnsavedFile.Filename; }; + + auto cxUnsavedFileIterator = std::find_if(d->cxUnsavedFiles.begin(), d->cxUnsavedFiles.end(), isSameFile); + if (cxUnsavedFileIterator == d->cxUnsavedFiles.end()) + d->cxUnsavedFiles.push_back(createCxUnsavedFile(filePath, fileContent)); + else { + deleteCXUnsavedFile(*cxUnsavedFileIterator); + *cxUnsavedFileIterator = createCxUnsavedFile(filePath, fileContent); + } +} + +void UnsavedFiles::updateLastChangeTimePoint() +{ + d->lastChangeTimePoint = std::chrono::steady_clock::now(); +} + + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/unsavedfiles.h b/src/tools/clangbackend/ipcsource/unsavedfiles.h new file mode 100644 index 0000000000..b1cc55440c --- /dev/null +++ b/src/tools/clangbackend/ipcsource/unsavedfiles.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_UNSAVEDFILES_H +#define CLANGBACKEND_UNSAVEDFILES_H + +#include + +#include +#include +#include + +#include + +#include + +namespace ClangBackEnd { + +using time_point = std::chrono::steady_clock::time_point; + +class UnsavedFilesData; + +class UnsavedFiles +{ + friend class UnsavedFilesData; +public: + UnsavedFiles(); + ~UnsavedFiles(); + + UnsavedFiles(const UnsavedFiles &unsavedFiles); + UnsavedFiles &operator=(const UnsavedFiles &unsavedFiles); + + UnsavedFiles(UnsavedFiles &&unsavedFiles); + UnsavedFiles &operator=(UnsavedFiles &&unsavedFiles); + + void createOrUpdate(const QVector &fileContainers); + void remove(const QVector &fileContainers); + void clear(); + + int count() const; + + CXUnsavedFile *cxUnsavedFiles() const; + const std::vector &cxUnsavedFileVector() const; + + const time_point &lastChangeTimePoint() const; + +private: + CXUnsavedFile createCxUnsavedFile(const Utf8String &filePath, const Utf8String &fileContent); + static void deleteCXUnsavedFile(const CXUnsavedFile &cxUnsavedFile); + void updateCXUnsavedFileWithFileContainer(const FileContainer &fileContainer); + void removeCXUnsavedFile(const FileContainer &fileContainer); + void addOrUpdateCXUnsavedFile(const FileContainer &fileContainer); + void updateLastChangeTimePoint(); + +private: + mutable std::shared_ptr d; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_UNSAVEDFILES_H diff --git a/src/tools/codemodelbackend/codemodelbackend.pri b/src/tools/codemodelbackend/codemodelbackend.pri deleted file mode 100644 index 65f8d13466..0000000000 --- a/src/tools/codemodelbackend/codemodelbackend.pri +++ /dev/null @@ -1,26 +0,0 @@ -QTC_LIB_DEPENDS += \ - sqlite \ - codemodelbackendipc - -QT += core network -QT -= gui - -TARGET = codemodelbackend -CONFIG += console -CONFIG -= app_bundle C++-14 - -TEMPLATE = app - -include(ipcsource/codemodelbackendclangipc-source.pri) -include(../../../qtcreator.pri) -include(../../shared/clang/clang_installation.pri) -include(../../rpath.pri) - -LIBS += $$LLVM_LIBS -INCLUDEPATH += $$LLVM_INCLUDEPATH - -SOURCES += codemodelbackendmain.cpp - -osx { - QMAKE_LFLAGS += -Wl,-rpath,$${LLVM_LIBDIR} -} diff --git a/src/tools/codemodelbackend/codemodelbackend.pro b/src/tools/codemodelbackend/codemodelbackend.pro deleted file mode 100644 index 3f99b04b00..0000000000 --- a/src/tools/codemodelbackend/codemodelbackend.pro +++ /dev/null @@ -1,5 +0,0 @@ -include(codemodelbackend.pri) - -DESTDIR = $$IDE_LIBEXEC_PATH -target.path = $$QTC_PREFIX/bin # FIXME: libexec, more or less -INSTALLS += target diff --git a/src/tools/codemodelbackend/codemodelbackend.qbs b/src/tools/codemodelbackend/codemodelbackend.qbs deleted file mode 100644 index e797119996..0000000000 --- a/src/tools/codemodelbackend/codemodelbackend.qbs +++ /dev/null @@ -1,30 +0,0 @@ -import qbs 1.0 -import QtcClangInstallation as Clang -import QtcProcessOutputReader - -QtcTool { - name: "codemodelbackend" - - Depends { name: "CodeModelBackEndIpc" } - - Group { - prefix: "ipcsource/" - files: [ - "*.h", - "*.cpp" - ] - } - - files: [ "codemodelbackendmain.cpp" ] - - property string llvmConfig: Clang.llvmConfig(qbs) - property string llvmIncludeDir: Clang.includeDir(llvmConfig, QtcProcessOutputReader) - property string llvmLibDir: Clang.libDir(llvmConfig, QtcProcessOutputReader) - property string llvmLibs: Clang.libraries(qbs.targetOS) - - condition: llvmConfig - - cpp.includePaths: base.concat(["ipcsource", llvmIncludeDir]) - cpp.libraryPaths: base.concat(llvmLibDir) - cpp.dynamicLibraries: base.concat(llvmLibs) -} diff --git a/src/tools/codemodelbackend/codemodelbackendmain.cpp b/src/tools/codemodelbackend/codemodelbackendmain.cpp deleted file mode 100644 index 398ebaaaf5..0000000000 --- a/src/tools/codemodelbackend/codemodelbackendmain.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** 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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include - -#include -#include -#include - -int main(int argc, char *argv[]) -{ - QCoreApplication::setOrganizationName(QStringLiteral("QtProject")); - QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org")); - QCoreApplication::setApplicationName(QStringLiteral("CodeModelBackend")); - QCoreApplication::setApplicationVersion(QStringLiteral("1.0.0")); - - QCoreApplication application(argc, argv); - - if (application.arguments().count() != 2) { - qWarning() << "wrong argument count"; - return 1; - } - - CodeModelBackEnd::Commands::registerCommands(); - - CodeModelBackEnd::ClangIpcServer clangIpcServer; - CodeModelBackEnd::ConnectionServer connectionServer(application.arguments()[1]); - connectionServer.start(); - connectionServer.setIpcServer(&clangIpcServer); - - return application.exec(); -} - - diff --git a/src/tools/codemodelbackend/ipcsource/clangcodecompleteresults.cpp b/src/tools/codemodelbackend/ipcsource/clangcodecompleteresults.cpp deleted file mode 100644 index 25a5742414..0000000000 --- a/src/tools/codemodelbackend/ipcsource/clangcodecompleteresults.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "clangcodecompleteresults.h" - -#include - -namespace CodeModelBackEnd { - -using std::swap; - -ClangCodeCompleteResults::ClangCodeCompleteResults(CXCodeCompleteResults *cxCodeCompleteResults) - : cxCodeCompleteResults(cxCodeCompleteResults) -{ -} - -ClangCodeCompleteResults::~ClangCodeCompleteResults() -{ - clang_disposeCodeCompleteResults(cxCodeCompleteResults); -} - -bool ClangCodeCompleteResults::isNull() const -{ - return cxCodeCompleteResults == nullptr; -} - -CXCodeCompleteResults *ClangCodeCompleteResults::data() const -{ - return cxCodeCompleteResults; -} - -ClangCodeCompleteResults &ClangCodeCompleteResults::operator=(ClangCodeCompleteResults &&clangCodeCompleteResults) -{ - swap(cxCodeCompleteResults, clangCodeCompleteResults.cxCodeCompleteResults); - - return *this; -} - -ClangCodeCompleteResults::ClangCodeCompleteResults(ClangCodeCompleteResults &&clangCodeCompleteResults) -{ - swap(cxCodeCompleteResults, clangCodeCompleteResults.cxCodeCompleteResults); -} - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/clangcodecompleteresults.h b/src/tools/codemodelbackend/ipcsource/clangcodecompleteresults.h deleted file mode 100644 index 4ba7605f27..0000000000 --- a/src/tools/codemodelbackend/ipcsource/clangcodecompleteresults.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_CLANGCODECOMPLETERESULTS_H -#define CODEMODELBACKEND_CLANGCODECOMPLETERESULTS_H - - -#include - -#include - -namespace CodeModelBackEnd { - -class ClangCodeCompleteResults -{ -public: - ClangCodeCompleteResults(CXCodeCompleteResults *cxCodeCompleteResults); - ~ClangCodeCompleteResults(); - - ClangCodeCompleteResults(const ClangCodeCompleteResults &ClangCodeCompleteResults) = delete; - const ClangCodeCompleteResults &operator=(const ClangCodeCompleteResults &ClangCodeCompleteResults) = delete; - - ClangCodeCompleteResults(ClangCodeCompleteResults &&ClangCodeCompleteResults); - ClangCodeCompleteResults &operator=(ClangCodeCompleteResults &&ClangCodeCompleteResults); - - bool isNull() const; - - CXCodeCompleteResults *data() const; - -private: - CXCodeCompleteResults *cxCodeCompleteResults = nullptr; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_CLANGCODECOMPLETERESULTS_H diff --git a/src/tools/codemodelbackend/ipcsource/clangipcserver.cpp b/src/tools/codemodelbackend/ipcsource/clangipcserver.cpp deleted file mode 100644 index c385cfcd07..0000000000 --- a/src/tools/codemodelbackend/ipcsource/clangipcserver.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "clangipcserver.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "translationunits.h" -#include "codecompleter.h" -#include "translationunitdoesnotexistexception.h" -#include "translationunitisnullexception.h" -#include "translationunitfilenotexitexception.h" -#include "projectpartsdonotexistexception.h" -#include "translationunitparseerrorexception.h" - -#include - -namespace CodeModelBackEnd { - -ClangIpcServer::ClangIpcServer() - : translationUnits(projects, unsavedFiles) -{ -} - -void ClangIpcServer::end() -{ - QCoreApplication::exit(); -} - -void ClangIpcServer::registerTranslationUnitsForCodeCompletion(const CodeModelBackEnd::RegisterTranslationUnitForCodeCompletionCommand &command) -{ - try { - translationUnits.createOrUpdate(command.fileContainers()); - unsavedFiles.createOrUpdate(command.fileContainers()); - } catch (const ProjectPartDoNotExistException &exception) { - client()->projectPartsDoNotExist(ProjectPartsDoNotExistCommand(exception.projectPartIds())); - } catch (const std::exception &exception) { - qWarning() << "Error in ClangIpcServer::registerTranslationUnitsForCodeCompletion:" << exception.what(); - } -} - -void ClangIpcServer::unregisterTranslationUnitsForCodeCompletion(const CodeModelBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand &command) -{ - try { - translationUnits.remove(command.fileContainers()); - } catch (const TranslationUnitDoesNotExistException &exception) { - client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistCommand(exception.fileContainer())); - } catch (const ProjectPartDoNotExistException &exception) { - client()->projectPartsDoNotExist(ProjectPartsDoNotExistCommand(exception.projectPartIds())); - } catch (const std::exception &exception) { - qWarning() << "Error in ClangIpcServer::unregisterTranslationUnitsForCodeCompletion:" << exception.what(); - } -} - -void ClangIpcServer::registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) -{ - try { - projects.createOrUpdate(command.projectContainers()); - } catch (const std::exception &exception) { - qWarning() << "Error in ClangIpcServer::registerProjectPartsForCodeCompletion:" << exception.what(); - } -} - -void ClangIpcServer::unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) -{ - try { - projects.remove(command.filePaths()); - } catch (const ProjectPartDoNotExistException &exception) { - client()->projectPartsDoNotExist(ProjectPartsDoNotExistCommand(exception.projectPartIds())); - } catch (const std::exception &exception) { - qWarning() << "Error in ClangIpcServer::unregisterProjectPartsForCodeCompletion:" << exception.what(); - } -} - -void ClangIpcServer::completeCode(const CodeModelBackEnd::CompleteCodeCommand &command) -{ - try { - CodeCompleter codeCompleter(translationUnits.translationUnit(command.filePath(), command.projectPartId())); - - const auto codeCompletions = codeCompleter.complete(command.line(), command.column()); - - client()->codeCompleted(CodeCompletedCommand(codeCompletions, command.ticketNumber())); - } catch (const TranslationUnitDoesNotExistException &exception) { - client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistCommand(exception.fileContainer())); - } catch (const ProjectPartDoNotExistException &exception) { - client()->projectPartsDoNotExist(ProjectPartsDoNotExistCommand(exception.projectPartIds())); - } catch (const std::exception &exception) { - qWarning() << "Error in ClangIpcServer::unregisterProjectPartsForCodeCompletion:" << exception.what(); - } -} - -} diff --git a/src/tools/codemodelbackend/ipcsource/clangipcserver.h b/src/tools/codemodelbackend/ipcsource/clangipcserver.h deleted file mode 100644 index 10c7ebd8a7..0000000000 --- a/src/tools/codemodelbackend/ipcsource/clangipcserver.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CLANGIPCSERVER_H -#define CLANGIPCSERVER_H - -#include "ipcserverinterface.h" - -#include "translationunit.h" -#include "projectpart.h" -#include "unsavedfiles.h" -#include "projects.h" -#include "translationunits.h" - -#include - -#include - -namespace CodeModelBackEnd { - -class ClangIpcServer : public IpcServerInterface -{ -public: - ClangIpcServer(); - - void end() override; - void registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) override; - void unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) override; - void registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) override; - void unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) override; - void completeCode(const CompleteCodeCommand &command) override; - -private: - ProjectParts projects; - UnsavedFiles unsavedFiles; - TranslationUnits translationUnits; -}; - -} // namespace CodeModelBackEnd -#endif // CLANGIPCSERVER_H diff --git a/src/tools/codemodelbackend/ipcsource/clangstring.cpp b/src/tools/codemodelbackend/ipcsource/clangstring.cpp deleted file mode 100644 index 139d496c18..0000000000 --- a/src/tools/codemodelbackend/ipcsource/clangstring.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "clangstring.h" - -#include - -namespace CodeModelBackEnd { - -ClangString::ClangString(CXString cxString) - : cxString(cxString) -{ -} - -ClangString::~ClangString() -{ - clang_disposeString(cxString); -} - -bool ClangString::isNull() const -{ - return cxString.data == nullptr; -} - -ClangString &ClangString::operator=(ClangString &&clangString) -{ - cxString = std::move(clangString.cxString); - clangString.cxString.data = nullptr; - clangString.cxString.private_flags = 0; - - return *this; -} - -ClangString::ClangString(ClangString &&clangString) - : cxString(std::move(clangString.cxString)) -{ - clangString.cxString.data = nullptr; - clangString.cxString.private_flags = 0; -} - -ClangString::operator Utf8String() const -{ - return Utf8String(clang_getCString(cxString), -1); -} - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/clangstring.h b/src/tools/codemodelbackend/ipcsource/clangstring.h deleted file mode 100644 index c38712c1c0..0000000000 --- a/src/tools/codemodelbackend/ipcsource/clangstring.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_CLANGSTRING_H -#define CODEMODELBACKEND_CLANGSTRING_H - -#include - -#include - -namespace CodeModelBackEnd { - -class ClangString -{ -public: - ClangString(CXString cxString); - ~ClangString(); - - ClangString(const ClangString &clangString) = delete; - const ClangString &operator=(const ClangString &clangString) = delete; - - ClangString(ClangString &&clangString); - ClangString &operator=(ClangString &&clangString); - - operator Utf8String() const; - - bool isNull() const; - -private: - CXString cxString; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_CLANGSTRING_H diff --git a/src/tools/codemodelbackend/ipcsource/codecompletefailedexception.cpp b/src/tools/codemodelbackend/ipcsource/codecompletefailedexception.cpp deleted file mode 100644 index f9b4231bbd..0000000000 --- a/src/tools/codemodelbackend/ipcsource/codecompletefailedexception.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "codecompletefailedexception.h" - -CodeCompleteFailedException::CodeCompleteFailedException() -{ - -} - diff --git a/src/tools/codemodelbackend/ipcsource/codecompletefailedexception.h b/src/tools/codemodelbackend/ipcsource/codecompletefailedexception.h deleted file mode 100644 index b792afd907..0000000000 --- a/src/tools/codemodelbackend/ipcsource/codecompletefailedexception.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODECOMPLETEFAILEDEXCEPTION_H -#define CODECOMPLETEFAILEDEXCEPTION_H - - -class CodeCompleteFailedException -{ -public: - CodeCompleteFailedException(); -}; - -#endif // CODECOMPLETEFAILEDEXCEPTION_H diff --git a/src/tools/codemodelbackend/ipcsource/codecompleter.cpp b/src/tools/codemodelbackend/ipcsource/codecompleter.cpp deleted file mode 100644 index 1943d6fab8..0000000000 --- a/src/tools/codemodelbackend/ipcsource/codecompleter.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "codecompleter.h" - -#include "clangstring.h" -#include "clangcodecompleteresults.h" -#include "translationunit.h" -#include "codecompletefailedexception.h" - -#include "codecompletionsextractor.h" - -#include - -#include - -namespace CodeModelBackEnd { - -CodeCompleter::CodeCompleter(TranslationUnit translationUnit) - : translationUnit(std::move(translationUnit)) -{ -} - -QVector CodeCompleter::complete(uint line, uint column) -{ - ClangCodeCompleteResults completeResults(clang_codeCompleteAt(translationUnit.cxTranslationUnit(), - translationUnit.filePath().constData(), - line, - column, - translationUnit.cxUnsavedFiles(), - translationUnit.unsavedFilesCount(), - CXCodeComplete_IncludeMacros | CXCodeComplete_IncludeCodePatterns)); - - CodeCompletionsExtractor extractor(completeResults.data()); - - return extractor.extractAll(); -} - -Utf8String CodeCompleter::filePath() const -{ - return translationUnit.filePath(); -} - -void CodeCompleter::checkCodeCompleteResult(CXCodeCompleteResults *completeResults) -{ - if (!completeResults) - throw CodeCompleteFailedException(); -} - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/codecompleter.h b/src/tools/codemodelbackend/ipcsource/codecompleter.h deleted file mode 100644 index d47f131516..0000000000 --- a/src/tools/codemodelbackend/ipcsource/codecompleter.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_CODECOMPLETER_H -#define CODEMODELBACKEND_CODECOMPLETER_H - -#include -#include - -#include "translationunit.h" - -namespace CodeModelBackEnd { - -class TranslationUnit; - -class CodeCompleter -{ -public: - CodeCompleter() = default; - CodeCompleter(TranslationUnit translationUnit); - - QVector complete(uint line, uint column); - -private: - Utf8String filePath() const; - static void checkCodeCompleteResult(CXCodeCompleteResults *completeResults); - -private: - TranslationUnit translationUnit; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_CODECOMPLETER_H diff --git a/src/tools/codemodelbackend/ipcsource/codecompletionchunkconverter.cpp b/src/tools/codemodelbackend/ipcsource/codecompletionchunkconverter.cpp deleted file mode 100644 index deda1fea0f..0000000000 --- a/src/tools/codemodelbackend/ipcsource/codecompletionchunkconverter.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "codecompletionchunkconverter.h" - -#include "clangstring.h" - -namespace CodeModelBackEnd { - -void CodeCompletionChunkConverter::extractCompletionChunks(CXCompletionString completionString) -{ - const uint completionChunkCount = clang_getNumCompletionChunks(completionString); - - for (uint chunkIndex = 0; chunkIndex < completionChunkCount; ++chunkIndex) { - const CodeCompletionChunk::Kind kind = chunkKind(completionString, chunkIndex); - - if (kind == CodeCompletionChunk::Optional) - chunks.append(CodeCompletionChunk(kind, - chunkText(completionString, chunkIndex), - optionalChunks(completionString, chunkIndex))); - else - chunks.append(CodeCompletionChunk(kind, - chunkText(completionString, chunkIndex))); - } -} - -void CodeCompletionChunkConverter::extractOptionalCompletionChunks(CXCompletionString completionString) -{ - const uint completionChunkCount = clang_getNumCompletionChunks(completionString); - - for (uint chunkIndex = 0; chunkIndex < completionChunkCount; ++chunkIndex) { - const CodeCompletionChunk::Kind kind = chunkKind(completionString, chunkIndex); - - if (kind == CodeCompletionChunk::Optional) - extractOptionalCompletionChunks(clang_getCompletionChunkCompletionString(completionString, chunkIndex)); - else - chunks.append(CodeCompletionChunk(kind, chunkText(completionString, chunkIndex))); - } -} - -CodeCompletionChunk::Kind CodeCompletionChunkConverter::chunkKind(CXCompletionString completionString, uint chunkIndex) -{ - return CodeCompletionChunk::Kind(clang_getCompletionChunkKind(completionString, chunkIndex)); -} - -QVector CodeCompletionChunkConverter::extract(CXCompletionString completionString) -{ - CodeCompletionChunkConverter converter; - - converter.extractCompletionChunks(completionString); - - return converter.chunks; -} - -Utf8String CodeCompletionChunkConverter::chunkText(CXCompletionString completionString, uint chunkIndex) -{ - return ClangString(clang_getCompletionChunkText(completionString, chunkIndex)); -} - -QVector CodeCompletionChunkConverter::optionalChunks(CXCompletionString completionString, uint chunkIndex) -{ - CodeCompletionChunkConverter converter; - - converter.extractOptionalCompletionChunks(clang_getCompletionChunkCompletionString(completionString, chunkIndex)); - - return converter.chunks; -} - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/codecompletionchunkconverter.h b/src/tools/codemodelbackend/ipcsource/codecompletionchunkconverter.h deleted file mode 100644 index 772cf8409e..0000000000 --- a/src/tools/codemodelbackend/ipcsource/codecompletionchunkconverter.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_CODECOMPLETIONCHUNKCONVERTER_H -#define CODEMODELBACKEND_CODECOMPLETIONCHUNKCONVERTER_H - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -class CodeCompletionChunkConverter -{ -public: - static QVector extract(CXCompletionString completionString); - - static Utf8String chunkText(CXCompletionString completionString, uint chunkIndex); - -private: - QVector optionalChunks(CXCompletionString completionString, uint chunkIndex); - static CodeCompletionChunk::Kind chunkKind(CXCompletionString completionString, uint chunkIndex); - void extractCompletionChunks(CXCompletionString completionString); - void extractOptionalCompletionChunks(CXCompletionString completionString); - -private: - QVector chunks; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_CODECOMPLETIONCHUNKCONVERTER_H diff --git a/src/tools/codemodelbackend/ipcsource/codecompletionsextractor.cpp b/src/tools/codemodelbackend/ipcsource/codecompletionsextractor.cpp deleted file mode 100644 index b6e28b02d3..0000000000 --- a/src/tools/codemodelbackend/ipcsource/codecompletionsextractor.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "codecompletionsextractor.h" - -#include "clangstring.h" -#include "codecompletionchunkconverter.h" - -#ifdef CODEMODELBACKEND_TESTS -#include -#endif - -#include - -namespace CodeModelBackEnd { - -CodeCompletionsExtractor::CodeCompletionsExtractor(CXCodeCompleteResults *cxCodeCompleteResults) - : cxCodeCompleteResults(cxCodeCompleteResults) -{ - -} - -bool CodeCompletionsExtractor::next() -{ - const uint cxCodeCompleteResultCount = cxCodeCompleteResults->NumResults; - - ++cxCodeCompleteResultIndex; - - if (cxCodeCompleteResultIndex < cxCodeCompleteResultCount) { - currentCxCodeCompleteResult = cxCodeCompleteResults->Results[cxCodeCompleteResultIndex]; - - currentCodeCompletion_ = CodeCompletion(); - - extractCompletionKind(); - extractText(); - extractPriority(); - extractAvailability(); - extractHasParameters(); - extractCompletionChunks(); - - return true; - } - - return false; -} - -bool CodeCompletionsExtractor::peek(const Utf8String &name) -{ - const uint cxCodeCompleteResultCount = cxCodeCompleteResults->NumResults; - - uint peekCxCodeCompleteResultIndex = cxCodeCompleteResultIndex + 1; - - while (peekCxCodeCompleteResultIndex < cxCodeCompleteResultCount) { - if (hasText(name, cxCodeCompleteResults->Results[peekCxCodeCompleteResultIndex].CompletionString)) - return true; - - ++peekCxCodeCompleteResultIndex; - } - - return false; -} - -QVector CodeCompletionsExtractor::extractAll() -{ - QVector codeCompletions; - - while (next()) - codeCompletions.append(currentCodeCompletion_); - - return codeCompletions; -} - -void CodeCompletionsExtractor::extractCompletionKind() -{ - switch (currentCxCodeCompleteResult.CursorKind) { - case CXCursor_FunctionTemplate: - currentCodeCompletion_.setCompletionKind(CodeCompletion::TemplateFunctionCompletionKind); - break; - case CXCursor_CXXMethod: - extractMethodCompletionKind(); - break; - case CXCursor_FunctionDecl: - currentCodeCompletion_.setCompletionKind(CodeCompletion::FunctionCompletionKind); - break; - case CXCursor_VariableRef: - case CXCursor_VarDecl: - case CXCursor_FieldDecl: - case CXCursor_ParmDecl: - case CXCursor_NonTypeTemplateParameter: - currentCodeCompletion_.setCompletionKind(CodeCompletion::VariableCompletionKind); - break; - case CXCursor_StructDecl: - case CXCursor_UnionDecl: - case CXCursor_ClassDecl: - case CXCursor_TemplateTypeParameter: - currentCodeCompletion_.setCompletionKind(CodeCompletion::ClassCompletionKind); - break; - case CXCursor_ClassTemplatePartialSpecialization: - case CXCursor_ClassTemplate: - case CXCursor_TemplateTemplateParameter: - currentCodeCompletion_.setCompletionKind(CodeCompletion::TemplateClassCompletionKind); - break; - case CXCursor_Namespace: - case CXCursor_NamespaceAlias: - currentCodeCompletion_.setCompletionKind(CodeCompletion::NamespaceCompletionKind); - break; - case CXCursor_EnumDecl: - currentCodeCompletion_.setCompletionKind(CodeCompletion::EnumerationCompletionKind); - break; - case CXCursor_EnumConstantDecl: - currentCodeCompletion_.setCompletionKind(CodeCompletion::EnumeratorCompletionKind); - break; - case CXCursor_Constructor: - currentCodeCompletion_.setCompletionKind(CodeCompletion::ConstructorCompletionKind); - break; - case CXCursor_Destructor: - currentCodeCompletion_.setCompletionKind(CodeCompletion::DestructorCompletionKind); - break; - case CXCursor_MacroDefinition: - extractMacroCompletionKind(); - break; - case CXCursor_NotImplemented: - currentCodeCompletion_.setCompletionKind(CodeCompletion::KeywordCompletionKind); - break; - default: - currentCodeCompletion_.setCompletionKind(CodeCompletion::Other); - } -} - -void CodeCompletionsExtractor::extractText() -{ - const uint completionChunkCount = clang_getNumCompletionChunks(currentCxCodeCompleteResult.CompletionString); - for (uint chunkIndex = 0; chunkIndex < completionChunkCount; ++chunkIndex) { - const CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(currentCxCodeCompleteResult.CompletionString, chunkIndex); - if (chunkKind == CXCompletionChunk_TypedText) { - currentCodeCompletion_.setText(CodeCompletionChunkConverter::chunkText(currentCxCodeCompleteResult.CompletionString, chunkIndex)); - break; - } - } -} - -void CodeCompletionsExtractor::extractMethodCompletionKind() -{ - CXCompletionString cxCompletionString = cxCodeCompleteResults->Results[cxCodeCompleteResultIndex].CompletionString; - const uint annotationCount = clang_getCompletionNumAnnotations(cxCompletionString); - - for (uint annotationIndex = 0; annotationIndex < annotationCount; ++annotationIndex) { - ClangString annotation = clang_getCompletionAnnotation(cxCompletionString, annotationIndex); - - if (annotation == Utf8StringLiteral("qt_signal")) { - currentCodeCompletion_.setCompletionKind(CodeCompletion::SignalCompletionKind); - return; - } - - if (annotation == Utf8StringLiteral("qt_slot")) { - currentCodeCompletion_.setCompletionKind(CodeCompletion::SlotCompletionKind); - return; - } - } - - currentCodeCompletion_.setCompletionKind(CodeCompletion::FunctionCompletionKind); -} - -void CodeCompletionsExtractor::extractMacroCompletionKind() -{ - CXCompletionString cxCompletionString = cxCodeCompleteResults->Results[cxCodeCompleteResultIndex].CompletionString; - - const uint completionChunkCount = clang_getNumCompletionChunks(cxCompletionString); - - for (uint chunkIndex = 0; chunkIndex < completionChunkCount; ++chunkIndex) { - CXCompletionChunkKind kind = clang_getCompletionChunkKind(cxCompletionString, chunkIndex); - if (kind == CXCompletionChunk_Placeholder) { - currentCodeCompletion_.setCompletionKind(CodeCompletion::FunctionCompletionKind); - return; - } - } - - currentCodeCompletion_.setCompletionKind(CodeCompletion::PreProcessorCompletionKind); -} - -void CodeCompletionsExtractor::extractPriority() -{ - CXCompletionString cxCompletionString = cxCodeCompleteResults->Results[cxCodeCompleteResultIndex].CompletionString; - quint32 priority = clang_getCompletionPriority(cxCompletionString); - currentCodeCompletion_.setPriority(priority); -} - -void CodeCompletionsExtractor::extractAvailability() -{ - CXCompletionString cxCompletionString = cxCodeCompleteResults->Results[cxCodeCompleteResultIndex].CompletionString; - CXAvailabilityKind cxAvailabilityKind = clang_getCompletionAvailability(cxCompletionString); - - switch (cxAvailabilityKind) { - case CXAvailability_Available: - currentCodeCompletion_.setAvailability(CodeCompletion::Available); - break; - case CXAvailability_Deprecated: - currentCodeCompletion_.setAvailability(CodeCompletion::Deprecated); - break; - case CXAvailability_NotAvailable: - currentCodeCompletion_.setAvailability(CodeCompletion::NotAvailable); - break; - case CXAvailability_NotAccessible: - currentCodeCompletion_.setAvailability(CodeCompletion::NotAccessible); - break; - } -} - -void CodeCompletionsExtractor::extractHasParameters() -{ - const uint completionChunkCount = clang_getNumCompletionChunks(currentCxCodeCompleteResult.CompletionString); - for (uint chunkIndex = 0; chunkIndex < completionChunkCount; ++chunkIndex) { - const CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(currentCxCodeCompleteResult.CompletionString, chunkIndex); - if (chunkKind == CXCompletionChunk_LeftParen) { - const CXCompletionChunkKind nextChunkKind = clang_getCompletionChunkKind(currentCxCodeCompleteResult.CompletionString, chunkIndex + 1); - currentCodeCompletion_.setHasParameters(nextChunkKind != CXCompletionChunk_RightParen); - return; - } - } -} - -void CodeCompletionsExtractor::extractCompletionChunks() -{ - currentCodeCompletion_.setChunks(CodeCompletionChunkConverter::extract(currentCxCodeCompleteResult.CompletionString)); -} - -bool CodeCompletionsExtractor::hasText(const Utf8String &text, CXCompletionString cxCompletionString) const -{ - const uint completionChunkCount = clang_getNumCompletionChunks(cxCompletionString); - - for (uint chunkIndex = 0; chunkIndex < completionChunkCount; ++chunkIndex) { - const CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(cxCompletionString, chunkIndex); - if (chunkKind == CXCompletionChunk_TypedText) { - const ClangString currentText(clang_getCompletionChunkText(cxCompletionString, chunkIndex)); - return text == currentText; - } - } - - return false; -} - -const CodeCompletion &CodeCompletionsExtractor::currentCodeCompletion() const -{ - return currentCodeCompletion_; -} - -#ifdef CODEMODELBACKEND_TESTS -void PrintTo(const CodeCompletionsExtractor &extractor, std::ostream *os) -{ - *os << "name: " << ::testing::PrintToString(extractor.currentCodeCompletion().text()) - << ", kind: " << ::testing::PrintToString(extractor.currentCodeCompletion().completionKind()) - << ", priority: " << extractor.currentCodeCompletion().priority() - << ", kind: " << ::testing::PrintToString(extractor.currentCodeCompletion().availability()); -} -#endif - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/codecompletionsextractor.h b/src/tools/codemodelbackend/ipcsource/codecompletionsextractor.h deleted file mode 100644 index 54010edbcf..0000000000 --- a/src/tools/codemodelbackend/ipcsource/codecompletionsextractor.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_CODECOMPLETIONSEXTRACTOR_H -#define CODEMODELBACKEND_CODECOMPLETIONSEXTRACTOR_H - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -class CodeCompletionsExtractor -{ -public: - CodeCompletionsExtractor(CXCodeCompleteResults *cxCodeCompleteResults); - - CodeCompletionsExtractor(CodeCompletionsExtractor&) = delete; - CodeCompletionsExtractor &operator=(CodeCompletionsExtractor&) = delete; - - CodeCompletionsExtractor(CodeCompletionsExtractor&&) = delete; - CodeCompletionsExtractor &operator=(CodeCompletionsExtractor&&) = delete; - - bool next(); - bool peek(const Utf8String &name); - - QVector extractAll(); - - const CodeCompletion ¤tCodeCompletion() const; - -private: - void extractCompletionKind(); - void extractText(); - void extractMethodCompletionKind(); - void extractMacroCompletionKind(); - void extractPriority(); - void extractAvailability(); - void extractHasParameters(); - void extractCompletionChunks(); - - bool hasText(const Utf8String &text, CXCompletionString cxCompletionString) const; - -private: - CodeCompletion currentCodeCompletion_; - CXCompletionResult currentCxCodeCompleteResult; - CXCodeCompleteResults *cxCodeCompleteResults; - uint cxCodeCompleteResultIndex = -1; -}; - -#ifdef CODEMODELBACKEND_TESTS -void PrintTo(const CodeCompletionsExtractor &extractor, ::std::ostream* os); -#endif -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_CODECOMPLETIONSEXTRACTOR_H diff --git a/src/tools/codemodelbackend/ipcsource/codemodelbackendclangipc-source.pri b/src/tools/codemodelbackend/ipcsource/codemodelbackendclangipc-source.pri deleted file mode 100644 index 4e8800de02..0000000000 --- a/src/tools/codemodelbackend/ipcsource/codemodelbackendclangipc-source.pri +++ /dev/null @@ -1,37 +0,0 @@ -INCLUDEPATH += $$PWD - -HEADERS += $$PWD/clangipcserver.h \ - $$PWD/codecompleter.h \ - $$PWD/clangstring.h \ - $$PWD/translationunit.h \ - $$PWD/translationunitisnullexception.h \ - $$PWD/codecompletefailedexception.h \ - $$PWD/clangcodecompleteresults.h \ - $$PWD/codecompletionsextractor.h \ - $$PWD/unsavedfiles.h \ - $$PWD/projects.h \ - $$PWD/translationunits.h \ - $$PWD/translationunitparseerrorexception.h \ - $$PWD/projectpart.h \ - $$PWD/translationunitfilenotexitexception.h \ - $$PWD/translationunitdoesnotexistexception.h \ - $$PWD/projectpartsdonotexistexception.h \ - $$PWD/codecompletionchunkconverter.h - -SOURCES += $$PWD/clangipcserver.cpp \ - $$PWD/codecompleter.cpp \ - $$PWD/clangstring.cpp \ - $$PWD/translationunit.cpp \ - $$PWD/translationunitisnullexception.cpp \ - $$PWD/codecompletefailedexception.cpp \ - $$PWD/clangcodecompleteresults.cpp \ - $$PWD/codecompletionsextractor.cpp \ - $$PWD/unsavedfiles.cpp \ - $$PWD/projects.cpp \ - $$PWD/translationunits.cpp \ - $$PWD/translationunitparseerrorexception.cpp \ - $$PWD/projectpart.cpp \ - $$PWD/translationunitfilenotexitexception.cpp \ - $$PWD/translationunitdoesnotexistexception.cpp \ - $$PWD/projectpartsdonotexistexception.cpp \ - $$PWD/codecompletionchunkconverter.cpp diff --git a/src/tools/codemodelbackend/ipcsource/projectcontainer.cpp b/src/tools/codemodelbackend/ipcsource/projectcontainer.cpp deleted file mode 100644 index 8d7cff15f8..0000000000 --- a/src/tools/codemodelbackend/ipcsource/projectcontainer.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** 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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "projectcontainer.h" - -#include - -namespace CodeModelBackEnd { - -ProjectPartContainer::ProjectPartContainer(const Utf8String &fileName, - const Utf8StringVector &arguments) - : projectPartId_(fileName), - arguments_(arguments) -{ -} - -const Utf8String &ProjectPartContainer::projectPartId() const -{ - return projectPartId_; -} - -const Utf8StringVector &ProjectPartContainer::arguments() const -{ - return arguments_; -} - - -QDataStream &operator<<(QDataStream &out, const ProjectPartContainer &container) -{ - out << container.projectPartId_; - out << container.arguments_; - - return out; -} - -QDataStream &operator>>(QDataStream &in, ProjectPartContainer &container) -{ - in >> container.projectPartId_; - in >> container.arguments_; - - return in; -} - -bool operator == (const ProjectPartContainer &first, const ProjectPartContainer &second) -{ - return first.projectPartId_ == second.projectPartId_; -} - -bool operator < (const ProjectPartContainer &first, const ProjectPartContainer &second) -{ - return first.projectPartId_ < second.projectPartId_; -} - -QDebug operator <<(QDebug debug, const ProjectPartContainer &container) -{ - debug.nospace() << "ProjectContainer(" - << container.projectPartId() - << ")"; - - return debug; -} - -void PrintTo(const ProjectPartContainer &container, ::std::ostream* os) -{ - *os << "ProjectContainer(" - << container.projectPartId().constData() - << ")"; -} - - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/projectcontainer.h b/src/tools/codemodelbackend/ipcsource/projectcontainer.h deleted file mode 100644 index ed2f2f9680..0000000000 --- a/src/tools/codemodelbackend/ipcsource/projectcontainer.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** 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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_PROJECTCONTAINER_H -#define CODEMODELBACKEND_PROJECTCONTAINER_H - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -class CMBIPC_EXPORT ProjectPartContainer -{ - friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const ProjectPartContainer &container); - friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, ProjectPartContainer &container); - friend CMBIPC_EXPORT bool operator == (const ProjectPartContainer &first, const ProjectPartContainer &second); - friend CMBIPC_EXPORT bool operator < (const ProjectPartContainer &first, const ProjectPartContainer &second); -public: - ProjectPartContainer() = default; - ProjectPartContainer(const Utf8String &projectPartId, - const Utf8StringVector &arguments = Utf8StringVector()); - - const Utf8String &projectPartId() const; - const Utf8StringVector &arguments() const; - -private: - Utf8String projectPartId_; - Utf8StringVector arguments_; -}; - -CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const ProjectPartContainer &container); -CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, ProjectPartContainer &container); -CMBIPC_EXPORT bool operator == (const ProjectPartContainer &first, const ProjectPartContainer &second); -CMBIPC_EXPORT bool operator < (const ProjectPartContainer &first, const ProjectPartContainer &second); - -CMBIPC_EXPORT QDebug operator <<(QDebug debug, const ProjectPartContainer &container); -void PrintTo(const ProjectPartContainer &container, ::std::ostream* os); - -} // namespace CodeModelBackEnd - -Q_DECLARE_METATYPE(CodeModelBackEnd::ProjectPartContainer) - -#endif // CODEMODELBACKEND_PROJECTCONTAINER_H diff --git a/src/tools/codemodelbackend/ipcsource/projectpart.cpp b/src/tools/codemodelbackend/ipcsource/projectpart.cpp deleted file mode 100644 index e560ea705f..0000000000 --- a/src/tools/codemodelbackend/ipcsource/projectpart.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "projectpart.h" - -#include - -#include - -#include - -namespace CodeModelBackEnd { - -class ProjectPartData { -public: - ProjectPartData(const Utf8String &projectPartId); - ~ProjectPartData(); - -public: - void clearArguments(); - -public: - time_point lastChangeTimePoint; - std::vector arguments; - Utf8String projectPartId; -}; - -void ProjectPartData::clearArguments() -{ - for (auto argument : arguments) - delete [] argument; - - arguments.clear(); -} - -ProjectPartData::ProjectPartData(const Utf8String &projectPartId) - : lastChangeTimePoint(std::chrono::steady_clock::now()), - projectPartId(projectPartId) -{ -} - -ProjectPartData::~ProjectPartData() -{ - clearArguments(); -} - -ProjectPart::ProjectPart(const Utf8String &projectPartId) - : d(std::make_shared(projectPartId)) -{ -} - -ProjectPart::ProjectPart(const ProjectPartContainer &projectContainer) - : d(std::make_shared(projectContainer.projectPartId())) -{ - setArguments(projectContainer.arguments()); -} - -ProjectPart::~ProjectPart() = default; -ProjectPart::ProjectPart(const ProjectPart &) = default; -ProjectPart &ProjectPart::operator=(const ProjectPart &) = default; - -ProjectPart::ProjectPart(ProjectPart &&other) - : d(std::move(other.d)) -{ -} - -ProjectPart &ProjectPart::operator=(ProjectPart &&other) -{ - d = std::move(other.d); - - return *this; -} - -void ProjectPart::clearProjectPartId() -{ - d->projectPartId.clear(); -} - -const Utf8String &ProjectPart::projectPartId() const -{ - return d->projectPartId; -} - -static const char *strdup(const Utf8String &utf8String) -{ - char *cxArgument = new char[utf8String.byteSize() + 1]; - std::memcpy(cxArgument, utf8String.constData(), utf8String.byteSize() + 1); - - return cxArgument; -} - -void ProjectPart::setArguments(const Utf8StringVector &arguments) -{ - d->clearArguments(); - d->arguments.resize(arguments.size()); - std::transform(arguments.cbegin(), arguments.cend(), d->arguments.begin(), strdup); - updateLastChangeTimePoint(); -} - -const std::vector &ProjectPart::arguments() const -{ - return d->arguments; -} - -int ProjectPart::argumentCount() const -{ - return d->arguments.size(); -} - -const char * const *ProjectPart::cxArguments() const -{ - return arguments().data(); -} - -const time_point &ProjectPart::lastChangeTimePoint() const -{ - return d->lastChangeTimePoint; -} - -void ProjectPart::updateLastChangeTimePoint() -{ - d->lastChangeTimePoint = std::chrono::steady_clock::now(); -} - -bool operator==(const ProjectPart &first, const ProjectPart &second) -{ - return first.projectPartId() == second.projectPartId(); -} - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/projectpart.h b/src/tools/codemodelbackend/ipcsource/projectpart.h deleted file mode 100644 index 01e7b82cc8..0000000000 --- a/src/tools/codemodelbackend/ipcsource/projectpart.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_PROJECT_H -#define CODEMODELBACKEND_PROJECT_H - -#include -#include -#include - -class Utf8String; -class Utf8StringVector; - -namespace CodeModelBackEnd { - -class ProjectPartContainer; -class ProjectPartData; - -using time_point = std::chrono::steady_clock::time_point; - -class ProjectPart -{ -public: - ProjectPart(const Utf8String &projectPartId); - ProjectPart(const ProjectPartContainer &projectContainer); - ~ProjectPart(); - - ProjectPart(const ProjectPart &project); - ProjectPart &operator=(const ProjectPart &project); - - ProjectPart(ProjectPart &&project); - ProjectPart &operator=(ProjectPart &&project); - - void clearProjectPartId(); - - const Utf8String &projectPartId() const; - - void setArguments(const Utf8StringVector &arguments_); - - const std::vector &arguments() const; - - int argumentCount() const; - const char *const *cxArguments() const; - - const time_point &lastChangeTimePoint() const; - -private: - void updateLastChangeTimePoint(); - -private: - std::shared_ptr d; -}; - -bool operator==(const ProjectPart &first, const ProjectPart &second); - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_PROJECT_H diff --git a/src/tools/codemodelbackend/ipcsource/projectpartsdonotexistexception.cpp b/src/tools/codemodelbackend/ipcsource/projectpartsdonotexistexception.cpp deleted file mode 100644 index a896481ca0..0000000000 --- a/src/tools/codemodelbackend/ipcsource/projectpartsdonotexistexception.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "projectpartsdonotexistexception.h" - -namespace CodeModelBackEnd { - -ProjectPartDoNotExistException::ProjectPartDoNotExistException(const Utf8StringVector &projectPartIds) - : projectPartIds_(projectPartIds) -{ -} - -const Utf8StringVector &ProjectPartDoNotExistException::projectPartIds() const -{ - return projectPartIds_; -} - -const char *ProjectPartDoNotExistException::what() const Q_DECL_NOEXCEPT -{ - if (what_.isEmpty()) - what_ += Utf8StringLiteral("ProjectPart files ") - + projectPartIds().join(Utf8StringLiteral(", ")) - + Utf8StringLiteral(" does not exist!"); - - return what_.constData(); -} - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/projectpartsdonotexistexception.h b/src/tools/codemodelbackend/ipcsource/projectpartsdonotexistexception.h deleted file mode 100644 index 6abaf39008..0000000000 --- a/src/tools/codemodelbackend/ipcsource/projectpartsdonotexistexception.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_PROJECTDONOTEXISTSEXCEPTION_H -#define CODEMODELBACKEND_PROJECTDONOTEXISTSEXCEPTION_H - -#include - -#include - -namespace CodeModelBackEnd { - -class ProjectPartDoNotExistException : public std::exception -{ -public: - ProjectPartDoNotExistException(const Utf8StringVector &projectPartIds); - - const Utf8StringVector &projectPartIds() const; - - const char *what() const Q_DECL_NOEXCEPT override; - -#if defined(__GNUC__) && !defined(__clang__) -# if !__GNUC_PREREQ(4,8) - ~ProjectPartDoNotExistException() noexcept {} -# endif -#endif - -private: - Utf8StringVector projectPartIds_; - mutable Utf8String what_; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_PROJECTDONOTEXISTSEXCEPTION_H diff --git a/src/tools/codemodelbackend/ipcsource/projects.cpp b/src/tools/codemodelbackend/ipcsource/projects.cpp deleted file mode 100644 index 2e2aa4afb4..0000000000 --- a/src/tools/codemodelbackend/ipcsource/projects.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "projects.h" - -#include - -#include "projectpartsdonotexistexception.h" - -namespace CodeModelBackEnd { - -void ProjectParts::createOrUpdate(const QVector &projectContainers) -{ - for (const ProjectPartContainer &projectContainer : projectContainers) - createOrUpdateProjectPart(projectContainer); -} - -void ProjectParts::remove(const Utf8StringVector &projectPartIds) -{ - Utf8StringVector processedProjectPartFilePaths = projectPartIds; - - auto removeBeginIterator = std::remove_if(projects_.begin(), projects_.end(), [&processedProjectPartFilePaths] (const ProjectPart &project) { - return processedProjectPartFilePaths.removeFast(project.projectPartId()); - }); - - std::for_each(removeBeginIterator, projects_.end(), [](ProjectPart &project) { project.clearProjectPartId(); }); - projects_.erase(removeBeginIterator, projects_.end()); - - if (!processedProjectPartFilePaths.isEmpty()) - throw ProjectPartDoNotExistException(processedProjectPartFilePaths); -} - -bool ProjectParts::hasProjectPart(const Utf8String &projectPartId) const -{ - return findProjectPart(projectPartId) != projects_.cend(); -} - -const ProjectPart &ProjectParts::project(const Utf8String &projectPartId) const -{ - const auto findIterator = findProjectPart(projectPartId); - - if (findIterator == projects_.cend()) - throw ProjectPartDoNotExistException({projectPartId}); - - return *findIterator; -} - -std::vector::const_iterator ProjectParts::findProjectPart(const Utf8String &projectPartId) const -{ - return std::find_if(projects_.begin(), projects_.end(), [projectPartId] (const ProjectPart &project) { - return project.projectPartId() == projectPartId; - }); -} - -std::vector::iterator ProjectParts::findProjectPart(const Utf8String &projectPartId) -{ - return std::find_if(projects_.begin(), projects_.end(), [projectPartId] (const ProjectPart &project) { - return project.projectPartId() == projectPartId; - }); -} - -const std::vector &ProjectParts::projects() const -{ - return projects_; -} - -void ProjectParts::createOrUpdateProjectPart(const ProjectPartContainer &projectContainer) -{ - auto findIterator = findProjectPart(projectContainer.projectPartId()); - if (findIterator == projects_.cend()) - projects_.push_back(ProjectPart(projectContainer)); - else - findIterator->setArguments(projectContainer.arguments()); -} - - -} // namespace CodeModelbackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/projects.h b/src/tools/codemodelbackend/ipcsource/projects.h deleted file mode 100644 index b63cc02874..0000000000 --- a/src/tools/codemodelbackend/ipcsource/projects.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_PROJECTS_H -#define CODEMODELBACKEND_PROJECTS_H - -#include - -#include "projectpart.h" - -#include - -namespace CodeModelBackEnd { - -class ProjectParts -{ -public: - void createOrUpdate(const QVector &projectConainers); - void remove(const Utf8StringVector &projectPartIds); - - bool hasProjectPart(const Utf8String &projectPartId) const; - - const ProjectPart &project(const Utf8String &projectPartId) const; - - std::vector::const_iterator findProjectPart(const Utf8String &projectPartId) const; - std::vector::iterator findProjectPart(const Utf8String &projectPartId); - - const std::vector &projects() const; - -private: - void createOrUpdateProjectPart(const ProjectPartContainer &projectConainer); - -private: - std::vector projects_; -}; - -} // namespace CodeModelbackEnd - -#endif // CODEMODELBACKEND_PROJECTS_H diff --git a/src/tools/codemodelbackend/ipcsource/translationunit.cpp b/src/tools/codemodelbackend/ipcsource/translationunit.cpp deleted file mode 100644 index e9664038a7..0000000000 --- a/src/tools/codemodelbackend/ipcsource/translationunit.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 http://www.qt.io/terms-conditions. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "translationunit.h" - -#include - -#include - -#include "codecompleter.h" - -#include "translationunitisnullexception.h" -#include "translationunitfilenotexitexception.h" -#include "translationunitparseerrorexception.h" -#include "unsavedfiles.h" -#include "projectpart.h" - -namespace CodeModelBackEnd { - -class TranslationUnitData -{ -public: - TranslationUnitData(const Utf8String &filePath, - const UnsavedFiles &unsavedFiles, - const ProjectPart &projectPart); - ~TranslationUnitData(); - -public: - time_point lastChangeTimePoint; - ProjectPart projectPart; - Utf8String filePath; - CXTranslationUnit translationUnit = nullptr; - CXIndex index = nullptr; - UnsavedFiles unsavedFiles; -}; - -TranslationUnitData::TranslationUnitData(const Utf8String &filePath, - const UnsavedFiles &unsavedFiles, - const ProjectPart &projectPart) - : lastChangeTimePoint(std::chrono::steady_clock::now()), - projectPart(projectPart), - filePath(filePath), - unsavedFiles(unsavedFiles) -{ -} - -TranslationUnitData::~TranslationUnitData() -{ - clang_disposeTranslationUnit(translationUnit); - clang_disposeIndex(index); -} - -TranslationUnit::TranslationUnit(const Utf8String &filePath, - const UnsavedFiles &unsavedFiles, - const ProjectPart &project, - FileExistsCheck fileExistsCheck) - : d(std::make_shared(filePath, unsavedFiles, project)) -{ - if (fileExistsCheck == CheckIfFileExists) - checkIfFileExists(); -} - -bool TranslationUnit::isNull() const -{ - return !d; -} - -void TranslationUnit::reset() -{ - d.reset(); -} - -CXIndex TranslationUnit::index() const -{ - checkIfNull(); - - if (!d->index) - d->index = clang_createIndex(1, 1); - - return d->index; -} - -CXTranslationUnit TranslationUnit::cxTranslationUnit() const -{ - checkIfNull(); - - removeOutdatedTranslationUnit(); - - createTranslationUnitIfNeeded(); - - return d->translationUnit; -} - -const Utf8String &TranslationUnit::filePath() const -{ - checkIfNull(); - - return d->filePath; -} - -const Utf8String &TranslationUnit::projectPartId() const -{ - checkIfNull(); - - return d->projectPart.projectPartId(); -} - -const time_point &TranslationUnit::lastChangeTimePoint() const -{ - return d->lastChangeTimePoint; -} - -void TranslationUnit::checkIfNull() const -{ - if (isNull()) - throw TranslationUnitIsNullException(); -} - -void TranslationUnit::checkIfFileExists() const -{ - if (!QFileInfo::exists(d->filePath.toString())) - throw TranslationUnitFileNotExitsException(d->filePath); -} - -void TranslationUnit::updateLastChangeTimePoint() const -{ - d->lastChangeTimePoint = std::chrono::steady_clock::now(); -} - -void TranslationUnit::removeOutdatedTranslationUnit() const -{ - if (d->projectPart.lastChangeTimePoint() >= d->lastChangeTimePoint) { - clang_disposeTranslationUnit(d->translationUnit); - d->translationUnit = nullptr; - } -} - -void TranslationUnit::createTranslationUnitIfNeeded() const -{ - const auto options = CXTranslationUnit_DetailedPreprocessingRecord - | CXTranslationUnit_CacheCompletionResults - | CXTranslationUnit_PrecompiledPreamble - | CXTranslationUnit_SkipFunctionBodies; - - if (!d->translationUnit) { - d->translationUnit = CXTranslationUnit(); - CXErrorCode errorCode = clang_parseTranslationUnit2(index(), - d->filePath.constData(), - d->projectPart.cxArguments(), - d->projectPart.argumentCount(), - d->unsavedFiles.cxUnsavedFiles(), - d->unsavedFiles.count(), - options, - &d->translationUnit); - - checkTranslationUnitErrorCode(errorCode); - - updateLastChangeTimePoint(); - } -} - -void TranslationUnit::checkTranslationUnitErrorCode(CXErrorCode errorCode) const -{ - switch (errorCode) { - case CXError_Success: break; - default: throw TranslationUnitParseErrorException(d->filePath, d->projectPart.projectPartId()); - } -} - -uint TranslationUnit::unsavedFilesCount() const -{ - return d->unsavedFiles.count(); -} - -CXUnsavedFile *TranslationUnit::cxUnsavedFiles() const -{ - return d->unsavedFiles.cxUnsavedFiles(); -} - -TranslationUnit::~TranslationUnit() = default; - -TranslationUnit::TranslationUnit(const TranslationUnit &) = default; -TranslationUnit &TranslationUnit::operator=(const TranslationUnit &) = default; - -TranslationUnit::TranslationUnit(TranslationUnit &&other) - : d(std::move(other.d)) -{ -} - -TranslationUnit &TranslationUnit::operator=(TranslationUnit &&other) -{ - d = std::move(other.d); - - return *this; -} - -bool operator==(const TranslationUnit &first, const TranslationUnit &second) -{ - return first.filePath() == second.filePath() && first.projectPartId() == second.projectPartId(); -} - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/translationunit.h b/src/tools/codemodelbackend/ipcsource/translationunit.h deleted file mode 100644 index 52efd2b201..0000000000 --- a/src/tools/codemodelbackend/ipcsource/translationunit.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 http://www.qt.io/terms-conditions. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_TRANSLATIONUNIT_H -#define CODEMODELBACKEND_TRANSLATIONUNIT_H - -#include - -#include -#include - -#include - -class Utf8String; - -namespace CodeModelBackEnd { - -class TranslationUnitData; -class CodeCompleter; -class UnsavedFiles; -class ProjectPart; - -using time_point = std::chrono::steady_clock::time_point; - -class TranslationUnit -{ -public: - enum FileExistsCheck { - CheckIfFileExists, - DoNotCheckIfFileExists - }; - - TranslationUnit() = default; - TranslationUnit(const Utf8String &filePath, - const UnsavedFiles &unsavedFiles, - const ProjectPart &projectPart, - FileExistsCheck fileExistsCheck = CheckIfFileExists); - ~TranslationUnit(); - - TranslationUnit(const TranslationUnit &cxTranslationUnit); - TranslationUnit &operator=(const TranslationUnit &cxTranslationUnit); - - TranslationUnit(TranslationUnit &&cxTranslationUnit); - TranslationUnit &operator=(TranslationUnit &&cxTranslationUnit); - - bool isNull() const; - - void reset(); - - CXIndex index() const; - CXTranslationUnit cxTranslationUnit() const; - CXUnsavedFile * cxUnsavedFiles() const; - uint unsavedFilesCount() const; - - const Utf8String &filePath() const; - const Utf8String &projectPartId() const; - - const time_point &lastChangeTimePoint() const; - -private: - void checkIfNull() const; - void checkIfFileExists() const; - void updateLastChangeTimePoint() const; - void removeOutdatedTranslationUnit() const; - void createTranslationUnitIfNeeded() const; - void checkTranslationUnitErrorCode(CXErrorCode errorCode) const; - -private: - mutable std::shared_ptr d; -}; - -bool operator==(const TranslationUnit &first, const TranslationUnit &second); - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_TRANSLATIONUNIT_H diff --git a/src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistexception.cpp b/src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistexception.cpp deleted file mode 100644 index 61761283cb..0000000000 --- a/src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistexception.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "translationunitdoesnotexistexception.h" - -namespace CodeModelBackEnd { - -TranslationUnitDoesNotExistException::TranslationUnitDoesNotExistException(const FileContainer &fileContainer) - : fileContainer_(fileContainer) -{ -} - -TranslationUnitDoesNotExistException::TranslationUnitDoesNotExistException(const Utf8String filePath, const Utf8String projectPartId) - : fileContainer_(filePath, projectPartId) -{ -} - -const FileContainer &TranslationUnitDoesNotExistException::fileContainer() const -{ - return fileContainer_; -} - -const char *TranslationUnitDoesNotExistException::what() const Q_DECL_NOEXCEPT -{ - if (what_.isEmpty()) - what_ += Utf8StringLiteral("Parse error for file ") - + fileContainer_.filePath() - + Utf8StringLiteral(" in project ") - + fileContainer_.projectPartId() - + Utf8StringLiteral("!"); - - return what_.constData(); -} - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistexception.h b/src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistexception.h deleted file mode 100644 index 648d76ea2c..0000000000 --- a/src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistexception.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_TRANSLATIONUNITDONOTEXISTS_H -#define CODEMODELBACKEND_TRANSLATIONUNITDONOTEXISTS_H - -#include - -namespace CodeModelBackEnd { - -class TranslationUnitDoesNotExistException : public std::exception -{ -public: - TranslationUnitDoesNotExistException(const FileContainer &fileContainer); - TranslationUnitDoesNotExistException(const Utf8String filePath, const Utf8String projectPartId); - - const FileContainer &fileContainer() const; - - const char *what() const Q_DECL_NOEXCEPT override; - -#if defined(__GNUC__) && !defined(__clang__) -# if !__GNUC_PREREQ(4,8) - ~TranslationUnitDoesNotExistException() noexcept {} -# endif -#endif - -private: - FileContainer fileContainer_; - mutable Utf8String what_; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_TRANSLATIONUNITDONOTEXISTS_H diff --git a/src/tools/codemodelbackend/ipcsource/translationunitfilenotexitexception.cpp b/src/tools/codemodelbackend/ipcsource/translationunitfilenotexitexception.cpp deleted file mode 100644 index 29836a22bc..0000000000 --- a/src/tools/codemodelbackend/ipcsource/translationunitfilenotexitexception.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "translationunitfilenotexitexception.h" - -namespace CodeModelBackEnd { - -TranslationUnitFileNotExitsException::TranslationUnitFileNotExitsException(const Utf8String &filePath) - : filePath_(filePath) -{ -} - -const Utf8String &TranslationUnitFileNotExitsException::filePath() const -{ - return filePath_; -} - -const char *TranslationUnitFileNotExitsException::what() const Q_DECL_NOEXCEPT -{ - if (what_.isEmpty()) - what_ += Utf8StringLiteral("File ") - + filePath() - + Utf8StringLiteral(" in project does not exist!"); - - return what_.constData(); -} - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/translationunitfilenotexitexception.h b/src/tools/codemodelbackend/ipcsource/translationunitfilenotexitexception.h deleted file mode 100644 index 186336c6fa..0000000000 --- a/src/tools/codemodelbackend/ipcsource/translationunitfilenotexitexception.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_TRANSLATIONUNITFILENOTEXITS_H -#define CODEMODELBACKEND_TRANSLATIONUNITFILENOTEXITS_H - -#include - -#include - -namespace CodeModelBackEnd { - -class TranslationUnitFileNotExitsException : public std::exception -{ -public: - TranslationUnitFileNotExitsException(const Utf8String &filePath); - - const Utf8String &filePath() const; - - const char *what() const Q_DECL_NOEXCEPT override; - -#if defined(__GNUC__) && !defined(__clang__) -# if !__GNUC_PREREQ(4,8) - ~TranslationUnitFileNotExitsException() noexcept {} -# endif -#endif - -private: - Utf8String filePath_; - mutable Utf8String what_; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_TRANSLATIONUNITFILENOTEXITS_H diff --git a/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.cpp b/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.cpp deleted file mode 100644 index 3ebb6a796a..0000000000 --- a/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "translationunitisnullexception.h" - -namespace CodeModelBackEnd { - -const char *TranslationUnitIsNullException::what() const Q_DECL_NOEXCEPT -{ - return "Tried to access a null TranslationUnit!"; -} - - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.h b/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.h deleted file mode 100644 index 247a23b2e6..0000000000 --- a/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_TRANSLATIONUNITISNULLEXCEPTION_H -#define CODEMODELBACKEND_TRANSLATIONUNITISNULLEXCEPTION_H - -#include - -#include - -namespace CodeModelBackEnd { - -class TranslationUnitIsNullException : public std::exception -{ -public: - const char *what() const Q_DECL_NOEXCEPT override; - -#if defined(__GNUC__) && !defined(__clang__) -# if !__GNUC_PREREQ(4,8) - ~TranslationUnitIsNullException() noexcept {} -# endif -#endif -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_TRANSLATIONUNITISNULLEXCEPTION_H diff --git a/src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.cpp b/src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.cpp deleted file mode 100644 index abd79a64ed..0000000000 --- a/src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "translationunitparseerrorexception.h" - - - -namespace CodeModelBackEnd { - -TranslationUnitParseErrorException::TranslationUnitParseErrorException(const Utf8String &filePath, const Utf8String &projectPartId) - : filePath_(filePath), - projectPartId_(projectPartId) -{ -} - -const Utf8String &TranslationUnitParseErrorException::filePath() const -{ - return filePath_; -} - -const Utf8String &TranslationUnitParseErrorException::projectPartId() const -{ - return projectPartId_; -} - -const char *TranslationUnitParseErrorException::what() const Q_DECL_NOEXCEPT -{ - if (what_.isEmpty()) - what_ += Utf8StringLiteral("Parse error for file ") - + filePath() - + Utf8StringLiteral(" in project ") - + projectPartId() - + Utf8StringLiteral("!"); - - return what_.constData(); -} - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.h b/src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.h deleted file mode 100644 index 5a7050183d..0000000000 --- a/src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_TRANSLATIONUNITPARSEERROREXCEPTION_H -#define CODEMODELBACKEND_TRANSLATIONUNITPARSEERROREXCEPTION_H - -#include - -#include - -namespace CodeModelBackEnd { - -class TranslationUnitParseErrorException : public std::exception -{ -public: - TranslationUnitParseErrorException(const Utf8String &filePath, const Utf8String &projectPartId); - - const Utf8String &filePath() const; - const Utf8String &projectPartId() const; - - const char *what() const Q_DECL_NOEXCEPT override; - -#if defined(__GNUC__) && !defined(__clang__) -# if !__GNUC_PREREQ(4,8) - ~TranslationUnitParseErrorException() noexcept {} -# endif -#endif - -private: - Utf8String filePath_; - Utf8String projectPartId_; - mutable Utf8String what_; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_TRANSLATIONUNITPARSEERROREXCEPTION_H diff --git a/src/tools/codemodelbackend/ipcsource/translationunits.cpp b/src/tools/codemodelbackend/ipcsource/translationunits.cpp deleted file mode 100644 index 1b4a3a9138..0000000000 --- a/src/tools/codemodelbackend/ipcsource/translationunits.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "translationunits.h" - -#include -#include -#include - -namespace CodeModelBackEnd { - -bool operator==(const FileContainer &fileContainer, const TranslationUnit &translationUnit) -{ - return fileContainer.filePath() == translationUnit.filePath() && fileContainer.projectPartId() == translationUnit.projectPartId(); -} - -bool operator==(const TranslationUnit &translationUnit, const FileContainer &fileContainer) -{ - return fileContainer == translationUnit; -} - - -TranslationUnits::TranslationUnits(ProjectParts &projects, UnsavedFiles &unsavedFiles) - : projects(projects), - unsavedFiles(unsavedFiles) -{ -} - -void TranslationUnits::createOrUpdate(const QVector &fileContainers) -{ - for (const FileContainer &fileContainer : fileContainers) - createOrUpdateTranslationUnit(fileContainer); -} - -static bool removeFromFileContainer(QVector &fileContainers, const TranslationUnit &translationUnit) -{ - auto position = std::remove(fileContainers.begin(), fileContainers.end(), translationUnit); - - bool entryIsRemoved = position != fileContainers.end(); - - fileContainers.erase(position, fileContainers.end()); - - return entryIsRemoved; -} - - -void TranslationUnits::remove(const QVector &fileContainers) -{ - checkIfProjectPartsExists(fileContainers); - - QVector processedFileContainers = fileContainers; - - auto removeBeginIterator = std::remove_if(translationUnits_.begin(), translationUnits_.end(), [&processedFileContainers] (const TranslationUnit &translationUnit) { - return removeFromFileContainer(processedFileContainers, translationUnit); - }); - - translationUnits_.erase(removeBeginIterator, translationUnits_.end()); - - if (!processedFileContainers.isEmpty()) - throw TranslationUnitDoesNotExistException(processedFileContainers.first()); - -} - -const TranslationUnit &TranslationUnits::translationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const -{ - checkIfProjectPartExists(projectPartId); - - auto findIterator = findTranslationUnit(filePath, projectPartId); - - if (findIterator == translationUnits_.end()) - throw TranslationUnitDoesNotExistException(FileContainer(filePath, projectPartId)); - - return *findIterator; -} - -const std::vector &TranslationUnits::translationUnits() const -{ - return translationUnits_; -} - -void TranslationUnits::createOrUpdateTranslationUnit(const FileContainer &fileContainer) -{ - TranslationUnit::FileExistsCheck checkIfFileExists = fileContainer.hasUnsavedFileContent() ? TranslationUnit::DoNotCheckIfFileExists : TranslationUnit::CheckIfFileExists; - auto findIterator = findTranslationUnit(fileContainer); - if (findIterator == translationUnits_.end()) - translationUnits_.push_back(TranslationUnit(fileContainer.filePath(), - unsavedFiles, - projects.project(fileContainer.projectPartId()), - checkIfFileExists)); -} - -std::vector::iterator TranslationUnits::findTranslationUnit(const FileContainer &fileContainer) -{ - return std::find(translationUnits_.begin(), translationUnits_.end(), fileContainer); -} - -std::vector::const_iterator TranslationUnits::findTranslationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const -{ - FileContainer fileContainer(filePath, projectPartId); - return std::find(translationUnits_.begin(), translationUnits_.end(), fileContainer); -} - -void TranslationUnits::checkIfProjectPartExists(const Utf8String &projectFileName) const -{ - projects.project(projectFileName); -} - -void TranslationUnits::checkIfProjectPartsExists(const QVector &fileContainers) const -{ - Utf8StringVector notExistingProjectParts; - - for (const FileContainer &fileContainer : fileContainers) { - if (!projects.hasProjectPart(fileContainer.projectPartId())) - notExistingProjectParts.push_back(fileContainer.projectPartId()); - } - - if (!notExistingProjectParts.isEmpty()) - throw ProjectPartDoNotExistException(notExistingProjectParts); - -} - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/translationunits.h b/src/tools/codemodelbackend/ipcsource/translationunits.h deleted file mode 100644 index 105ec0052f..0000000000 --- a/src/tools/codemodelbackend/ipcsource/translationunits.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_TRANSLATIONUNITS_H -#define CODEMODELBACKEND_TRANSLATIONUNITS_H - -#include -#include - -#include - -#include "translationunit.h" - -namespace CodeModelBackEnd { - -class ProjectParts; -class UnsavedFiles; - -class TranslationUnits -{ -public: - TranslationUnits(ProjectParts &projects, UnsavedFiles &unsavedFiles); - - void createOrUpdate(const QVector &fileContainers); - void remove(const QVector &fileContainers); - - const TranslationUnit &translationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const; - - const std::vector &translationUnits() const; - -private: - void createOrUpdateTranslationUnit(const FileContainer &fileContainer); - std::vector::iterator findTranslationUnit(const FileContainer &fileContainer); - std::vector::const_iterator findTranslationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const; - void checkIfProjectPartExists(const Utf8String &projectFileName) const; - void checkIfProjectPartsExists(const QVector &fileContainers) const; - - -private: - std::vector translationUnits_; - ProjectParts &projects; - UnsavedFiles &unsavedFiles; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_TRANSLATIONUNITS_H diff --git a/src/tools/codemodelbackend/ipcsource/unsavedfiles.cpp b/src/tools/codemodelbackend/ipcsource/unsavedfiles.cpp deleted file mode 100644 index a5029245a8..0000000000 --- a/src/tools/codemodelbackend/ipcsource/unsavedfiles.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "unsavedfiles.h" - - -#include - -namespace CodeModelBackEnd { - -class UnsavedFilesData -{ -public: - UnsavedFilesData(); - ~UnsavedFilesData(); - -public: - time_point lastChangeTimePoint; - std::vector cxUnsavedFiles; -}; - -UnsavedFilesData::UnsavedFilesData() - : lastChangeTimePoint(std::chrono::steady_clock::now()) -{ -} - -UnsavedFilesData::~UnsavedFilesData() -{ - for (const CXUnsavedFile &cxUnsavedFile : cxUnsavedFiles) - UnsavedFiles::deleteCXUnsavedFile(cxUnsavedFile); - - cxUnsavedFiles.clear(); -} - -UnsavedFiles::UnsavedFiles() - : d(std::make_shared()) -{ -} - -UnsavedFiles::~UnsavedFiles() = default; - -UnsavedFiles::UnsavedFiles(const UnsavedFiles &) = default; -UnsavedFiles &UnsavedFiles::operator=(const UnsavedFiles &) = default; - -UnsavedFiles::UnsavedFiles(UnsavedFiles &&other) - : d(std::move(other.d)) -{ -} - -UnsavedFiles &UnsavedFiles::operator=(UnsavedFiles &&other) -{ - d = std::move(other.d); - - return *this; -} - -void UnsavedFiles::createOrUpdate(const QVector &fileContainers) -{ - for (const FileContainer &fileContainer : fileContainers) - updateCXUnsavedFileWithFileContainer(fileContainer); - - updateLastChangeTimePoint(); -} - -void UnsavedFiles::remove(const QVector &fileContainers) -{ - for (const FileContainer &fileContainer : fileContainers) - removeCXUnsavedFile(fileContainer); - - updateLastChangeTimePoint(); -} - -void UnsavedFiles::clear() -{ - for (const CXUnsavedFile &cxUnsavedFile : d->cxUnsavedFiles) - deleteCXUnsavedFile(cxUnsavedFile); - - d->cxUnsavedFiles.clear(); - updateLastChangeTimePoint(); -} - -int UnsavedFiles::count() const -{ - return d->cxUnsavedFiles.size(); -} - -CXUnsavedFile *UnsavedFiles::cxUnsavedFiles() const -{ - return d->cxUnsavedFiles.data(); -} - -const std::vector &UnsavedFiles::cxUnsavedFileVector() const -{ - return d->cxUnsavedFiles; -} - -const time_point &UnsavedFiles::lastChangeTimePoint() const -{ - return d->lastChangeTimePoint; -} - -CXUnsavedFile UnsavedFiles::createCxUnsavedFile(const Utf8String &filePath, const Utf8String &fileContent) -{ - char *cxUnsavedFilePath = new char[filePath.byteSize() + 1]; - char *cxUnsavedFileContent = new char[fileContent.byteSize() + 1]; - - std::memcpy(cxUnsavedFilePath, filePath.constData(), filePath.byteSize() + 1); - std::memcpy(cxUnsavedFileContent, fileContent.constData(), fileContent.byteSize() + 1); - - return CXUnsavedFile { cxUnsavedFilePath, cxUnsavedFileContent, ulong(fileContent.byteSize())}; -} - -void UnsavedFiles::deleteCXUnsavedFile(const CXUnsavedFile &cxUnsavedFile) -{ - delete [] cxUnsavedFile.Contents; - delete [] cxUnsavedFile.Filename; -} - -void UnsavedFiles::updateCXUnsavedFileWithFileContainer(const FileContainer &fileContainer) -{ - if (fileContainer.hasUnsavedFileContent()) { - addOrUpdateCXUnsavedFile(fileContainer); - } else { - removeCXUnsavedFile(fileContainer); - } -} - -void UnsavedFiles::removeCXUnsavedFile(const FileContainer &fileContainer) -{ - const Utf8String filePath = fileContainer.filePath(); - auto removeBeginIterator = std::remove_if(d->cxUnsavedFiles.begin(), - d->cxUnsavedFiles.end(), - [filePath] (const CXUnsavedFile &cxUnsavedFile) { return filePath == cxUnsavedFile.Filename; }); - - std::for_each(removeBeginIterator, d->cxUnsavedFiles.end(), UnsavedFiles::deleteCXUnsavedFile); - d->cxUnsavedFiles.erase( removeBeginIterator, d->cxUnsavedFiles.end()); -} - -void UnsavedFiles::addOrUpdateCXUnsavedFile(const FileContainer &fileContainer) -{ - const Utf8String filePath = fileContainer.filePath(); - const Utf8String fileContent = fileContainer.unsavedFileContent(); - auto isSameFile = [filePath] (const CXUnsavedFile &cxUnsavedFile) { return filePath == cxUnsavedFile.Filename; }; - - auto cxUnsavedFileIterator = std::find_if(d->cxUnsavedFiles.begin(), d->cxUnsavedFiles.end(), isSameFile); - if (cxUnsavedFileIterator == d->cxUnsavedFiles.end()) - d->cxUnsavedFiles.push_back(createCxUnsavedFile(filePath, fileContent)); - else { - deleteCXUnsavedFile(*cxUnsavedFileIterator); - *cxUnsavedFileIterator = createCxUnsavedFile(filePath, fileContent); - } -} - -void UnsavedFiles::updateLastChangeTimePoint() -{ - d->lastChangeTimePoint = std::chrono::steady_clock::now(); -} - - -} // namespace CodeModelBackEnd - diff --git a/src/tools/codemodelbackend/ipcsource/unsavedfiles.h b/src/tools/codemodelbackend/ipcsource/unsavedfiles.h deleted file mode 100644 index 071bebdecf..0000000000 --- a/src/tools/codemodelbackend/ipcsource/unsavedfiles.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_UNSAVEDFILES_H -#define CODEMODELBACKEND_UNSAVEDFILES_H - -#include - -#include -#include -#include - -#include - -#include - -namespace CodeModelBackEnd { - -using time_point = std::chrono::steady_clock::time_point; - -class UnsavedFilesData; - -class UnsavedFiles -{ - friend class UnsavedFilesData; -public: - UnsavedFiles(); - ~UnsavedFiles(); - - UnsavedFiles(const UnsavedFiles &unsavedFiles); - UnsavedFiles &operator=(const UnsavedFiles &unsavedFiles); - - UnsavedFiles(UnsavedFiles &&unsavedFiles); - UnsavedFiles &operator=(UnsavedFiles &&unsavedFiles); - - void createOrUpdate(const QVector &fileContainers); - void remove(const QVector &fileContainers); - void clear(); - - int count() const; - - CXUnsavedFile *cxUnsavedFiles() const; - const std::vector &cxUnsavedFileVector() const; - - const time_point &lastChangeTimePoint() const; - -private: - CXUnsavedFile createCxUnsavedFile(const Utf8String &filePath, const Utf8String &fileContent); - static void deleteCXUnsavedFile(const CXUnsavedFile &cxUnsavedFile); - void updateCXUnsavedFileWithFileContainer(const FileContainer &fileContainer); - void removeCXUnsavedFile(const FileContainer &fileContainer); - void addOrUpdateCXUnsavedFile(const FileContainer &fileContainer); - void updateLastChangeTimePoint(); - -private: - mutable std::shared_ptr d; -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_UNSAVEDFILES_H diff --git a/src/tools/tools.pro b/src/tools/tools.pro index 0e9140799f..be4170db1a 100644 --- a/src/tools/tools.pro +++ b/src/tools/tools.pro @@ -20,7 +20,7 @@ mac { isEmpty(LLVM_INSTALL_DIR):LLVM_INSTALL_DIR=$$(LLVM_INSTALL_DIR) exists($$LLVM_INSTALL_DIR) { - SUBDIRS += codemodelbackend + SUBDIRS += clangbackend } BUILD_CPLUSPLUS_TOOLS = $$(BUILD_CPLUSPLUS_TOOLS) diff --git a/src/tools/tools.qbs b/src/tools/tools.qbs index d6bbbbe657..1a378e8628 100644 --- a/src/tools/tools.qbs +++ b/src/tools/tools.qbs @@ -4,7 +4,7 @@ Project { name: "Tools" references: [ "buildoutputparser/buildoutputparser.qbs", - "codemodelbackend/codemodelbackend.qbs", + "clangbackend/clangbackend.qbs", "cplusplustools.qbs", "qtcdebugger/qtcdebugger.qbs", "qtcreatorcrashhandler/qtcreatorcrashhandler.qbs", diff --git a/tests/unit/codemodelbackend/codemodelbackend.pro b/tests/unit/codemodelbackend/codemodelbackend.pro deleted file mode 100644 index cbd0d9bb05..0000000000 --- a/tests/unit/codemodelbackend/codemodelbackend.pro +++ /dev/null @@ -1,5 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS = echoserver unittest - -unittest.depends = echoserver diff --git a/tests/unit/codemodelbackend/echoserver/echoipcserver.cpp b/tests/unit/codemodelbackend/echoserver/echoipcserver.cpp deleted file mode 100644 index ca2c51c8c6..0000000000 --- a/tests/unit/codemodelbackend/echoserver/echoipcserver.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "echoipcserver.h" - -#include "cmbendcommand.h" -#include "cmbechocommand.h" -#include "cmbregistertranslationunitsforcodecompletioncommand.h" -#include "cmbunregistertranslationunitsforcodecompletioncommand.h" -#include "cmbregisterprojectsforcodecompletioncommand.h" -#include "cmbunregisterprojectsforcodecompletioncommand.h" -#include "cmbcompletecodecommand.h" -#include "cmbcodecompletedcommand.h" - -#include "connectionserver.h" - -#include - -#include - -namespace CodeModelBackEnd { - -void EchoIpcServer::dispatch(const QVariant &command) -{ - IpcServerInterface::dispatch(command); -} - -void EchoIpcServer::end() -{ - ConnectionServer::removeServer(); - QCoreApplication::quit(); -} - -void EchoIpcServer::registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) -{ - echoCommand(QVariant::fromValue(command)); -} - -void EchoIpcServer::unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) -{ - echoCommand(QVariant::fromValue(command)); -} - -void EchoIpcServer::registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) -{ - echoCommand(QVariant::fromValue(command)); -} - -void EchoIpcServer::unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) -{ - echoCommand(QVariant::fromValue(command)); -} - -void EchoIpcServer::completeCode(const CompleteCodeCommand &command) -{ - echoCommand(QVariant::fromValue(command)); -} - -void EchoIpcServer::echoCommand(const QVariant &command) -{ - client()->echo(EchoCommand(command)); -} - -} // namespace CodeModelBackEnd - diff --git a/tests/unit/codemodelbackend/echoserver/echoipcserver.h b/tests/unit/codemodelbackend/echoserver/echoipcserver.h deleted file mode 100644 index d26a1244bc..0000000000 --- a/tests/unit/codemodelbackend/echoserver/echoipcserver.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEMODELBACKEND_ECHOIPCSERVER_H -#define CODEMODELBACKEND_ECHOIPCSERVER_H - -#include "ipcserverinterface.h" - -namespace CodeModelBackEnd { - -class EchoIpcServer : public IpcServerInterface -{ -public: - void dispatch(const QVariant &command) override; - void end() override; - void registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) override; - void unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) override; - void registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) override; - void unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) override; - void completeCode(const CompleteCodeCommand &command) override; - -private: - void echoCommand(const QVariant &command); -}; - -} // namespace CodeModelBackEnd - -#endif // CODEMODELBACKEND_ECHOIPCSERVER_H diff --git a/tests/unit/codemodelbackend/echoserver/echoserver.pro b/tests/unit/codemodelbackend/echoserver/echoserver.pro deleted file mode 100644 index 7894618441..0000000000 --- a/tests/unit/codemodelbackend/echoserver/echoserver.pro +++ /dev/null @@ -1,28 +0,0 @@ -QT += core network - -QT -= gui - -TARGET = echo -CONFIG += console c++14 -CONFIG -= app_bundle - -TEMPLATE = app - -unix:LIBS += -ldl - -osx:QMAKE_CXXFLAGS = -stdlib=libc++ - -include(../../../../src/libs/codemodelbackendipc/codemodelbackendipc-lib.pri) -include(../../../../src/libs/sqlite/sqlite-lib.pri) - -SOURCES += \ - echoipcserver.cpp \ - echoserverprocessmain.cpp - -HEADERS += \ - echoipcserver.h - -DEFINES += CODEMODELBACKENDIPC_TESTS -DEFINES += DONT_CHECK_COMMAND_COUNTER - -win32:DESTDIR = .. diff --git a/tests/unit/codemodelbackend/echoserver/echoserverprocessmain.cpp b/tests/unit/codemodelbackend/echoserver/echoserverprocessmain.cpp deleted file mode 100644 index 7dd1db9051..0000000000 --- a/tests/unit/codemodelbackend/echoserver/echoserverprocessmain.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include - -#include "echoipcserver.h" -#include "connectionserver.h" -#include "cmbcommands.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication::setOrganizationName("QtProject"); - QCoreApplication::setOrganizationDomain("qt-project.org"); - QCoreApplication::setApplicationName("EchoCodeModelBackend"); - QCoreApplication::setApplicationVersion("1.0.0"); - - QCoreApplication application(argc, argv); - - if (application.arguments().count() != 2) { - qWarning() << "wrong argument count"; - return 1; - } - - CodeModelBackEnd::Commands::registerCommands(); - - CodeModelBackEnd::EchoIpcServer echoIpcServer; - CodeModelBackEnd::ConnectionServer connectionServer(application.arguments()[1]); - connectionServer.start(); - connectionServer.setIpcServer(&echoIpcServer); - - return application.exec(); -} diff --git a/tests/unit/codemodelbackend/unittest/clangcodecompleteresultstest.cpp b/tests/unit/codemodelbackend/unittest/clangcodecompleteresultstest.cpp deleted file mode 100644 index 4f2ebbeee3..0000000000 --- a/tests/unit/codemodelbackend/unittest/clangcodecompleteresultstest.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gmock/gmock.h" -#include "gtest-qt-printing.h" - -#include - -#include -#include -#include -#include -#include - -namespace { - -using CodeModelBackEnd::ClangCodeCompleteResults; -using CodeModelBackEnd::TranslationUnit; -using CodeModelBackEnd::UnsavedFiles; -using CodeModelBackEnd::ProjectPart; - -TEST(ClangCodeCompleteResults, GetData) -{ - ProjectPart projectPart(Utf8StringLiteral("projectPartId")); - UnsavedFiles unsavedFiles; - TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), unsavedFiles, projectPart); - CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(translationUnit.cxTranslationUnit(), translationUnit.filePath().constData(), 49, 1, 0, 0, 0); - - ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults); - - ASSERT_THAT(codeCompleteResults.data(), cxCodeCompleteResults); -} - -TEST(ClangCodeCompleteResults, GetInvalidData) -{ - CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(nullptr, "file.cpp", 49, 1, 0, 0, 0); - - ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults); - - ASSERT_THAT(codeCompleteResults.data(), cxCodeCompleteResults); -} - -TEST(ClangCodeCompleteResults, MoveClangCodeCompleteResults) -{ - ProjectPart projectPart(Utf8StringLiteral("projectPartId")); - UnsavedFiles unsavedFiles; - TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), unsavedFiles, projectPart); - CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(translationUnit.cxTranslationUnit(), translationUnit.filePath().constData(), 49, 1, 0, 0, 0); - - ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults); - - const ClangCodeCompleteResults codeCompleteResults2 = std::move(codeCompleteResults); - - ASSERT_TRUE(codeCompleteResults.isNull()); - ASSERT_FALSE(codeCompleteResults2.isNull()); -} - -} diff --git a/tests/unit/codemodelbackend/unittest/clangipcservertest.cpp b/tests/unit/codemodelbackend/unittest/clangipcservertest.cpp deleted file mode 100644 index 73988fe336..0000000000 --- a/tests/unit/codemodelbackend/unittest/clangipcservertest.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gmock/gmock.h" - -#include "gtest-qt-printing.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "mockipclient.h" - -using testing::Property; -using testing::Contains; -using testing::Not; -using testing::Eq; - -namespace { - -using CodeModelBackEnd::RegisterTranslationUnitForCodeCompletionCommand; -using CodeModelBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand; -using CodeModelBackEnd::RegisterProjectPartsForCodeCompletionCommand; -using CodeModelBackEnd::UnregisterProjectPartsForCodeCompletionCommand; -using CodeModelBackEnd::CompleteCodeCommand; -using CodeModelBackEnd::CodeCompletedCommand; -using CodeModelBackEnd::CodeCompletion; -using CodeModelBackEnd::FileContainer; -using CodeModelBackEnd::ProjectPartContainer; -using CodeModelBackEnd::TranslationUnitDoesNotExistCommand; -using CodeModelBackEnd::ProjectPartsDoNotExistCommand; - -class ClangIpcServer : public ::testing::Test -{ -protected: - void SetUp() override; - - void registerFiles(); - void registerProjectPart(); - void changeProjectPartArguments(); - void changeProjectPartArgumentsToWrongValues(); - static const Utf8String unsavedContent(const QString &unsavedFilePath); - -protected: - MockIpcClient mockIpcClient; - CodeModelBackEnd::ClangIpcServer clangServer; - const Utf8String projectPartId = Utf8StringLiteral("pathToProjectPart.pro"); - const Utf8String functionTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"); - const Utf8String variableTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp"); - const QString unsavedTestFilePath = QStringLiteral(TESTDATA_DIR) + QStringLiteral("/complete_extractor_function_unsaved.cpp"); - const QString updatedUnsavedTestFilePath = QStringLiteral(TESTDATA_DIR) + QStringLiteral("/complete_extractor_function_unsaved_2.cpp"); - const Utf8String parseErrorTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_translationunit_parse_error.cpp"); -}; - - -void ClangIpcServer::SetUp() -{ - clangServer.addClient(&mockIpcClient); - registerProjectPart(); - registerFiles(); -} - -void ClangIpcServer::registerFiles() -{ - RegisterTranslationUnitForCodeCompletionCommand command({FileContainer(functionTestFilePath, projectPartId, unsavedContent(unsavedTestFilePath), true), - FileContainer(variableTestFilePath, projectPartId)}); - - clangServer.registerTranslationUnitsForCodeCompletion(command); -} - -void ClangIpcServer::registerProjectPart() -{ - RegisterProjectPartsForCodeCompletionCommand command({ProjectPartContainer(projectPartId)}); - - clangServer.registerProjectPartsForCodeCompletion(command); -} - -void ClangIpcServer::changeProjectPartArguments() -{ - RegisterProjectPartsForCodeCompletionCommand command({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DArgumentDefinition")})}); - - clangServer.registerProjectPartsForCodeCompletion(command); -} - -void ClangIpcServer::changeProjectPartArgumentsToWrongValues() -{ - RegisterProjectPartsForCodeCompletionCommand command({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-blah")})}); - - clangServer.registerProjectPartsForCodeCompletion(command); -} - -const Utf8String ClangIpcServer::unsavedContent(const QString &unsavedFilePath) -{ - QFile unsavedFileContentFile(unsavedFilePath); - bool isOpen = unsavedFileContentFile.open(QIODevice::ReadOnly | QIODevice::Text); - if (!isOpen) - ADD_FAILURE() << "File with the unsaved content cannot be opened!"; - - return Utf8String::fromByteArray(unsavedFileContentFile.readAll()); -} - -TEST_F(ClangIpcServer, GetCodeCompletion) -{ - CompleteCodeCommand completeCodeCommand(functionTestFilePath, - 20, - 1, - projectPartId); - CodeCompletion codeCompletion(Utf8StringLiteral("Function"), - Utf8String(), - Utf8String(), - 34, - CodeCompletion::FunctionCompletionKind); - - EXPECT_CALL(mockIpcClient, codeCompleted(Property(&CodeCompletedCommand::codeCompletions, Contains(codeCompletion)))) - .Times(1); - - clangServer.completeCode(completeCodeCommand); -} - -TEST_F(ClangIpcServer, GetCodeCompletionDependingOnArgumets) -{ - CompleteCodeCommand completeCodeCommand(variableTestFilePath, - 35, - 1, - projectPartId); - CodeCompletion codeCompletion(Utf8StringLiteral("ArgumentDefinitionVariable"), - Utf8String(), - Utf8String(), - 34, - CodeCompletion::VariableCompletionKind); - - EXPECT_CALL(mockIpcClient, codeCompleted(Property(&CodeCompletedCommand::codeCompletions, Contains(codeCompletion)))) - .Times(1); - - changeProjectPartArguments(); - clangServer.completeCode(completeCodeCommand); -} - -TEST_F(ClangIpcServer, GetTranslationUnitDoesNotExistForCodeCompletionOnNonExistingTranslationUnit) -{ - CompleteCodeCommand completeCodeCommand(Utf8StringLiteral("dontexists.cpp"), - 34, - 1, - projectPartId); - TranslationUnitDoesNotExistCommand translationUnitDoesNotExistCommand(Utf8StringLiteral("dontexists.cpp"), projectPartId); - - EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(translationUnitDoesNotExistCommand)) - .Times(1); - - clangServer.completeCode(completeCodeCommand); -} - -TEST_F(ClangIpcServer, GetTranslationUnitDoesNotExistForCompletingUnregisteredFile) -{ - CompleteCodeCommand completeCodeCommand(parseErrorTestFilePath, - 20, - 1, - projectPartId); - TranslationUnitDoesNotExistCommand translationUnitDoesNotExistCommand(parseErrorTestFilePath, projectPartId); - - EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(translationUnitDoesNotExistCommand)) - .Times(1); - - clangServer.completeCode(completeCodeCommand); -} - -TEST_F(ClangIpcServer, GetCodeCompletionForUnsavedFile) -{ - CompleteCodeCommand completeCodeCommand(functionTestFilePath, - 20, - 1, - projectPartId); - CodeCompletion codeCompletion(Utf8StringLiteral("Method2"), - Utf8String(), - Utf8String(), - 34, - CodeCompletion::FunctionCompletionKind); - - EXPECT_CALL(mockIpcClient, codeCompleted(Property(&CodeCompletedCommand::codeCompletions, Contains(codeCompletion)))) - .Times(1); - - clangServer.completeCode(completeCodeCommand); -} - -TEST_F(ClangIpcServer, GetNoCodeCompletionAfterRemovingUnsavedFile) -{ - clangServer.registerTranslationUnitsForCodeCompletion(RegisterTranslationUnitForCodeCompletionCommand({FileContainer(functionTestFilePath, projectPartId)})); - CompleteCodeCommand completeCodeCommand(functionTestFilePath, - 20, - 1, - projectPartId); - CodeCompletion codeCompletion(Utf8StringLiteral("Method2"), - Utf8String(), - Utf8String(), - 34, - CodeCompletion::FunctionCompletionKind); - - EXPECT_CALL(mockIpcClient, codeCompleted(Property(&CodeCompletedCommand::codeCompletions, Not(Contains(codeCompletion))))) - .Times(1); - - clangServer.completeCode(completeCodeCommand); -} - -TEST_F(ClangIpcServer, GetNewCodeCompletionAfterUpdatingUnsavedFile) -{ - clangServer.registerTranslationUnitsForCodeCompletion(RegisterTranslationUnitForCodeCompletionCommand({FileContainer(functionTestFilePath, - projectPartId, - unsavedContent(updatedUnsavedTestFilePath), - true)})); - CompleteCodeCommand completeCodeCommand(functionTestFilePath, - 20, - 1, - projectPartId); - CodeCompletion codeCompletion(Utf8StringLiteral("Method3"), - Utf8String(), - Utf8String(), - 34, - CodeCompletion::FunctionCompletionKind); - - EXPECT_CALL(mockIpcClient, codeCompleted(Property(&CodeCompletedCommand::codeCompletions, Contains(codeCompletion)))) - .Times(1); - - clangServer.completeCode(completeCodeCommand); -} - -TEST_F(ClangIpcServer, GetTranslationUnitDoesNotExistForUnregisterTranslationUnitWithWrongFilePath) -{ - FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), projectPartId); - UnregisterTranslationUnitsForCodeCompletionCommand command({fileContainer}); - TranslationUnitDoesNotExistCommand translationUnitDoesNotExistCommand(fileContainer); - - EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(translationUnitDoesNotExistCommand)) - .Times(1); - - clangServer.unregisterTranslationUnitsForCodeCompletion(command); -} - -TEST_F(ClangIpcServer, UnregisterTranslationUnitAndTestFailingCompletion) -{ - FileContainer fileContainer(functionTestFilePath, projectPartId); - UnregisterTranslationUnitsForCodeCompletionCommand command({fileContainer}); - clangServer.unregisterTranslationUnitsForCodeCompletion(command); - CompleteCodeCommand completeCodeCommand(functionTestFilePath, - 20, - 1, - projectPartId); - TranslationUnitDoesNotExistCommand translationUnitDoesNotExistCommand(fileContainer); - - EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(translationUnitDoesNotExistCommand)) - .Times(1); - - clangServer.completeCode(completeCodeCommand); -} - -TEST_F(ClangIpcServer, GetProjectPartDoesNotExistUnregisterProjectPartInexistingProjectPart) -{ - Utf8StringVector inexistingProjectPartFilePath = {Utf8StringLiteral("projectpartsdoesnotexist.pro"), Utf8StringLiteral("project2doesnotexists.pro")}; - UnregisterProjectPartsForCodeCompletionCommand unregisterProjectPartsForCodeCompletionCommand(inexistingProjectPartFilePath); - ProjectPartsDoNotExistCommand projectPartsDoNotExistCommand(inexistingProjectPartFilePath); - - EXPECT_CALL(mockIpcClient, projectPartsDoNotExist(projectPartsDoNotExistCommand)) - .Times(1); - - clangServer.unregisterProjectPartsForCodeCompletion(unregisterProjectPartsForCodeCompletionCommand); -} - -TEST_F(ClangIpcServer, GetProjectPartDoesNotExistRegisterTranslationUnitWithInexistingProjectPart) -{ - Utf8String inexistingProjectPartFilePath = Utf8StringLiteral("projectpartsdoesnotexist.pro"); - RegisterTranslationUnitForCodeCompletionCommand registerFileForCodeCompletionCommand({FileContainer(variableTestFilePath, inexistingProjectPartFilePath)}); - ProjectPartsDoNotExistCommand projectPartsDoNotExistCommand({inexistingProjectPartFilePath}); - - EXPECT_CALL(mockIpcClient, projectPartsDoNotExist(projectPartsDoNotExistCommand)) - .Times(1); - - clangServer.registerTranslationUnitsForCodeCompletion(registerFileForCodeCompletionCommand); -} - -TEST_F(ClangIpcServer, GetProjectPartDoesNotExistUnregisterTranslationUnitWithInexistingProjectPart) -{ - Utf8String inexistingProjectPartFilePath = Utf8StringLiteral("projectpartsdoesnotexist.pro"); - UnregisterTranslationUnitsForCodeCompletionCommand unregisterFileForCodeCompletionCommand({FileContainer(variableTestFilePath, inexistingProjectPartFilePath)}); - ProjectPartsDoNotExistCommand projectPartsDoNotExistCommand({inexistingProjectPartFilePath}); - - EXPECT_CALL(mockIpcClient, projectPartsDoNotExist(projectPartsDoNotExistCommand)) - .Times(1); - - clangServer.unregisterTranslationUnitsForCodeCompletion(unregisterFileForCodeCompletionCommand); -} - -TEST_F(ClangIpcServer, GetProjectPartDoesNotExistForCompletingProjectPartFile) -{ - Utf8String inexistingProjectPartFilePath = Utf8StringLiteral("projectpartsdoesnotexist.pro"); - CompleteCodeCommand completeCodeCommand(variableTestFilePath, - 20, - 1, - inexistingProjectPartFilePath); - ProjectPartsDoNotExistCommand projectPartsDoNotExistCommand({inexistingProjectPartFilePath}); - - EXPECT_CALL(mockIpcClient, projectPartsDoNotExist(projectPartsDoNotExistCommand)) - .Times(1); - - clangServer.completeCode(completeCodeCommand); -} - -TEST_F(ClangIpcServer, GetProjectPartDoesNotExistForCompletingUnregisteredFile) -{ - CompleteCodeCommand completeCodeCommand(parseErrorTestFilePath, - 20, - 1, - projectPartId); - TranslationUnitDoesNotExistCommand translationUnitDoesNotExistCommand(parseErrorTestFilePath, projectPartId); - - EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(translationUnitDoesNotExistCommand)) - .Times(1); - - clangServer.completeCode(completeCodeCommand); -} - -TEST_F(ClangIpcServer, TicketNumberIsForwarded) -{ - CompleteCodeCommand completeCodeCommand(functionTestFilePath, - 20, - 1, - projectPartId); - CodeCompletion codeCompletion(Utf8StringLiteral("Function"), - Utf8String(), - Utf8String(), - 34, - CodeCompletion::FunctionCompletionKind); - - EXPECT_CALL(mockIpcClient, codeCompleted(Property(&CodeCompletedCommand::ticketNumber, Eq(completeCodeCommand.ticketNumber())))) - .Times(1); - - clangServer.completeCode(completeCodeCommand); -} -} diff --git a/tests/unit/codemodelbackend/unittest/clangstringtest.cpp b/tests/unit/codemodelbackend/unittest/clangstringtest.cpp deleted file mode 100644 index 0e0a233dd6..0000000000 --- a/tests/unit/codemodelbackend/unittest/clangstringtest.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gmock/gmock.h" -#include "gtest-qt-printing.h" - -#include -#include - -#include -#include - -namespace { - -using CodeModelBackEnd::ClangString; - -TEST(ClangString, ConvertToUtf8String) -{ - const CXString cxString = { "text", 0}; - - ASSERT_THAT(Utf8String(ClangString(cxString)), Utf8StringLiteral("text")); -} - -TEST(ClangString, ConvertNullStringToUtf8String) -{ - const CXString cxString = { 0, 0}; - - ASSERT_THAT(Utf8String(ClangString(cxString)), Utf8String()); -} - -TEST(ClangString, MoveClangString) -{ - ClangString text(CXString{ "text", 0}); - - const ClangString text2 = std::move(text); - - ASSERT_TRUE(text.isNull()); - ASSERT_FALSE(text2.isNull()); -} - -} diff --git a/tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp b/tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp deleted file mode 100644 index 58961bd8bf..0000000000 --- a/tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gmock/gmock.h" - -#include "gtest-qt-printing.h" -#include "translationunitdoesnotexistcommand.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "mockipclient.h" -#include "mockipcserver.h" - -using namespace CodeModelBackEnd; - -namespace { - -using ::testing::Args; -using ::testing::Property; -using ::testing::Eq; - -class ClientServerInProcess : public ::testing::Test -{ -protected: - ClientServerInProcess(); - - void SetUp(); - void TearDown(); - - - void scheduleServerCommands(); - void scheduleClientCommands(); - - QBuffer buffer; - MockIpcClient mockIpcClient; - MockIpcServer mockIpcServer; - - CodeModelBackEnd::IpcServerProxy serverProxy; - CodeModelBackEnd::IpcClientProxy clientProxy; -}; - -TEST_F(ClientServerInProcess, SendEndCommand) -{ - EXPECT_CALL(mockIpcServer, end()) - .Times(1); - - serverProxy.end(); - scheduleServerCommands(); -} - -TEST_F(ClientServerInProcess, SendAliveCommand) -{ - EXPECT_CALL(mockIpcClient, alive()) - .Times(1); - - clientProxy.alive(); - scheduleClientCommands(); -} - -TEST_F(ClientServerInProcess, SendRegisterTranslationUnitForCodeCompletionCommand) -{ - CodeModelBackEnd::FileContainer fileContainer(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"), - Utf8StringLiteral("pathToProjectPart.pro")); - CodeModelBackEnd::RegisterTranslationUnitForCodeCompletionCommand command({fileContainer}); - - EXPECT_CALL(mockIpcServer, registerTranslationUnitsForCodeCompletion(command)) - .Times(1); - - serverProxy.registerTranslationUnitsForCodeCompletion(command); - scheduleServerCommands(); -} - -TEST_F(ClientServerInProcess, SendUnregisterTranslationUnitsForCodeCompletionCommand) -{ - CodeModelBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("pathToProjectPart.pro")); - CodeModelBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand command({fileContainer}); - - EXPECT_CALL(mockIpcServer, unregisterTranslationUnitsForCodeCompletion(command)) - .Times(1); - - serverProxy.unregisterTranslationUnitsForCodeCompletion(command); - scheduleServerCommands(); -} - -TEST_F(ClientServerInProcess, SendCompleteCodeCommand) -{ - CodeModelBackEnd::CompleteCodeCommand command(Utf8StringLiteral("foo.cpp"), 24, 33, Utf8StringLiteral("do what I want")); - - EXPECT_CALL(mockIpcServer, completeCode(command)) - .Times(1); - - serverProxy.completeCode(command); - scheduleServerCommands(); -} - -TEST_F(ClientServerInProcess, SendCodeCompletedCommand) -{ - QVector codeCompletions({Utf8StringLiteral("newFunction()")}); - CodeModelBackEnd::CodeCompletedCommand command(codeCompletions, 1); - - EXPECT_CALL(mockIpcClient, codeCompleted(command)) - .Times(1); - - clientProxy.codeCompleted(command); - scheduleClientCommands(); -} - -TEST_F(ClientServerInProcess, SendRegisterProjectPartsForCodeCompletionCommand) -{ - CodeModelBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral(TESTDATA_DIR"/complete.pro")); - CodeModelBackEnd::RegisterProjectPartsForCodeCompletionCommand command({projectContainer}); - - EXPECT_CALL(mockIpcServer, registerProjectPartsForCodeCompletion(command)) - .Times(1); - - serverProxy.registerProjectPartsForCodeCompletion(command); - scheduleServerCommands(); -} - -TEST_F(ClientServerInProcess, SendUnregisterProjectPartsForCodeCompletionCommand) -{ - CodeModelBackEnd::UnregisterProjectPartsForCodeCompletionCommand command({Utf8StringLiteral(TESTDATA_DIR"/complete.pro")}); - - EXPECT_CALL(mockIpcServer, unregisterProjectPartsForCodeCompletion(command)) - .Times(1); - - serverProxy.unregisterProjectPartsForCodeCompletion(command); - scheduleServerCommands(); -} - -TEST_F(ClientServerInProcess, SendTranslationUnitDoesNotExistCommand) -{ - CodeModelBackEnd::FileContainer fileContainer(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"), - Utf8StringLiteral("pathToProjectPart.pro")); - CodeModelBackEnd::TranslationUnitDoesNotExistCommand command(fileContainer); - - EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(command)) - .Times(1); - - clientProxy.translationUnitDoesNotExist(command); - scheduleClientCommands(); -} - - -TEST_F(ClientServerInProcess, SendProjectPartDoesNotExistCommand) -{ - CodeModelBackEnd::ProjectPartsDoNotExistCommand command({Utf8StringLiteral("pathToProjectPart.pro")}); - - EXPECT_CALL(mockIpcClient, projectPartsDoNotExist(command)) - .Times(1); - - clientProxy.projectPartsDoNotExist(command); - scheduleClientCommands(); -} -ClientServerInProcess::ClientServerInProcess() - : serverProxy(&mockIpcClient, &buffer), - clientProxy(&mockIpcServer, &buffer) -{ -} - -void ClientServerInProcess::SetUp() -{ - buffer.open(QIODevice::ReadWrite); -} - -void ClientServerInProcess::TearDown() -{ - buffer.close(); -} - -void ClientServerInProcess::scheduleServerCommands() -{ - buffer.seek(0); - clientProxy.readCommands(); - buffer.buffer().clear(); -} - -void ClientServerInProcess::scheduleClientCommands() -{ - buffer.seek(0); - serverProxy.readCommands(); - buffer.buffer().clear(); -} - -} diff --git a/tests/unit/codemodelbackend/unittest/clientserveroutsideprocess.cpp b/tests/unit/codemodelbackend/unittest/clientserveroutsideprocess.cpp deleted file mode 100644 index 98553c3faa..0000000000 --- a/tests/unit/codemodelbackend/unittest/clientserveroutsideprocess.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gmock/gmock.h" - -#include -#include -#include -#include -#include - -#include - -#include "gtest-qt-printing.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#ifdef Q_OS_WIN -#define QTC_HOST_EXE_SUFFIX L".exe" -#else -#define QTC_HOST_EXE_SUFFIX "" -#endif - -using namespace CodeModelBackEnd; - -using ::testing::Eq; - -class ClientServerOutsideProcess : public ::testing::Test -{ -protected: - void SetUp(); - void TearDown(); - - static void SetUpTestCase(); - static void TearDownTestCase(); - - static MockIpcClient mockIpcClient; - static CodeModelBackEnd::ConnectionClient client; -}; - -MockIpcClient ClientServerOutsideProcess::mockIpcClient; -CodeModelBackEnd::ConnectionClient ClientServerOutsideProcess::client(&ClientServerOutsideProcess::mockIpcClient); - -TEST_F(ClientServerOutsideProcess, RestartProcess) -{ - client.restartProcess(); - - ASSERT_TRUE(client.isProcessIsRunning()); - ASSERT_TRUE(client.isConnected()); -} - -TEST_F(ClientServerOutsideProcess, RestartProcessAfterAliveTimeout) -{ - QSignalSpy clientSpy(&client, SIGNAL(processRestarted())); - - client.setProcessAliveTimerInterval(1); - - ASSERT_TRUE(clientSpy.wait(100000)); -} - -TEST_F(ClientServerOutsideProcess, RestartProcessAfterTermination) -{ - QSignalSpy clientSpy(&client, SIGNAL(processRestarted())); - - client.processForTestOnly()->kill(); - - ASSERT_TRUE(clientSpy.wait(100000)); -} - -TEST_F(ClientServerOutsideProcess, SendRegisterTranslationUnitForCodeCompletionCommand) -{ - CodeModelBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo"), Utf8StringLiteral("pathToProjectPart.pro")); - CodeModelBackEnd::RegisterTranslationUnitForCodeCompletionCommand registerTranslationUnitForCodeCompletionCommand({fileContainer}); - EchoCommand echoCommand(QVariant::fromValue(registerTranslationUnitForCodeCompletionCommand)); - - EXPECT_CALL(mockIpcClient, echo(echoCommand)) - .Times(1); - - client.serverProxy().registerTranslationUnitsForCodeCompletion(registerTranslationUnitForCodeCompletionCommand); - ASSERT_TRUE(client.waitForEcho()); -} - -TEST_F(ClientServerOutsideProcess, SendUnregisterTranslationUnitsForCodeCompletionCommand) -{ - FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("bar.pro")); - CodeModelBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand unregisterTranslationUnitsForCodeCompletionCommand ({fileContainer}); - EchoCommand echoCommand(QVariant::fromValue(unregisterTranslationUnitsForCodeCompletionCommand)); - - EXPECT_CALL(mockIpcClient, echo(echoCommand)) - .Times(1); - - client.serverProxy().unregisterTranslationUnitsForCodeCompletion(unregisterTranslationUnitsForCodeCompletionCommand); - ASSERT_TRUE(client.waitForEcho()); -} - -TEST_F(ClientServerOutsideProcess, SendCompleteCodeCommand) -{ - CompleteCodeCommand codeCompleteCommand(Utf8StringLiteral("foo.cpp"), 24, 33, Utf8StringLiteral("do what I want")); - EchoCommand echoCommand(QVariant::fromValue(codeCompleteCommand)); - - EXPECT_CALL(mockIpcClient, echo(echoCommand)) - .Times(1); - - client.serverProxy().completeCode(codeCompleteCommand); - ASSERT_TRUE(client.waitForEcho()); -} - -TEST_F(ClientServerOutsideProcess, SendRegisterProjectPartsForCodeCompletionCommand) -{ - CodeModelBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral(TESTDATA_DIR"/complete.pro")); - CodeModelBackEnd::RegisterProjectPartsForCodeCompletionCommand registerProjectPartsForCodeCompletionCommand({projectContainer}); - EchoCommand echoCommand(QVariant::fromValue(registerProjectPartsForCodeCompletionCommand)); - - EXPECT_CALL(mockIpcClient, echo(echoCommand)) - .Times(1); - - client.serverProxy().registerProjectPartsForCodeCompletion(registerProjectPartsForCodeCompletionCommand); - ASSERT_TRUE(client.waitForEcho()); -} - -TEST_F(ClientServerOutsideProcess, SendUnregisterProjectPartsForCodeCompletionCommand) -{ - CodeModelBackEnd::UnregisterProjectPartsForCodeCompletionCommand unregisterProjectPartsForCodeCompletionCommand({Utf8StringLiteral(TESTDATA_DIR"/complete.pro")}); - EchoCommand echoCommand(QVariant::fromValue(unregisterProjectPartsForCodeCompletionCommand)); - - EXPECT_CALL(mockIpcClient, echo(echoCommand)) - .Times(1); - - client.serverProxy().unregisterProjectPartsForCodeCompletion(unregisterProjectPartsForCodeCompletionCommand); - ASSERT_TRUE(client.waitForEcho()); -} - -void ClientServerOutsideProcess::SetUpTestCase() -{ - client.setProcessPath(QStringLiteral(ECHOSERVER QTC_HOST_EXE_SUFFIX)); - - ASSERT_TRUE(client.connectToServer()); -} - -void ClientServerOutsideProcess::TearDownTestCase() -{ - client.finishProcess(); -} -void ClientServerOutsideProcess::SetUp() -{ - client.setProcessAliveTimerInterval(1000000); - - ASSERT_TRUE(client.isConnected()); -} - -void ClientServerOutsideProcess::TearDown() -{ - ASSERT_TRUE(client.isProcessIsRunning()); - ASSERT_TRUE(client.isConnected()); -} diff --git a/tests/unit/codemodelbackend/unittest/codecompletionsextractortest.cpp b/tests/unit/codemodelbackend/unittest/codecompletionsextractortest.cpp deleted file mode 100644 index 0e88a7ebee..0000000000 --- a/tests/unit/codemodelbackend/unittest/codecompletionsextractortest.cpp +++ /dev/null @@ -1,663 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" - -#include "gmock/gmock-matchers.h" -#include "gmock/gmock-generated-matchers.h" -#include "gtest-qt-printing.h" - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -using CodeModelBackEnd::CodeCompletionsExtractor; -using CodeModelBackEnd::ClangCodeCompleteResults; -using CodeModelBackEnd::TranslationUnit; -using CodeModelBackEnd::CodeCompletion; -using CodeModelBackEnd::UnsavedFiles; -using CodeModelBackEnd::CodeCompletionChunk; - - - -namespace { - -using ::testing::PrintToString; -using ::testing::Not; - -MATCHER_P3(HasCompletion, name, kind, availability, - std::string(negation ? "hasn't" : "has") + " completion of name " + PrintToString(name) + - ", kind " + PrintToString(kind)) -{ - ::CodeCompletionsExtractor &extractor = const_cast<::CodeCompletionsExtractor&>(arg); - while (extractor.next()) { - if (extractor.currentCodeCompletion().text() == name) { - if (extractor.currentCodeCompletion().completionKind() == kind) { - if (extractor.currentCodeCompletion().availability() == availability) { - return true; - } else if (!extractor.peek(name)) { - *result_listener << "availability is " << PrintToString(extractor.currentCodeCompletion().availability()) << " and not " << PrintToString(availability); - return false; - } - } else if (!extractor.peek(name)) { - *result_listener << "kind is " << PrintToString(extractor.currentCodeCompletion().completionKind()) << " and not " << PrintToString(kind); - return false; - } - } - } - - return false; -} - -MATCHER_P2(HasCompletionChunks, name, chunks, - std::string(negation ? "hasn't" : "has") + " completion of name " + PrintToString(name) + - " with the chunks " + PrintToString(chunks)) -{ - ::CodeCompletionsExtractor &extractor = const_cast<::CodeCompletionsExtractor&>(arg); - while (extractor.next()) { - if (extractor.currentCodeCompletion().text() == name) { - if (extractor.currentCodeCompletion().chunks() == chunks) { - return true; - } else if (!extractor.peek(name)) { - *result_listener << "chunks are " << PrintToString(arg.currentCodeCompletion().chunks()) << " and not " << PrintToString(chunks); - return false; - } - } - } - - return false; -} - -const Utf8String unsavedFileContent(const char *unsavedFilePath) -{ - QFile unsavedFileContentFile(QString::fromUtf8(unsavedFilePath)); - bool isOpen = unsavedFileContentFile.open(QIODevice::ReadOnly | QIODevice::Text); - if (!isOpen) - ADD_FAILURE() << "File with the unsaved content cannot be opened!"; - - return Utf8String::fromByteArray(unsavedFileContentFile.readAll()); -} - -const CodeModelBackEnd::FileContainer unsavedDataFileContainer(const char *filePath, - const char *unsavedFilePath) -{ - return CodeModelBackEnd::FileContainer(Utf8String::fromUtf8(filePath), - Utf8String(), - unsavedFileContent(unsavedFilePath), - true); -} - -ClangCodeCompleteResults getResults(const TranslationUnit &translationUnit, uint line, uint column = 1) -{ - return ClangCodeCompleteResults(clang_codeCompleteAt(translationUnit.cxTranslationUnit(), - translationUnit.filePath().constData(), - line, - column, - translationUnit.cxUnsavedFiles(), - translationUnit.unsavedFilesCount(), - CXCodeComplete_IncludeMacros | CXCodeComplete_IncludeCodePatterns)); -} - -class CodeCompletionsExtractor : public ::testing::Test -{ -public: - static void TearDownTestCase(); - -protected: - static CodeModelBackEnd::ProjectPart project; - static CodeModelBackEnd::UnsavedFiles unsavedFiles; - static TranslationUnit functionTranslationUnit; - static TranslationUnit variableTranslationUnit; - static TranslationUnit classTranslationUnit ; - static TranslationUnit namespaceTranslationUnit; - static TranslationUnit enumerationTranslationUnit; - static TranslationUnit constructorTranslationUnit; -}; - -CodeModelBackEnd::ProjectPart CodeCompletionsExtractor::project(Utf8StringLiteral("/path/to/projectfile")); -CodeModelBackEnd::UnsavedFiles CodeCompletionsExtractor::unsavedFiles; -TranslationUnit CodeCompletionsExtractor::functionTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"), unsavedFiles, project); -TranslationUnit CodeCompletionsExtractor::variableTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp"), unsavedFiles, project); -TranslationUnit CodeCompletionsExtractor::classTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_class.cpp"), unsavedFiles, project); -TranslationUnit CodeCompletionsExtractor::namespaceTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_namespace.cpp"), unsavedFiles, project); -TranslationUnit CodeCompletionsExtractor::enumerationTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_enumeration.cpp"), unsavedFiles, project); -TranslationUnit CodeCompletionsExtractor::constructorTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_constructor.cpp"), unsavedFiles, project); - -void CodeCompletionsExtractor::TearDownTestCase() -{ - functionTranslationUnit.reset(); - variableTranslationUnit.reset(); - classTranslationUnit.reset(); - namespaceTranslationUnit.reset(); - enumerationTranslationUnit.reset(); - constructorTranslationUnit.reset(); -} - -TEST_F(CodeCompletionsExtractor, Function) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Function"), - CodeCompletion::FunctionCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, TemplateFunction) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("TemplateFunction"), - CodeCompletion::TemplateFunctionCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Variable) -{ - ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 4)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Var"), - CodeCompletion::VariableCompletionKind, - CodeCompletion::Available)); -} - - -TEST_F(CodeCompletionsExtractor, NonTypeTemplateParameter) -{ - ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 25, 19)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("NonTypeTemplateParameter"), - CodeCompletion::VariableCompletionKind, - CodeCompletion::Available)); -} - - -TEST_F(CodeCompletionsExtractor, VariableReference) -{ - ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 12)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Var"), - CodeCompletion::VariableCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Parameter) -{ - ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 4)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Parameter"), - CodeCompletion::VariableCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Field) -{ - ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Field"), - CodeCompletion::VariableCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Class) -{ - ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Class"), - CodeCompletion::ClassCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Struct) -{ - ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Struct"), - CodeCompletion::ClassCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Union) -{ - ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Union"), - CodeCompletion::ClassCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, TemplateTypeParameter) -{ - ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("TemplateTypeParameter"), - CodeCompletion::ClassCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, TemplateClass) -{ - ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("TemplateClass"), - CodeCompletion::TemplateClassCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, TemplateTemplateParameter) -{ - ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("TemplateTemplateParameter"), - CodeCompletion::TemplateClassCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, ClassTemplatePartialSpecialization) -{ - ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("ClassTemplatePartialSpecialization"), - CodeCompletion::TemplateClassCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Namespace) -{ - ClangCodeCompleteResults completeResults(getResults(namespaceTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Namespace"), - CodeCompletion::NamespaceCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, NamespaceAlias) -{ - ClangCodeCompleteResults completeResults(getResults(namespaceTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("NamespaceAlias"), - CodeCompletion::NamespaceCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Enumeration) -{ - ClangCodeCompleteResults completeResults(getResults(enumerationTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Enumeration"), - CodeCompletion::EnumerationCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Enumerator) -{ - ClangCodeCompleteResults completeResults(getResults(enumerationTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Enumerator"), - CodeCompletion::EnumeratorCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Constructor) -{ - ClangCodeCompleteResults completeResults(getResults(constructorTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Constructor"), - CodeCompletion::ConstructorCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Destructor) -{ - ClangCodeCompleteResults completeResults(getResults(constructorTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("~Constructor"), - CodeCompletion::DestructorCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Method) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Method"), - CodeCompletion::FunctionCompletionKind, - CodeCompletion::Available)); - ASSERT_FALSE(extractor.currentCodeCompletion().hasParameters()); -} - -TEST_F(CodeCompletionsExtractor, MethodWithParameters) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("MethodWithParameters"), - CodeCompletion::FunctionCompletionKind, - CodeCompletion::Available)); - ASSERT_TRUE(extractor.currentCodeCompletion().hasParameters()); -} - -TEST_F(CodeCompletionsExtractor, Slot) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Slot"), - CodeCompletion::SlotCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, Signal) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Signal"), - CodeCompletion::SignalCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, MacroDefinition) -{ - ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("MacroDefinition"), - CodeCompletion::PreProcessorCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, FunctionMacro) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("FunctionMacro"), - CodeCompletion::FunctionCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, IntKeyword) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("int"), - CodeCompletion::KeywordCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, SwitchKeyword) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("switch"), - CodeCompletion::KeywordCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, ClassKeyword) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("class"), - CodeCompletion::KeywordCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, DeprecatedFunction) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("DeprecatedFunction"), - CodeCompletion::FunctionCompletionKind, - CodeCompletion::Deprecated)); -} - -TEST_F(CodeCompletionsExtractor, NotAccessibleFunction) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("NotAccessibleFunction"), - CodeCompletion::FunctionCompletionKind, - CodeCompletion::NotAccessible)); -} - -TEST_F(CodeCompletionsExtractor, NotAvailableFunction) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("NotAvailableFunction"), - CodeCompletion::FunctionCompletionKind, - CodeCompletion::NotAvailable)); -} - -TEST_F(CodeCompletionsExtractor, UnsavedFile) -{ - CodeModelBackEnd::UnsavedFiles unsavedFiles; - CodeModelBackEnd::ProjectPart project(Utf8StringLiteral("/path/to/projectfile")); - TranslationUnit translationUnit(Utf8String::fromUtf8(TESTDATA_DIR"/complete_extractor_function.cpp"), unsavedFiles, project); - unsavedFiles.createOrUpdate({unsavedDataFileContainer(TESTDATA_DIR"/complete_extractor_function.cpp", - TESTDATA_DIR"/complete_extractor_function_unsaved.cpp")}); - ClangCodeCompleteResults completeResults(getResults(translationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Method2"), - CodeCompletion::FunctionCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, ChangeUnsavedFile) -{ - CodeModelBackEnd::UnsavedFiles unsavedFiles; - CodeModelBackEnd::ProjectPart project(Utf8StringLiteral("/path/to/projectfile")); - TranslationUnit translationUnit(Utf8String::fromUtf8(TESTDATA_DIR"/complete_extractor_function.cpp"), unsavedFiles, project); - unsavedFiles.createOrUpdate({unsavedDataFileContainer(TESTDATA_DIR"/complete_extractor_function.cpp", - TESTDATA_DIR"/complete_extractor_function_unsaved.cpp")}); - ClangCodeCompleteResults completeResults(getResults(translationUnit, 20)); - unsavedFiles.createOrUpdate({unsavedDataFileContainer(TESTDATA_DIR"/complete_extractor_function.cpp", - TESTDATA_DIR"/complete_extractor_function_unsaved_2.cpp")}); - completeResults = getResults(translationUnit, 20); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Method3"), - CodeCompletion::FunctionCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, ArgumentDefinition) -{ - variableTranslationUnit.cxTranslationUnit(); - project.setArguments({Utf8StringLiteral("-DArgumentDefinition")}); - ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("ArgumentDefinitionVariable"), - CodeCompletion::VariableCompletionKind, - CodeCompletion::Available)); -} - -TEST_F(CodeCompletionsExtractor, NoArgumentDefinition) -{ - variableTranslationUnit.cxTranslationUnit(); - project.setArguments(Utf8StringVector()); - ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, Not(HasCompletion(Utf8StringLiteral("ArgumentDefinitionVariable"), - CodeCompletion::VariableCompletionKind, - CodeCompletion::Available))); -} - -TEST_F(CodeCompletionsExtractor, CompletionChunksFunction) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Function"), - QVector({{CodeCompletionChunk::ResultType, Utf8StringLiteral("void")}, - {CodeCompletionChunk::TypedText, Utf8StringLiteral("Function")}, - {CodeCompletionChunk::LeftParen, Utf8StringLiteral("(")}, - {CodeCompletionChunk::RightParen, Utf8StringLiteral(")")}}))); -} - -TEST_F(CodeCompletionsExtractor, CompletionChunksFunctionWithOptionalChunks) -{ - ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("FunctionWithOptional"), - QVector({{CodeCompletionChunk::ResultType, Utf8StringLiteral("void")}, - {CodeCompletionChunk::TypedText, Utf8StringLiteral("FunctionWithOptional")}, - {CodeCompletionChunk::LeftParen, Utf8StringLiteral("(")}, - {CodeCompletionChunk::Placeholder, Utf8StringLiteral("int x")}, - {CodeCompletionChunk::Optional, Utf8String(), QVector({ - {CodeCompletionChunk::Comma, Utf8StringLiteral(", ")}, - {CodeCompletionChunk::Placeholder, Utf8StringLiteral("char y")}, - {CodeCompletionChunk::Comma, Utf8StringLiteral(", ")}, - {CodeCompletionChunk::Placeholder, Utf8StringLiteral("int z")}})}, - {CodeCompletionChunk::RightParen, Utf8StringLiteral(")")}}))); -} - -TEST_F(CodeCompletionsExtractor, CompletionChunksField) -{ - ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Field"), - QVector({{CodeCompletionChunk::ResultType, Utf8StringLiteral("int")}, - {CodeCompletionChunk::TypedText, Utf8StringLiteral("Field")}}))); -} - -TEST_F(CodeCompletionsExtractor, CompletionChunksEnumerator) -{ - ClangCodeCompleteResults completeResults(getResults(enumerationTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Enumerator"), - QVector({{CodeCompletionChunk::ResultType, Utf8StringLiteral("Enumeration")}, - {CodeCompletionChunk::TypedText, Utf8StringLiteral("Enumerator")}}))); -} - -TEST_F(CodeCompletionsExtractor, CompletionChunksEnumeration) -{ - ClangCodeCompleteResults completeResults(getResults(enumerationTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Enumeration"), - QVector({{CodeCompletionChunk::TypedText, Utf8StringLiteral("Enumeration")}}))); -} - -TEST_F(CodeCompletionsExtractor, CompletionChunksClass) -{ - ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); - - ::CodeCompletionsExtractor extractor(completeResults.data()); - - ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Class"), - QVector({{CodeCompletionChunk::TypedText, Utf8StringLiteral("Class")}}))); -} - - -} diff --git a/tests/unit/codemodelbackend/unittest/codecompletiontest.cpp b/tests/unit/codemodelbackend/unittest/codecompletiontest.cpp deleted file mode 100644 index a92d176773..0000000000 --- a/tests/unit/codemodelbackend/unittest/codecompletiontest.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gtest-qt-printing.h" - -#include -#include -#include -#include -#include -#include - -#include - - -using ::testing::ElementsAreArray; -using ::testing::Contains; -using ::testing::AllOf; -using ::testing::Not; - -using CodeModelBackEnd::CodeCompletion; -using CodeModelBackEnd::CodeCompleter; - -namespace { - -class CodeCompleter : public ::testing::Test -{ -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - -protected: - static CodeModelBackEnd::ProjectPart projectPart; - static CodeModelBackEnd::UnsavedFiles unsavedFiles; - static CodeModelBackEnd::TranslationUnit translationUnit; - static CodeModelBackEnd::CodeCompleter completer; -}; - -CodeModelBackEnd::ProjectPart CodeCompleter::projectPart(Utf8StringLiteral("projectPartId")); -CodeModelBackEnd::UnsavedFiles CodeCompleter::unsavedFiles; -CodeModelBackEnd::TranslationUnit CodeCompleter::translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_completer.cpp"), unsavedFiles, projectPart); -CodeModelBackEnd::CodeCompleter CodeCompleter::completer = translationUnit; - -void CodeCompleter::SetUpTestCase() -{ - QFile unsavedFileContentFile(QStringLiteral(TESTDATA_DIR) + QStringLiteral("/complete_completer_unsaved.cpp")); - unsavedFileContentFile.open(QIODevice::ReadOnly); - - const Utf8String unsavedFileContent = Utf8String::fromByteArray(unsavedFileContentFile.readAll()); - const CodeModelBackEnd::FileContainer unsavedDataFileContainer(translationUnit.filePath(), - projectPart.projectPartId(), - unsavedFileContent, - true); - - unsavedFiles.createOrUpdate({unsavedDataFileContainer}); -} - -void CodeCompleter::TearDownTestCase() -{ - translationUnit.reset(); - completer = CodeModelBackEnd::CodeCompleter(); -} - - -TEST_F(CodeCompleter, FunctionInUnsavedFile) -{ - ASSERT_THAT(completer.complete(100, 1), - AllOf(Contains(CodeCompletion(Utf8StringLiteral("functionWithArguments"), - Utf8String(), - Utf8String(), - 0, - CodeCompletion::FunctionCompletionKind)), - Contains(CodeCompletion(Utf8StringLiteral("function"), - Utf8String(), - Utf8String(), - 0, - CodeCompletion::FunctionCompletionKind)), - Contains(CodeCompletion(Utf8StringLiteral("newFunction"), - Utf8String(), - Utf8String(), - 0, - CodeCompletion::FunctionCompletionKind)), - Contains(CodeCompletion(Utf8StringLiteral("f"), - Utf8String(), - Utf8String(), - 0, - CodeCompletion::FunctionCompletionKind)), - Not(Contains(CodeCompletion(Utf8StringLiteral("otherFunction"), - Utf8String(), - Utf8String(), - 0, - CodeCompletion::FunctionCompletionKind))))); -} - - -TEST_F(CodeCompleter, Macro) -{ - ASSERT_THAT(completer.complete(100, 1), - Contains(CodeCompletion(Utf8StringLiteral("Macro"), - Utf8String(), - Utf8String(), - 0, - CodeCompletion::PreProcessorCompletionKind))); -} - -TEST_F(CodeCompleter, Keyword) -{ - ASSERT_THAT(completer.complete(100, 1), - Contains(CodeCompletion(Utf8StringLiteral("switch"), - Utf8String(), - Utf8String(), - 0, - CodeCompletion::KeywordCompletionKind))); -} - - -} - - diff --git a/tests/unit/codemodelbackend/unittest/completionchunkstotextconvertertest.cpp b/tests/unit/codemodelbackend/unittest/completionchunkstotextconvertertest.cpp deleted file mode 100644 index 7d43af8c59..0000000000 --- a/tests/unit/codemodelbackend/unittest/completionchunkstotextconvertertest.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gmock/gmock-generated-matchers.h" -#include "gtest-qt-printing.h" - -#include -#include - -namespace { - -using CodeModelBackEnd::CodeCompletionChunk; - -class CompletionChunksToTextConverter : public ::testing::Test -{ -protected: - ClangCodeModel::Internal::CompletionChunksToTextConverter converter; - CodeCompletionChunk integerResultType{CodeCompletionChunk::ResultType, Utf8StringLiteral("int")}; - CodeCompletionChunk enumerationResultType{CodeCompletionChunk::ResultType, Utf8StringLiteral("Enumeration")}; - CodeCompletionChunk functionName{CodeCompletionChunk::TypedText, Utf8StringLiteral("Function")}; - CodeCompletionChunk variableName{CodeCompletionChunk::TypedText, Utf8StringLiteral("Variable")}; - CodeCompletionChunk enumeratorName{CodeCompletionChunk::TypedText, Utf8StringLiteral("Enumerator")}; - CodeCompletionChunk enumerationName{CodeCompletionChunk::TypedText, Utf8StringLiteral("Enumeration")}; - CodeCompletionChunk className{CodeCompletionChunk::TypedText, Utf8StringLiteral("Class")}; - CodeCompletionChunk leftParen{CodeCompletionChunk::LeftParen, Utf8StringLiteral("(")}; - CodeCompletionChunk rightParen{CodeCompletionChunk::LeftParen, Utf8StringLiteral(")")}; - CodeCompletionChunk comma{CodeCompletionChunk::Comma, Utf8StringLiteral(", ")}; - CodeCompletionChunk functionArgumentX{CodeCompletionChunk::Placeholder, Utf8StringLiteral("char x")}; - CodeCompletionChunk functionArgumentY{CodeCompletionChunk::Placeholder, Utf8StringLiteral("int y")}; - CodeCompletionChunk functionArgumentZ{CodeCompletionChunk::Placeholder, Utf8StringLiteral("int z")}; - CodeCompletionChunk optional{CodeCompletionChunk::Optional, Utf8String(), {comma, functionArgumentY, comma, functionArgumentZ}}; -}; - -TEST_F(CompletionChunksToTextConverter, ParseIsClearingText) -{ - QVector completionChunks({integerResultType, functionName, leftParen, rightParen}); - converter.parseChunks(completionChunks); - - converter.parseChunks(completionChunks); - - ASSERT_THAT(converter.text(), QStringLiteral("int Function()")); -} - -TEST_F(CompletionChunksToTextConverter, ConvertFunction) -{ - QVector completionChunks({integerResultType, functionName, leftParen, rightParen}); - - converter.parseChunks(completionChunks); - - ASSERT_THAT(converter.text(), QStringLiteral("int Function()")); -} - -TEST_F(CompletionChunksToTextConverter, ConvertFunctionWithParameters) -{ - QVector completionChunks({integerResultType, functionName, leftParen, functionArgumentX,rightParen}); - - converter.parseChunks(completionChunks); - - ASSERT_THAT(converter.text(), QStringLiteral("int Function(char x)")); -} - -TEST_F(CompletionChunksToTextConverter, ConvertFunctionWithOptionalParameter) -{ - QVector completionChunks({integerResultType, functionName, leftParen, functionArgumentX, optional,rightParen}); - - converter.parseChunks(completionChunks); - - ASSERT_THAT(converter.text(), QStringLiteral("int Function(char x, int y, int z)")); -} - -TEST_F(CompletionChunksToTextConverter, ConvertVariable) -{ - QVector completionChunks({integerResultType, variableName}); - - converter.parseChunks(completionChunks); - - ASSERT_THAT(converter.text(), QStringLiteral("int Variable")); -} - -TEST_F(CompletionChunksToTextConverter, Enumerator) -{ - QVector completionChunks({enumerationResultType, enumeratorName}); - - converter.parseChunks(completionChunks); - - ASSERT_THAT(converter.text(), QStringLiteral("Enumeration Enumerator")); -} - -TEST_F(CompletionChunksToTextConverter, Enumeration) -{ - QVector completionChunks({className}); - - converter.parseChunks(completionChunks); - - ASSERT_THAT(converter.text(), QStringLiteral("Class")); -} - -} diff --git a/tests/unit/codemodelbackend/unittest/createtablesqlstatementbuildertest.cpp b/tests/unit/codemodelbackend/unittest/createtablesqlstatementbuildertest.cpp deleted file mode 100644 index 87dbb84189..0000000000 --- a/tests/unit/codemodelbackend/unittest/createtablesqlstatementbuildertest.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gtest-qt-printing.h" - -#include - -#include -#include - -#include - -class CreateTableSqlStatementBuilder : public ::testing::Test -{ -protected: - void SetUp() override; - - void bindValues(); - static const QVector createColumnDefintions(); - static const Internal::ColumnDefinition createColumnDefintion(const Utf8String &name, - ColumnType type, - bool isPrimaryKey = false); - - Internal::CreateTableSqlStatementBuilder builder; -}; - -TEST_F(CreateTableSqlStatementBuilder, IsNotValidAfterCreation) -{ - ASSERT_FALSE(builder.isValid()); -} - -TEST_F(CreateTableSqlStatementBuilder, IsValidAfterBinding) -{ - bindValues(); - - ASSERT_TRUE(builder.isValid()); -} - -TEST_F(CreateTableSqlStatementBuilder, InvalidAfterClear) -{ - bindValues(); - - builder.clear(); - - ASSERT_TRUE(!builder.isValid()); -} - -TEST_F(CreateTableSqlStatementBuilder, NoSqlStatementAfterClear) -{ - bindValues(); - builder.sqlStatement(); - - builder.clear(); - - ASSERT_THROW(builder.sqlStatement(), SqlStatementBuilderException); -} - -TEST_F(CreateTableSqlStatementBuilder, SqlStatement) -{ - bindValues(); - - ASSERT_THAT(builder.sqlStatement(), - Utf8StringLiteral("CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY, name TEXT, number NUMERIC)"));} - -TEST_F(CreateTableSqlStatementBuilder, AddColumnToExistingColumns) -{ - bindValues(); - - builder.addColumnDefinition(Utf8StringLiteral("number2"), ColumnType::Real); - - ASSERT_THAT(builder.sqlStatement(), - Utf8StringLiteral("CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY, name TEXT, number NUMERIC, number2 REAL)"));} - -TEST_F(CreateTableSqlStatementBuilder, ChangeTable) -{ - bindValues(); - - builder.setTable(Utf8StringLiteral("test2")); - - ASSERT_THAT(builder.sqlStatement(), - Utf8StringLiteral("CREATE TABLE IF NOT EXISTS test2(id INTEGER PRIMARY KEY, name TEXT, number NUMERIC)")); -} - -TEST_F(CreateTableSqlStatementBuilder, IsInvalidAfterClearColumsOnly) -{ - bindValues(); - builder.sqlStatement(); - - builder.clearColumns(); - - ASSERT_THROW(builder.sqlStatement(), SqlStatementBuilderException); -} - -TEST_F(CreateTableSqlStatementBuilder, ClearColumnsAndAddColumnNewColumns) -{ - bindValues(); - builder.clearColumns(); - - builder.addColumnDefinition(Utf8StringLiteral("name3"), ColumnType::Text); - builder.addColumnDefinition(Utf8StringLiteral("number3"), ColumnType::Real); - - ASSERT_THAT(builder.sqlStatement(), - Utf8StringLiteral("CREATE TABLE IF NOT EXISTS test(name3 TEXT, number3 REAL)")); -} - -TEST_F(CreateTableSqlStatementBuilder, SetWitoutRowId) -{ - bindValues(); - - builder.setUseWithoutRowId(true); - - ASSERT_THAT(builder.sqlStatement(), - Utf8StringLiteral("CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY, name TEXT, number NUMERIC) WITHOUT ROWID")); -} - -TEST_F(CreateTableSqlStatementBuilder, SetColumnDefinitions) -{ - builder.clear(); - builder.setTable(Utf8StringLiteral("test")); - - builder.setColumnDefinitions(createColumnDefintions()); - - ASSERT_THAT(builder.sqlStatement(), - Utf8StringLiteral("CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY, name TEXT, number NUMERIC)")); -} - -void CreateTableSqlStatementBuilder::SetUp() -{ - builder = Internal::CreateTableSqlStatementBuilder(); -} - -void CreateTableSqlStatementBuilder::bindValues() -{ - builder.clear(); - builder.setTable(Utf8StringLiteral("test")); - builder.addColumnDefinition(Utf8StringLiteral("id"), ColumnType::Integer, true); - builder.addColumnDefinition(Utf8StringLiteral("name"), ColumnType::Text); - builder.addColumnDefinition(Utf8StringLiteral("number"),ColumnType:: Numeric); -} - -const QVector CreateTableSqlStatementBuilder::createColumnDefintions() -{ - QVector columnDefinitions; - columnDefinitions.append(createColumnDefintion(Utf8StringLiteral("id"), ColumnType::Integer, true)); - columnDefinitions.append(createColumnDefintion(Utf8StringLiteral("name"), ColumnType::Text)); - columnDefinitions.append(createColumnDefintion(Utf8StringLiteral("number"), ColumnType::Numeric)); - - return columnDefinitions; -} - -const Internal::ColumnDefinition CreateTableSqlStatementBuilder::createColumnDefintion(const Utf8String &name, ColumnType type, bool isPrimaryKey) -{ - Internal::ColumnDefinition columnDefinition; - - columnDefinition.setName(name); - columnDefinition.setType(type); - columnDefinition.setIsPrimaryKey(isPrimaryKey); - - return columnDefinition; -} diff --git a/tests/unit/codemodelbackend/unittest/data/complete_completer.cpp b/tests/unit/codemodelbackend/unittest/data/complete_completer.cpp deleted file mode 100644 index a764b7adb4..0000000000 --- a/tests/unit/codemodelbackend/unittest/data/complete_completer.cpp +++ /dev/null @@ -1,101 +0,0 @@ -void function() -{ - -} - -class Foo; -void functionWithArguments(int i, char *c, const Foo &ref) -{ - -} - -void otherFunction() -{ - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void f() -{ - -} diff --git a/tests/unit/codemodelbackend/unittest/data/complete_completer_unsaved.cpp b/tests/unit/codemodelbackend/unittest/data/complete_completer_unsaved.cpp deleted file mode 100644 index 9ec3fed8f4..0000000000 --- a/tests/unit/codemodelbackend/unittest/data/complete_completer_unsaved.cpp +++ /dev/null @@ -1,100 +0,0 @@ -void function() -{ - -} - -class Foo; -void functionWithArguments(int i, char *c, const Foo &ref) -{ - -} - -void newFunction() -{ - -} - -#define Macro - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void f() -{ - -} diff --git a/tests/unit/codemodelbackend/unittest/data/complete_extractor_class.cpp b/tests/unit/codemodelbackend/unittest/data/complete_extractor_class.cpp deleted file mode 100644 index becfdc3292..0000000000 --- a/tests/unit/codemodelbackend/unittest/data/complete_extractor_class.cpp +++ /dev/null @@ -1,21 +0,0 @@ -class Class {}; -struct Struct{}; -union Union{}; -typedef Class TypeDef; -template class TemplateClass{}; -template class ClassTemplatePartialSpecialization; -template class ClassTemplatePartialSpecialization; - - - - - - - - - -template class TemplateTemplateParameter> -void function() -{ - -} diff --git a/tests/unit/codemodelbackend/unittest/data/complete_extractor_constructor.cpp b/tests/unit/codemodelbackend/unittest/data/complete_extractor_constructor.cpp deleted file mode 100644 index e28ccaea82..0000000000 --- a/tests/unit/codemodelbackend/unittest/data/complete_extractor_constructor.cpp +++ /dev/null @@ -1,22 +0,0 @@ -class Constructor { - Constructor(); - ~Constructor(); - - - - - - - - - - - - - - - void function() - { - - } -}; diff --git a/tests/unit/codemodelbackend/unittest/data/complete_extractor_enumeration.cpp b/tests/unit/codemodelbackend/unittest/data/complete_extractor_enumeration.cpp deleted file mode 100644 index 79973a616b..0000000000 --- a/tests/unit/codemodelbackend/unittest/data/complete_extractor_enumeration.cpp +++ /dev/null @@ -1,22 +0,0 @@ -enum Enumeration { - Enumerator -}; - - - - - - - - - - - - - - -void function() -{ - -} - diff --git a/tests/unit/codemodelbackend/unittest/data/complete_extractor_function.cpp b/tests/unit/codemodelbackend/unittest/data/complete_extractor_function.cpp deleted file mode 100644 index a4d34fb04a..0000000000 --- a/tests/unit/codemodelbackend/unittest/data/complete_extractor_function.cpp +++ /dev/null @@ -1,22 +0,0 @@ -void Function(); -template void TemplateFunction(); -void FunctionWithOptional(int x, char y = 1, int z = 5); -#define FunctionMacro(X, Y) X + Y - -class base { - void NotAccessibleFunction(); -}; -class Class : public base { - void Method(); - void MethodWithParameters(int x = 30); - __attribute__((annotate("qt_slot"))) void Slot(); - __attribute__((annotate("qt_signal"))) void Signal(); - __attribute__ ((deprecated)) void DeprecatedFunction(); - void NotAvailableFunction() = delete; - -public: - void function() - { - - } -}; diff --git a/tests/unit/codemodelbackend/unittest/data/complete_extractor_function_unsaved.cpp b/tests/unit/codemodelbackend/unittest/data/complete_extractor_function_unsaved.cpp deleted file mode 100644 index adab53527b..0000000000 --- a/tests/unit/codemodelbackend/unittest/data/complete_extractor_function_unsaved.cpp +++ /dev/null @@ -1,22 +0,0 @@ -void Function(); -template void TemplateFunction(); - -#define FunctionMacro(X, Y) X + Y - -class base { - void NotAccessibleFunction(); -}; -class Class : public base { - void Method2(); - void MethodWithParameters(int x = 30); - __attribute__((annotate("qt_slot"))) void Slot(); - __attribute__((annotate("qt_signal"))) void Signal(); - __attribute__ ((deprecated)) void DeprecatedFunction(); - void NotAvailableFunction() = delete; - -public: - void function() - { - - } -}; diff --git a/tests/unit/codemodelbackend/unittest/data/complete_extractor_function_unsaved_2.cpp b/tests/unit/codemodelbackend/unittest/data/complete_extractor_function_unsaved_2.cpp deleted file mode 100644 index 08153184f4..0000000000 --- a/tests/unit/codemodelbackend/unittest/data/complete_extractor_function_unsaved_2.cpp +++ /dev/null @@ -1,22 +0,0 @@ -void Function(); -template void TemplateFunction(); - -#define FunctionMacro(X, Y) X + Y - -class base { - void NotAccessibleFunction(); -}; -class Class : public base { - void Method3(); - void MethodWithParameters(int x = 30); - __attribute__((annotate("qt_slot"))) void Slot(); - __attribute__((annotate("qt_signal"))) void Signal(); - __attribute__ ((deprecated)) void DeprecatedFunction(); - void NotAvailableFunction() = delete; - -public: - void function() - { - - } -}; diff --git a/tests/unit/codemodelbackend/unittest/data/complete_extractor_namespace.cpp b/tests/unit/codemodelbackend/unittest/data/complete_extractor_namespace.cpp deleted file mode 100644 index 46d273da9d..0000000000 --- a/tests/unit/codemodelbackend/unittest/data/complete_extractor_namespace.cpp +++ /dev/null @@ -1,22 +0,0 @@ -namespace Namespace {} -namespace NamespaceAlias = Namespace; - - - - - - - - - - - - - - - -void function() -{ - -} - diff --git a/tests/unit/codemodelbackend/unittest/data/complete_extractor_variable.cpp b/tests/unit/codemodelbackend/unittest/data/complete_extractor_variable.cpp deleted file mode 100644 index e8a67f9c6c..0000000000 --- a/tests/unit/codemodelbackend/unittest/data/complete_extractor_variable.cpp +++ /dev/null @@ -1,36 +0,0 @@ -void function(int Parameter) -{ - int Var = 0; - -} - -void function2() -{ - int Var = 0; - auto Lambda = [&Var]() - { - - }; -} - -class Class { - int Field; - - void function() { - - } -}; - -template -void function3() {} - -#define MacroDefinition - - -void function4() -{ -#ifdef ArgumentDefinition - int ArgumentDefinitionVariable; -#endif - -} diff --git a/tests/unit/codemodelbackend/unittest/data/complete_testfile_1.cpp b/tests/unit/codemodelbackend/unittest/data/complete_testfile_1.cpp deleted file mode 100644 index 7804bc5fd6..0000000000 --- a/tests/unit/codemodelbackend/unittest/data/complete_testfile_1.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -void function() -{ - -} - -class Foo; -void functionWithArguments(int i, char *c, const Foo &ref) -{ - -} - -void otherFunction() -{ - -} - -void f() -{ - -} diff --git a/tests/unit/codemodelbackend/unittest/data/complete_translationunit_parse_error.cpp b/tests/unit/codemodelbackend/unittest/data/complete_translationunit_parse_error.cpp deleted file mode 100644 index 288cef2a33..0000000000 --- a/tests/unit/codemodelbackend/unittest/data/complete_translationunit_parse_error.cpp +++ /dev/null @@ -1,2 +0,0 @@ -NAMESPACE { - diff --git a/tests/unit/codemodelbackend/unittest/gtest-qt-printing.cpp b/tests/unit/codemodelbackend/unittest/gtest-qt-printing.cpp deleted file mode 100644 index da82cd2595..0000000000 --- a/tests/unit/codemodelbackend/unittest/gtest-qt-printing.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -//#include "gtest-qt-printing.h" diff --git a/tests/unit/codemodelbackend/unittest/gtest-qt-printing.h b/tests/unit/codemodelbackend/unittest/gtest-qt-printing.h deleted file mode 100644 index 353efad9ea..0000000000 --- a/tests/unit/codemodelbackend/unittest/gtest-qt-printing.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include -#include - -#include - -#include - -#ifndef GTESTQTPRINTING_H -#define GTESTQTPRINTING_H - -QT_BEGIN_NAMESPACE -class QVariant; -inline void PrintTo(const QVariant &variant, ::std::ostream *os) -{ - QString output; - QDebug debug(&output); - - debug << variant; - - *os << output.toUtf8().constData(); -} - -inline void PrintTo(const QString &text, ::std::ostream *os) -{ - *os << text.toUtf8().constData(); -} - -QT_END_NAMESPACE - -//namespace testing { -//namespace internal { - -// void PrintTo(const QVariant &variant, ::std::ostream *os); - -//} -//} -#endif // GTESTQTPRINTING_H - diff --git a/tests/unit/codemodelbackend/unittest/main.cpp b/tests/unit/codemodelbackend/unittest/main.cpp deleted file mode 100644 index 09ff5812c8..0000000000 --- a/tests/unit/codemodelbackend/unittest/main.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" - -#include -#include - -#include - -int main(int argc, char *argv[]) -{ - CodeModelBackEnd::Commands::registerCommands(); - Sqlite::registerTypes(); - - QCoreApplication application(argc, argv); - - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/tests/unit/codemodelbackend/unittest/mockipclient.h b/tests/unit/codemodelbackend/unittest/mockipclient.h deleted file mode 100644 index 677daee173..0000000000 --- a/tests/unit/codemodelbackend/unittest/mockipclient.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef MOCKIPCLIENT_H -#define MOCKIPCLIENT_H - -#include - - -class MockIpcClient : public CodeModelBackEnd::IpcClientInterface { - public: - MOCK_METHOD0(alive, - void()); - MOCK_METHOD1(echo, - void(const CodeModelBackEnd::EchoCommand &command)); - MOCK_METHOD1(codeCompleted, - void(const CodeModelBackEnd::CodeCompletedCommand &command)); - MOCK_METHOD1(translationUnitDoesNotExist, - void(const CodeModelBackEnd::TranslationUnitDoesNotExistCommand &command)); - MOCK_METHOD1(projectPartsDoNotExist, - void(const CodeModelBackEnd::ProjectPartsDoNotExistCommand &command)); -}; - -#endif // MOCKIPCLIENT_H - diff --git a/tests/unit/codemodelbackend/unittest/mockipcserver.h b/tests/unit/codemodelbackend/unittest/mockipcserver.h deleted file mode 100644 index ab04b74ddb..0000000000 --- a/tests/unit/codemodelbackend/unittest/mockipcserver.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef MOCKIPCSERVER_H -#define MOCKIPCSERVER_H - -#include - -class MockIpcServer : public CodeModelBackEnd::IpcServerInterface { - public: - MOCK_METHOD0(end, - void()); - MOCK_METHOD1(registerTranslationUnitsForCodeCompletion, - void(const CodeModelBackEnd::RegisterTranslationUnitForCodeCompletionCommand &command)); - MOCK_METHOD1(unregisterTranslationUnitsForCodeCompletion, - void(const CodeModelBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand &command)); - MOCK_METHOD1(registerProjectPartsForCodeCompletion, - void(const CodeModelBackEnd::RegisterProjectPartsForCodeCompletionCommand &command)); - MOCK_METHOD1(unregisterProjectPartsForCodeCompletion, - void(const CodeModelBackEnd::UnregisterProjectPartsForCodeCompletionCommand &command)); - MOCK_METHOD1(completeCode, - void(const CodeModelBackEnd::CompleteCodeCommand &command)); -}; - -#endif // MOCKIPCSERVER_H - diff --git a/tests/unit/codemodelbackend/unittest/projecttest.cpp b/tests/unit/codemodelbackend/unittest/projecttest.cpp deleted file mode 100644 index 2310174635..0000000000 --- a/tests/unit/codemodelbackend/unittest/projecttest.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" - -#include "gmock/gmock-matchers.h" -#include "gmock/gmock-generated-matchers.h" -#include "gtest-qt-printing.h" - -#include -#include -#include -#include - -#include -#include - -using testing::ElementsAre; -using testing::StrEq; -using testing::Pointwise; -using testing::Contains; -using testing::Gt; -using testing::Not; - -namespace { - -TEST(ProjectPart, CreateProjectPart) -{ - Utf8String projectPath(Utf8StringLiteral("/tmp/blah.pro")); - - CodeModelBackEnd::ProjectPart project(projectPath); - - ASSERT_THAT(project.projectPartId(), projectPath); -} - -TEST(ProjectPart, CreateProjectPartWithProjectPartContainer) -{ - CodeModelBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); - - CodeModelBackEnd::ProjectPart project(projectContainer); - - ASSERT_THAT(project.projectPartId(), Utf8StringLiteral("pathToProjectPart.pro")); - ASSERT_THAT(project.arguments(), Contains(StrEq("-O"))); -} - -TEST(ProjectPart, SetArguments) -{ - CodeModelBackEnd::ProjectPart project(Utf8StringLiteral("/tmp/blah.pro")); - - project.setArguments(Utf8StringVector({Utf8StringLiteral("-O"), Utf8StringLiteral("-fast")})); - - ASSERT_THAT(project.arguments(), ElementsAre(StrEq("-O"), StrEq("-fast"))); -} - -TEST(ProjectPart, ArgumentCount) -{ - CodeModelBackEnd::ProjectPart project(Utf8StringLiteral("/tmp/blah.pro")); - - project.setArguments(Utf8StringVector({Utf8StringLiteral("-O"), Utf8StringLiteral("-fast")})); - - ASSERT_THAT(project.argumentCount(), 2); -} - -TEST(ProjectPart, TimeStampIsUpdatedAsArgumentChanged) -{ - CodeModelBackEnd::ProjectPart project(Utf8StringLiteral("/tmp/blah.pro")); - auto lastChangeTimePoint = project.lastChangeTimePoint(); - std::this_thread::sleep_for(std::chrono::steady_clock::duration(1)); - - project.setArguments(Utf8StringVector({Utf8StringLiteral("-O"), Utf8StringLiteral("-fast")})); - - ASSERT_THAT(project.lastChangeTimePoint(), Gt(lastChangeTimePoint)); - -} - -TEST(ProjectPart, GetNonExistingPoject) -{ - CodeModelBackEnd::ProjectParts projects; - - ASSERT_THROW(projects.project(Utf8StringLiteral("pathToProjectPart.pro")), CodeModelBackEnd::ProjectPartDoNotExistException); -} - -TEST(ProjectPart, AddProjectParts) -{ - CodeModelBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); - CodeModelBackEnd::ProjectParts projects; - - projects.createOrUpdate({projectContainer}); - - ASSERT_THAT(projects.project(projectContainer.projectPartId()), CodeModelBackEnd::ProjectPart(projectContainer)); - ASSERT_THAT(projects.project(projectContainer.projectPartId()).arguments(), ElementsAre(StrEq("-O"))); -} - -TEST(ProjectPart, UpdateProjectParts) -{ - CodeModelBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); - CodeModelBackEnd::ProjectPartContainer projectContainerWithNewArguments(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-fast")}); - CodeModelBackEnd::ProjectParts projects; - projects.createOrUpdate({projectContainer}); - - projects.createOrUpdate({projectContainerWithNewArguments}); - - ASSERT_THAT(projects.project(projectContainer.projectPartId()), CodeModelBackEnd::ProjectPart(projectContainer)); - ASSERT_THAT(projects.project(projectContainer.projectPartId()).arguments(), ElementsAre(StrEq("-fast"))); -} - -TEST(ProjectPart, ThrowExceptionForAccesingRemovedProjectParts) -{ - CodeModelBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); - CodeModelBackEnd::ProjectParts projects; - projects.createOrUpdate({projectContainer}); - - projects.remove({projectContainer.projectPartId()}); - - ASSERT_THROW(projects.project(projectContainer.projectPartId()), CodeModelBackEnd::ProjectPartDoNotExistException); -} - -TEST(ProjectPart, ProjectPartProjectPartIdIsEmptyfterRemoving) -{ - CodeModelBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); - CodeModelBackEnd::ProjectParts projects; - projects.createOrUpdate({projectContainer}); - CodeModelBackEnd::ProjectPart project(projects.project(projectContainer.projectPartId())); - - projects.remove({projectContainer.projectPartId()}); - - ASSERT_TRUE(project.projectPartId().isEmpty()); -} - -TEST(Project, ThrowsForNotExistingProjectPartButRemovesAllExistingProject) -{ - CodeModelBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro")); - CodeModelBackEnd::ProjectParts projects; - projects.createOrUpdate({projectContainer}); - CodeModelBackEnd::ProjectPart project = *projects.findProjectPart(Utf8StringLiteral("pathToProjectPart.pro")); - - EXPECT_THROW(projects.remove({Utf8StringLiteral("doesnotexist.pro"), projectContainer.projectPartId()}), CodeModelBackEnd::ProjectPartDoNotExistException); - - ASSERT_THAT(projects.projects(), Not(Contains(project))); -} - -TEST(ProjectPart, HasProjectPart) -{ - CodeModelBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro")); - CodeModelBackEnd::ProjectParts projects; - projects.createOrUpdate({projectContainer}); - - ASSERT_TRUE(projects.hasProjectPart(projectContainer.projectPartId())); -} - -TEST(ProjectPart, DoNotHasProjectPart) -{ - CodeModelBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro")); - CodeModelBackEnd::ProjectParts projects; - projects.createOrUpdate({projectContainer}); - - ASSERT_FALSE(projects.hasProjectPart(Utf8StringLiteral("doesnotexist.pro"))); -} - - -} diff --git a/tests/unit/codemodelbackend/unittest/readandwritecommandblocktest.cpp b/tests/unit/codemodelbackend/unittest/readandwritecommandblocktest.cpp deleted file mode 100644 index e0b4960b67..0000000000 --- a/tests/unit/codemodelbackend/unittest/readandwritecommandblocktest.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gtest-qt-printing.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "gtest-qt-printing.h" - -using namespace testing; -namespace CodeModelBackeEndTest { - -class ReadAndWriteCommandBlockTest : public ::testing::Test -{ -protected: - ReadAndWriteCommandBlockTest(); - - virtual void SetUp() override; - virtual void TearDown() override; - - template - void CompareCommand(const Type &command); - - QVariant writeCodeCompletedCommand(); - void popLastCharacterFromBuffer(); - void pushLastCharacterToBuffer(); - void readPartialCommand(); - -protected: - QBuffer buffer; - CodeModelBackEnd::WriteCommandBlock writeCommandBlock; - CodeModelBackEnd::ReadCommandBlock readCommandBlock; - char lastCharacter = 0; -}; - -ReadAndWriteCommandBlockTest::ReadAndWriteCommandBlockTest() - : writeCommandBlock(&buffer), - readCommandBlock(&buffer) -{ -} - -void ReadAndWriteCommandBlockTest::SetUp() -{ - buffer.open(QIODevice::ReadWrite); - writeCommandBlock = CodeModelBackEnd::WriteCommandBlock(&buffer); - readCommandBlock = CodeModelBackEnd::ReadCommandBlock(&buffer); -} - -void ReadAndWriteCommandBlockTest::TearDown() -{ - buffer.close(); -} - -TEST_F(ReadAndWriteCommandBlockTest, WriteCommandAndTestSize) -{ - writeCommandBlock.write(QVariant::fromValue(CodeModelBackEnd::EndCommand())); - - ASSERT_EQ(50, buffer.size()); -} - -TEST_F(ReadAndWriteCommandBlockTest, WriteSecondCommandAndTestSize) -{ - writeCommandBlock.write(QVariant::fromValue(CodeModelBackEnd::EndCommand())); - - ASSERT_EQ(50, buffer.size()); -} - -TEST_F(ReadAndWriteCommandBlockTest, WriteTwoCommandsAndTestCount) -{ - writeCommandBlock.write(QVariant::fromValue(CodeModelBackEnd::EndCommand())); - writeCommandBlock.write(QVariant::fromValue(CodeModelBackEnd::EndCommand())); - - ASSERT_EQ(2, writeCommandBlock.counter()); -} - -TEST_F(ReadAndWriteCommandBlockTest, ReadThreeCommandsAndTestCount) -{ - writeCommandBlock.write(QVariant::fromValue(CodeModelBackEnd::EndCommand())); - writeCommandBlock.write(QVariant::fromValue(CodeModelBackEnd::EndCommand())); - writeCommandBlock.write(QVariant::fromValue(CodeModelBackEnd::EndCommand())); - buffer.seek(0); - - ASSERT_EQ(3, readCommandBlock.readAll().count()); -} - -TEST_F(ReadAndWriteCommandBlockTest, CompareEndCommand) -{ - CompareCommand(CodeModelBackEnd::EndCommand()); -} - -TEST_F(ReadAndWriteCommandBlockTest, CompareAliveCommand) -{ - CompareCommand(CodeModelBackEnd::AliveCommand()); -} - -TEST_F(ReadAndWriteCommandBlockTest, CompareRegisterTranslationUnitForCodeCompletionCommand) -{ - CodeModelBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("pathToProject.pro")); - QVector fileContainers({fileContainer}); - - CompareCommand(CodeModelBackEnd::RegisterTranslationUnitForCodeCompletionCommand(fileContainers)); -} - -TEST_F(ReadAndWriteCommandBlockTest, CompareUnregisterFileForCodeCompletionCommand) -{ - CodeModelBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("pathToProject.pro")); - - CompareCommand(CodeModelBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand({fileContainer})); -} - -TEST_F(ReadAndWriteCommandBlockTest, CompareCompleteCodeCommand) -{ - CompareCommand(CodeModelBackEnd::CompleteCodeCommand(Utf8StringLiteral("foo.cpp"), 24, 33, Utf8StringLiteral("do what I want"))); -} - -TEST_F(ReadAndWriteCommandBlockTest, CompareCodeCompletedCommand) -{ - QVector codeCompletions({Utf8StringLiteral("newFunction()")}); - - CompareCommand(CodeModelBackEnd::CodeCompletedCommand(codeCompletions, 1)); -} - -TEST_F(ReadAndWriteCommandBlockTest, GetInvalidCommandForAPartialBuffer) -{ - writeCodeCompletedCommand(); - popLastCharacterFromBuffer(); - buffer.seek(0); - - readPartialCommand(); -} - -TEST_F(ReadAndWriteCommandBlockTest, ReadCommandAfterInterruption) -{ - const QVariant writeCommand = writeCodeCompletedCommand(); - popLastCharacterFromBuffer(); - buffer.seek(0); - readPartialCommand(); - pushLastCharacterToBuffer(); - - ASSERT_EQ(readCommandBlock.read(), writeCommand); -} - -QVariant ReadAndWriteCommandBlockTest::writeCodeCompletedCommand() -{ - CodeModelBackEnd::CodeCompletedCommand command(QVector({Utf8StringLiteral("newFunction()")}), 1); - const QVariant writeCommand = QVariant::fromValue(command); - writeCommandBlock.write(writeCommand); - - return writeCommand; -} - -void ReadAndWriteCommandBlockTest::popLastCharacterFromBuffer() -{ - auto &internalBuffer = buffer.buffer(); - lastCharacter = internalBuffer.at(internalBuffer.size() - 1); - internalBuffer.chop(1); -} - -void ReadAndWriteCommandBlockTest::pushLastCharacterToBuffer() -{ - buffer.buffer().push_back(lastCharacter); -} - -void ReadAndWriteCommandBlockTest::readPartialCommand() -{ - QVariant readCommand = readCommandBlock.read(); - - ASSERT_FALSE(readCommand.isValid()); -} - -template -void ReadAndWriteCommandBlockTest::CompareCommand(const Type &command) -{ - const QVariant writeCommand = QVariant::fromValue(command); - writeCommandBlock.write(writeCommand); - buffer.seek(0); - - const QVariant readCommand = readCommandBlock.read(); - - ASSERT_EQ(writeCommand, readCommand); -} - -} diff --git a/tests/unit/codemodelbackend/unittest/spydummy.cpp b/tests/unit/codemodelbackend/unittest/spydummy.cpp deleted file mode 100644 index 758c8b0762..0000000000 --- a/tests/unit/codemodelbackend/unittest/spydummy.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "spydummy.h" - -SpyDummy::SpyDummy(QObject *parent) : QObject(parent) -{ - -} - -SpyDummy::~SpyDummy() -{ - -} - diff --git a/tests/unit/codemodelbackend/unittest/spydummy.h b/tests/unit/codemodelbackend/unittest/spydummy.h deleted file mode 100644 index 6d17f49472..0000000000 --- a/tests/unit/codemodelbackend/unittest/spydummy.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef SPYDUMMY_H -#define SPYDUMMY_H - -#include - -class SpyDummy : public QObject -{ - Q_OBJECT -public: - explicit SpyDummy(QObject *parent = 0); - ~SpyDummy(); - -signals: - void tableIsReady(); - void databaseIsOpened(); - void databaseIsClosed(); -}; - -#endif // SPYDUMMY_H diff --git a/tests/unit/codemodelbackend/unittest/sqlitecolumntest.cpp b/tests/unit/codemodelbackend/unittest/sqlitecolumntest.cpp deleted file mode 100644 index a716dc5f3d..0000000000 --- a/tests/unit/codemodelbackend/unittest/sqlitecolumntest.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - - -#include -#include -#include "gtest-qt-printing.h" - -#include - -namespace { - -class SqliteColumn : public ::testing::Test -{ -protected: - void SetUp() override; - - ::SqliteColumn column; -}; - -TEST_F(SqliteColumn, ChangeName) -{ - column.setName(Utf8StringLiteral("Claudia")); - - ASSERT_THAT(column.name(), Utf8StringLiteral("Claudia")); -} - -TEST_F(SqliteColumn, DefaultType) -{ - ASSERT_THAT(column.type(), ColumnType::Numeric); -} - -TEST_F(SqliteColumn, ChangeType) -{ - column.setType(ColumnType::Text); - - ASSERT_THAT(column.type(), ColumnType::Text); -} - -TEST_F(SqliteColumn, DefaultPrimaryKey) -{ - ASSERT_FALSE(column.isPrimaryKey()); -} - -TEST_F(SqliteColumn, SetPrimaryKey) -{ - column.setIsPrimaryKey(true); - - ASSERT_TRUE(column.isPrimaryKey()); -} - -TEST_F(SqliteColumn, GetColumnDefinition) -{ - column.setName(Utf8StringLiteral("Claudia")); - - Internal::ColumnDefinition columnDefintion = column.columnDefintion(); - - ASSERT_THAT(columnDefintion.name(), Utf8StringLiteral("Claudia")); - ASSERT_THAT(columnDefintion.type(), ColumnType::Numeric); - ASSERT_FALSE(columnDefintion.isPrimaryKey()); -} - -void SqliteColumn::SetUp() -{ - column.clear(); -} - -} diff --git a/tests/unit/codemodelbackend/unittest/sqlitedatabasebackendtest.cpp b/tests/unit/codemodelbackend/unittest/sqlitedatabasebackendtest.cpp deleted file mode 100644 index c023d85268..0000000000 --- a/tests/unit/codemodelbackend/unittest/sqlitedatabasebackendtest.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gtest-qt-printing.h" - -#include - -#include "sqlitedatabasebackend.h" -#include "sqliteexception.h" -#include "sqlitewritestatement.h" - -namespace { - -class SqliteDatabaseBackend : public ::testing::Test -{ -protected: - void SetUp() override; - void TearDown() override; - - QString databaseFilePath = QDir::tempPath() + QStringLiteral("/SqliteDatabaseBackendTest.db"); - ::SqliteDatabaseBackend databaseBackend; -}; - -TEST_F(SqliteDatabaseBackend, OpenAlreadyOpenDatabase) -{ - ASSERT_THROW(databaseBackend.open(databaseFilePath), SqliteException); -} - -TEST_F(SqliteDatabaseBackend, CloseAlreadyClosedDatabase) -{ - databaseBackend.close(); - ASSERT_THROW(databaseBackend.close(), SqliteException); -} - -TEST_F(SqliteDatabaseBackend, OpenWithWrongPath) -{ - ASSERT_THROW(databaseBackend.open(QStringLiteral("/xxx/SqliteDatabaseBackendTest.db")), SqliteException); -} - -TEST_F(SqliteDatabaseBackend, DefaultJournalMode) -{ - ASSERT_THAT(databaseBackend.journalMode(), JournalMode::Delete); -} - -TEST_F(SqliteDatabaseBackend, WalJournalMode) -{ - databaseBackend.setJournalMode(JournalMode::Wal); - - ASSERT_THAT(databaseBackend.journalMode(), JournalMode::Wal); -} - -TEST_F(SqliteDatabaseBackend, TruncateJournalMode) -{ - databaseBackend.setJournalMode(JournalMode::Truncate); - - ASSERT_THAT(databaseBackend.journalMode(), JournalMode::Truncate); -} - -TEST_F(SqliteDatabaseBackend, MemoryJournalMode) -{ - databaseBackend.setJournalMode(JournalMode::Memory); - - ASSERT_THAT(databaseBackend.journalMode(), JournalMode::Memory); -} - -TEST_F(SqliteDatabaseBackend, PersistJournalMode) -{ - databaseBackend.setJournalMode(JournalMode::Persist); - - ASSERT_THAT(databaseBackend.journalMode(), JournalMode::Persist); -} - -TEST_F(SqliteDatabaseBackend, DefaultTextEncoding) -{ - ASSERT_THAT(databaseBackend.textEncoding(), Utf8); -} - -TEST_F(SqliteDatabaseBackend, Utf16TextEncoding) -{ - databaseBackend.setTextEncoding(Utf16); - - ASSERT_THAT(databaseBackend.textEncoding(), Utf16); -} - -TEST_F(SqliteDatabaseBackend, Utf16beTextEncoding) -{ - databaseBackend.setTextEncoding(Utf16be); - - ASSERT_THAT(databaseBackend.textEncoding(), Utf16be); -} - -TEST_F(SqliteDatabaseBackend, Utf16leTextEncoding) -{ - databaseBackend.setTextEncoding(Utf16le); - - ASSERT_THAT(databaseBackend.textEncoding(), Utf16le); -} - -TEST_F(SqliteDatabaseBackend, Utf8TextEncoding) -{ - databaseBackend.setTextEncoding(Utf8); - - ASSERT_THAT(databaseBackend.textEncoding(), Utf8); -} - -TEST_F(SqliteDatabaseBackend, TextEncodingCannotBeChangedAfterTouchingDatabase) -{ - databaseBackend.setJournalMode(JournalMode::Memory); - - SqliteWriteStatement::execute(Utf8StringLiteral("CREATE TABLE text(name, number)")); - - ASSERT_THROW(databaseBackend.setTextEncoding(Utf16), SqliteException); -} - -void SqliteDatabaseBackend::SetUp() -{ - QDir::temp().remove(QStringLiteral("SqliteDatabaseBackendTest.db")); - databaseBackend.open(databaseFilePath); -} - -void SqliteDatabaseBackend::TearDown() -{ - databaseBackend.closeWithoutException(); -} -} diff --git a/tests/unit/codemodelbackend/unittest/sqlitedatabasetest.cpp b/tests/unit/codemodelbackend/unittest/sqlitedatabasetest.cpp deleted file mode 100644 index b4c979fe17..0000000000 --- a/tests/unit/codemodelbackend/unittest/sqlitedatabasetest.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gtest-qt-printing.h" - -#include -#include - -#include -#include -#include - -#include "spydummy.h" - -namespace { - -class SqliteDatabase : public ::testing::Test -{ -protected: - void SetUp() override; - void TearDown() override; - - SpyDummy spyDummy; - QString databaseFilePath = QStringLiteral(":memory:"); - ::SqliteDatabase database; -}; - -TEST_F(SqliteDatabase, SetDatabaseFilePath) -{ - ASSERT_THAT(database.databaseFilePath(), databaseFilePath); -} - -TEST_F(SqliteDatabase, SetJournalMode) -{ - database.setJournalMode(JournalMode::Memory); - - ASSERT_THAT(database.journalMode(), JournalMode::Memory); -} - -TEST_F(SqliteDatabase, OpenDatabase) -{ - database.close(); - QSignalSpy signalSpy(&spyDummy, &SpyDummy::databaseIsOpened); - database.open(); - - ASSERT_TRUE(signalSpy.wait(100000)); - ASSERT_TRUE(database.isOpen()); -} - -TEST_F(SqliteDatabase, CloseDatabase) -{ - QSignalSpy signalSpy(&spyDummy, &SpyDummy::databaseIsClosed); - - database.close(); - - ASSERT_TRUE(signalSpy.wait(100000)); - ASSERT_FALSE(database.isOpen()); -} - -TEST_F(SqliteDatabase, AddTable) -{ - SqliteTable *sqliteTable = new SqliteTable; - - database.addTable(sqliteTable); - - ASSERT_THAT(database.tables().first(), sqliteTable); -} - -void SqliteDatabase::SetUp() -{ - QObject::connect(&database, &::SqliteDatabase::databaseIsOpened, &spyDummy, &SpyDummy::databaseIsOpened); - QObject::connect(&database, &::SqliteDatabase::databaseIsClosed, &spyDummy, &SpyDummy::databaseIsClosed); - - database.setJournalMode(JournalMode::Memory); - database.setDatabaseFilePath(databaseFilePath); -} - -void SqliteDatabase::TearDown() -{ - database.close(); -} -} diff --git a/tests/unit/codemodelbackend/unittest/sqlitestatementtest.cpp b/tests/unit/codemodelbackend/unittest/sqlitestatementtest.cpp deleted file mode 100644 index 5e218168ee..0000000000 --- a/tests/unit/codemodelbackend/unittest/sqlitestatementtest.cpp +++ /dev/null @@ -1,570 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gtest-qt-printing.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace { -class SqliteStatement : public ::testing::Test -{ -protected: - void SetUp() override; - void TearDown() override; - - SqliteDatabaseBackend databaseBackend; -}; - -TEST_F(SqliteStatement, PrepareFailure) -{ - ASSERT_THROW(SqliteReadStatement(Utf8StringLiteral("blah blah blah")), SqliteException); - ASSERT_THROW(SqliteWriteStatement(Utf8StringLiteral("blah blah blah")), SqliteException); - ASSERT_THROW(SqliteReadStatement(Utf8StringLiteral("INSERT INTO test(name, number) VALUES (?, ?)")), SqliteException); - ASSERT_THROW(SqliteWriteStatement(Utf8StringLiteral("SELECT name, number FROM test '")), SqliteException); -} - -TEST_F(SqliteStatement, CountRows) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT * FROM test")); - int nextCount = 0; - while (statement.next()) - ++nextCount; - - int sqlCount = SqliteReadStatement::toValue(Utf8StringLiteral("SELECT count(*) FROM test")); - - ASSERT_THAT(nextCount, sqlCount); -} - -TEST_F(SqliteStatement, Value) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test ORDER BY name")); - - statement.next(); - - ASSERT_THAT(statement.value(1).type(), QVariant::ByteArray); - - statement.next(); - - ASSERT_THAT(statement.value(0), 0); - ASSERT_THAT(statement.value(0), 0); - ASSERT_THAT(statement.value(0), 0.0); - ASSERT_THAT(statement.value(0), QStringLiteral("foo")); - ASSERT_THAT(statement.value(0), Utf8StringLiteral("foo")); - ASSERT_THAT(statement.value(0), QVariant::fromValue(QStringLiteral("foo"))); - ASSERT_THAT(statement.value(0).type(), QVariant::String); - - ASSERT_THAT(statement.value(1), 23); - ASSERT_THAT(statement.value(1), 23); - ASSERT_THAT(statement.value(1), 23.3); - ASSERT_THAT(statement.value(1), QStringLiteral("23.3")); - ASSERT_THAT(statement.value(1), Utf8StringLiteral("23.3")); - ASSERT_THAT(statement.value(1), QVariant::fromValue(23.3)); - ASSERT_THAT(statement.value(1).type(), QVariant::Double); - - statement.next(); - - ASSERT_THAT(statement.value(1).type(), QVariant::LongLong); -} - -TEST_F(SqliteStatement, ValueFailure) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test")); - ASSERT_THROW(statement.value(0), SqliteException); - - statement.reset(); - - while (statement.next()) {} - ASSERT_THROW(statement.value(0), SqliteException); - - statement.reset(); - - statement.next(); - ASSERT_THROW(statement.value(-1), SqliteException); - ASSERT_THROW(statement.value(2), SqliteException); -} - -TEST_F(SqliteStatement, ToIntergerValue) -{ - ASSERT_THAT(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT number FROM test WHERE name='foo'")), 23); -} - -TEST_F(SqliteStatement, ToLongIntergerValue) -{ - ASSERT_THAT(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT number FROM test WHERE name='foo'")), 23LL); -} - -TEST_F(SqliteStatement, ToDoubleValue) -{ - ASSERT_THAT(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT number FROM test WHERE name='foo'")), 23.3); -} - -TEST_F(SqliteStatement, ToQStringValue) -{ - ASSERT_THAT(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT name FROM test WHERE name='foo'")), QStringLiteral("foo")); -} - -TEST_F(SqliteStatement, ToUtf8StringValue) -{ - ASSERT_THAT(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT name FROM test WHERE name='foo'")), Utf8StringLiteral("foo")); -} - -TEST_F(SqliteStatement, ToQByteArrayValueIsNull) -{ - ASSERT_TRUE(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT name FROM test WHERE name='foo'")).isNull()); -} - -TEST_F(SqliteStatement, ToQVariantValue) -{ - ASSERT_THAT(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT name FROM test WHERE name='foo'")), QVariant::fromValue(QStringLiteral("foo"))); -} - -TEST_F(SqliteStatement, Utf8Values) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test ORDER by name")); - - Utf8StringVector values = statement.values(); - ASSERT_THAT(values.count(), 3); - ASSERT_THAT(values.at(0), Utf8StringLiteral("bar")); - ASSERT_THAT(values.at(1), Utf8StringLiteral("foo")); - ASSERT_THAT(values.at(2), Utf8StringLiteral("poo")); -} -TEST_F(SqliteStatement, DoubleValues) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test ORDER by name")); - - QVector values = statement.values>(1); - - ASSERT_THAT(values.count(), 3); - ASSERT_THAT(values.at(0), 0.0); - ASSERT_THAT(values.at(1), 23.3); - ASSERT_THAT(values.at(2), 40.0); -} - -TEST_F(SqliteStatement, QVariantValues) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test ORDER by name")); - - QVector values = statement.values>(QVector() << 0 << 1); - - ASSERT_THAT(values.count(), 6); - ASSERT_THAT(values.at(0), QVariant::fromValue(QStringLiteral("bar"))); - ASSERT_THAT(values.at(1), QVariant::fromValue(QByteArray::fromHex("0500"))); - ASSERT_THAT(values.at(2), QVariant::fromValue(QStringLiteral("foo"))); - ASSERT_THAT(values.at(3), QVariant::fromValue(23.3)); - ASSERT_THAT(values.at(4), QVariant::fromValue(QStringLiteral("poo"))); - ASSERT_THAT(values.at(5), QVariant::fromValue(40)); -} - -TEST_F(SqliteStatement, RowColumnValueMapCountForValidRow) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE rowid=1")); - - QMap values = statement.rowColumnValueMap(); - - ASSERT_THAT(values.count(), 2); -} - -TEST_F(SqliteStatement, RowColumnValueMapCountForInvalidRow) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE rowid=100")); - - QMap values = statement.rowColumnValueMap(); - - ASSERT_THAT(values.count(), 0); -} - -TEST_F(SqliteStatement, RowColumnValueMapValues) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE rowid=2")); - - QMap values = statement.rowColumnValueMap(); - - ASSERT_THAT(values.value(QStringLiteral("name")).toString(), QStringLiteral("foo")); - ASSERT_THAT(values.value(QStringLiteral("number")).toDouble(), 23.3); -} - -TEST_F(SqliteStatement, TwoColumnValueMapCount) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test")); - - QMap values = statement.twoColumnValueMap(); - - ASSERT_THAT(values.count(), 3); -} - -TEST_F(SqliteStatement, TwoColumnValueMapValues) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test")); - - QMap values = statement.twoColumnValueMap(); - - ASSERT_THAT(values.value(QStringLiteral("foo")).toDouble(), 23.3); -} - -TEST_F(SqliteStatement, ValuesFailure) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test")); - - ASSERT_THROW(statement.values>(QVector() << 1 << 2);, SqliteException); - ASSERT_THROW(statement.values>(QVector() << -1 << 1);, SqliteException); -} - -TEST_F(SqliteStatement, ColumnNames) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test")); - - Utf8StringVector columnNames = statement.columnNames(); - - ASSERT_THAT(columnNames.count(), statement.columnCount()); - - ASSERT_THAT(columnNames.at(0), Utf8StringLiteral("name")); - ASSERT_THAT(columnNames.at(1), Utf8StringLiteral("number")); -} - -TEST_F(SqliteStatement, BindQString) -{ - - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE name=?")); - - statement.bind(1, QStringLiteral("foo")); - - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("foo")); - ASSERT_THAT(statement.value(1), 23.3); -} - -TEST_F(SqliteStatement, BindInteger) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); - - statement.bind(1, 40); - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("poo")); -} - -TEST_F(SqliteStatement, BindLongInteger) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); - - statement.bind(1, qint64(40)); - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("poo")); -} - -TEST_F(SqliteStatement, BindByteArray) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); - - statement.bind(1, QByteArray::fromHex("0500")); - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("bar")); -} - -TEST_F(SqliteStatement, BindDouble) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); - - statement.bind(1, 23.3); - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("foo")); -} - -TEST_F(SqliteStatement, BindIntergerQVariant) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); - - statement.bind(1, QVariant::fromValue(40)); - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("poo")); -} - -TEST_F(SqliteStatement, BindLongIntergerQVariant) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); - - statement.bind(1, QVariant::fromValue(qint64(40))); - statement.next(); - ASSERT_THAT(statement.value(0), QStringLiteral("poo")); -} - -TEST_F(SqliteStatement, BindDoubleQVariant) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); - - statement.bind(1, QVariant::fromValue(23.3)); - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("foo")); - } - -TEST_F(SqliteStatement, BindByteArrayQVariant) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); - - statement.bind(1, QVariant::fromValue(QByteArray::fromHex("0500"))); - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("bar")); -} - -TEST_F(SqliteStatement, BindIntegerByParameter) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=@number")); - - statement.bind(Utf8StringLiteral("@number"), 40); - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("poo")); -} - -TEST_F(SqliteStatement, BindLongIntegerByParameter) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=@number")); - - statement.bind(Utf8StringLiteral("@number"), qint64(40)); - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("poo")); -} - -TEST_F(SqliteStatement, BindByteArrayByParameter) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=@number")); - - statement.bind(Utf8StringLiteral("@number"), QByteArray::fromHex("0500")); - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("bar")); -} - -TEST_F(SqliteStatement, BindDoubleByIndex) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=@number")); - - statement.bind(statement.bindingIndexForName(Utf8StringLiteral("@number")), 23.3); - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("foo")); -} - -TEST_F(SqliteStatement, BindQVariantByIndex) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=@number")); - - statement.bind(statement.bindingIndexForName(Utf8StringLiteral("@number")), QVariant::fromValue((40))); - statement.next(); - - ASSERT_THAT(statement.value(0), QStringLiteral("poo")); - -} - -TEST_F(SqliteStatement, BindFailure) -{ - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=@number")); - - ASSERT_THROW(statement.bind(0, 40), SqliteException); - ASSERT_THROW(statement.bind(2, 40), SqliteException); - ASSERT_THROW(statement.bind(Utf8StringLiteral("@name"), 40), SqliteException); -} - -TEST_F(SqliteStatement, RequestBindingNamesFromStatement) -{ - Utf8StringVector expectedValues({Utf8StringLiteral("name"), Utf8StringLiteral("number"), Utf8StringLiteral("id")}); - - SqliteWriteStatement statement(Utf8StringLiteral("UPDATE test SET name=@name, number=@number WHERE rowid=@id")); - - ASSERT_THAT(statement.bindingColumnNames(), expectedValues); -} - -TEST_F(SqliteStatement, WriteUpdateWidthUnamedParameter) -{ - { - int startTotalCount = databaseBackend.totalChangesCount(); - RowDictionary firstValueMap; - firstValueMap.insert(Utf8StringLiteral("name"), QStringLiteral("foo")); - firstValueMap.insert(Utf8StringLiteral("number"), 66.6); - - RowDictionary secondValueMap; - secondValueMap.insert(Utf8StringLiteral("name"), QStringLiteral("bar")); - secondValueMap.insert(Utf8StringLiteral("number"), 77.7); - - SqliteWriteStatement statement(Utf8StringLiteral("UPDATE test SET number=? WHERE name=?")); - statement.setBindingColumnNames(Utf8StringVector() << Utf8StringLiteral("number") << Utf8StringLiteral("name")); - - statement.write(firstValueMap); - - ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 1); - - statement.write(firstValueMap); - - ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 2); - - statement.write(secondValueMap); - - ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 3); - } - - { - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE name='foo'")); - - statement.next(); - - ASSERT_THAT(statement.value(1), 66.6); - } -} - -TEST_F(SqliteStatement, WriteUpdateWidthNamedParameter) -{ - { - int startTotalCount = databaseBackend.totalChangesCount(); - RowDictionary firstValueMap; - firstValueMap.insert(Utf8StringLiteral("name"), QStringLiteral("foo")); - firstValueMap.insert(Utf8StringLiteral("number"), 99.9); - - SqliteWriteStatement statement(Utf8StringLiteral("UPDATE test SET number=@number WHERE name=@name")); - statement.write(firstValueMap); - ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 1); - } - - { - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE name='foo'")); - statement.next(); - ASSERT_THAT(statement.value(1), 99.9); - } -} - -TEST_F(SqliteStatement, WriteUpdateWidthNamedParameterAndBindNotAllParameter) -{ - { - int startTotalCount = databaseBackend.totalChangesCount(); - RowDictionary firstValueMap; - firstValueMap.insert(Utf8StringLiteral("name"), QStringLiteral("foo")); - - SqliteWriteStatement statement(Utf8StringLiteral("UPDATE test SET number=@number WHERE name=@name")); - statement.writeUnchecked(firstValueMap); - ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 1); - } - - { - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE name='foo'")); - statement.next(); - ASSERT_THAT(statement.value(1), 0.0); - } -} - -TEST_F(SqliteStatement, WriteInsert) -{ - { - int startTotalCount = databaseBackend.totalChangesCount(); - - RowDictionary valueMap; - valueMap.insert(Utf8StringLiteral("name"), QStringLiteral("jane")); - valueMap.insert(Utf8StringLiteral("number"), 232.3); - - SqliteWriteStatement statement(Utf8StringLiteral("INSERT OR IGNORE INTO test(name, number) VALUES (?, ?)")); - statement.setBindingColumnNames(Utf8StringVector() << Utf8StringLiteral("name") << Utf8StringLiteral("number")); - statement.write(valueMap); - ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 1); - statement.write(valueMap); - ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 1); - } - - { - SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE name='jane'")); - statement.next(); - ASSERT_THAT(statement.value(1), 232.3); - } -} - -TEST_F(SqliteStatement, WriteFailure) -{ - { - RowDictionary valueMap; - valueMap.insert(Utf8StringLiteral("name"), QStringLiteral("foo")); - valueMap.insert(Utf8StringLiteral("number"), 323.3); - - SqliteWriteStatement statement(Utf8StringLiteral("INSERT INTO test(name, number) VALUES (?, ?)")); - statement.setBindingColumnNames(Utf8StringVector() << Utf8StringLiteral("name") << Utf8StringLiteral("number")); - ASSERT_THROW(statement.write(valueMap), SqliteException); - } - - { - RowDictionary valueMap; - valueMap.insert(Utf8StringLiteral("name"), QStringLiteral("bar")); - - SqliteWriteStatement statement(Utf8StringLiteral("INSERT OR IGNORE INTO test(name, number) VALUES (?, ?)")); - statement.setBindingColumnNames(Utf8StringVector() << Utf8StringLiteral("name") << Utf8StringLiteral("number")); - ASSERT_THROW(statement.write(valueMap), SqliteException); - } -} - -TEST_F(SqliteStatement, ClosedDatabase) -{ - databaseBackend.close(); - ASSERT_THROW(SqliteWriteStatement(Utf8StringLiteral("INSERT INTO test(name, number) VALUES (?, ?)")), SqliteException); - ASSERT_THROW(SqliteReadStatement(Utf8StringLiteral("SELECT * FROM test")), SqliteException); - ASSERT_THROW(SqliteReadWriteStatement(Utf8StringLiteral("INSERT INTO test(name, number) VALUES (?, ?)")), SqliteException); - databaseBackend.open(QDir::tempPath() + QStringLiteral("/SqliteStatementTest.db")); -} - -void SqliteStatement::SetUp() -{ - databaseBackend.open(QStringLiteral(":memory:")); - SqliteWriteStatement::execute(Utf8StringLiteral("CREATE TABLE test(name TEXT UNIQUE, number NUMERIC)")); - SqliteWriteStatement::execute(Utf8StringLiteral("INSERT INTO test VALUES ('bar', x'0500')")); - SqliteWriteStatement::execute(Utf8StringLiteral("INSERT INTO test VALUES ('foo', 23.3)")); - SqliteWriteStatement::execute(Utf8StringLiteral("INSERT INTO test VALUES ('poo', 40)")); -} - -void SqliteStatement::TearDown() -{ - databaseBackend.close(); -} - -} diff --git a/tests/unit/codemodelbackend/unittest/sqlitetabletest.cpp b/tests/unit/codemodelbackend/unittest/sqlitetabletest.cpp deleted file mode 100644 index fa5e671163..0000000000 --- a/tests/unit/codemodelbackend/unittest/sqlitetabletest.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gtest-qt-printing.h" - -#include -#include - -#include -#include -#include -#include - -#include "spydummy.h" - -namespace { - -class SqliteTable : public ::testing::Test -{ -protected: - void SetUp() override; - void TearDown() override; - - SqliteColumn *addColumn(const Utf8String &columnName); - - SpyDummy spyDummy; - SqliteDatabase *database = nullptr; - ::SqliteTable *table = nullptr; - Utf8String tableName = Utf8StringLiteral("testTable"); -}; - - -TEST_F(SqliteTable, ColumnIsAddedToTable) -{ - table->setUseWithoutRowId(true); - - ASSERT_TRUE(table->useWithoutRowId()); -} - -TEST_F(SqliteTable, SetTableName) -{ - table->setName(tableName); - - ASSERT_THAT(table->name(), tableName); -} - -TEST_F(SqliteTable, SetUseWithoutRowid) -{ - table->setUseWithoutRowId(true); - - ASSERT_TRUE(table->useWithoutRowId()); -} - -TEST_F(SqliteTable, TableIsReadyAfterOpenDatabase) -{ - QSignalSpy signalSpy(&spyDummy, &SpyDummy::tableIsReady); - table->setName(tableName); - addColumn(Utf8StringLiteral("name")); - - database->open(); - - ASSERT_TRUE(signalSpy.wait(100000)); -} - -void SqliteTable::SetUp() -{ - table = new ::SqliteTable; - QObject::connect(table, &::SqliteTable::tableIsReady, &spyDummy, &SpyDummy::tableIsReady); - - database = new SqliteDatabase; - database->setJournalMode(JournalMode::Memory); - database->setDatabaseFilePath( QStringLiteral(":memory:")); - database->addTable(table); -} - -void SqliteTable::TearDown() -{ - database->close(); - delete database; - database = nullptr; - table = nullptr; -} - -SqliteColumn *SqliteTable::addColumn(const Utf8String &columnName) -{ - SqliteColumn *newSqliteColum = new SqliteColumn; - - newSqliteColum->setName(columnName); - - table->addColumn(newSqliteColum); - - return newSqliteColum; -} -} diff --git a/tests/unit/codemodelbackend/unittest/sqlstatementbuildertest.cpp b/tests/unit/codemodelbackend/unittest/sqlstatementbuildertest.cpp deleted file mode 100644 index 1f04c64f5f..0000000000 --- a/tests/unit/codemodelbackend/unittest/sqlstatementbuildertest.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gtest-qt-printing.h" - -#include - -#include -#include -#include - -using namespace ::testing; - -TEST(SqlStatementBuilder, Bind) -{ - SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table WHERE $column = 'foo' AND rowid=$row AND rowid IN ($rows)")); - - sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringVector() << Utf8StringLiteral("name") << Utf8StringLiteral("number")); - sqlStatementBuilder.bind(Utf8StringLiteral("$column"), Utf8StringLiteral("name")); - sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); - sqlStatementBuilder.bind(Utf8StringLiteral("$row"), 20); - sqlStatementBuilder.bind(Utf8StringLiteral("$rows"), QVector() << 1 << 2 << 3); - - ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("SELECT name, number FROM test WHERE name = 'foo' AND rowid=20 AND rowid IN (1, 2, 3)")); -} - -TEST(SqlStatementBuilder, BindEmpty) -{ - SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table$emptyPart")); - sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringVector() << Utf8StringLiteral("name") << Utf8StringLiteral("number")); - sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); - - sqlStatementBuilder.bindEmptyText(Utf8StringLiteral("$emptyPart")); - - ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("SELECT name, number FROM test")); -} - -TEST(SqlStatementBuilder, BindFailure) -{ - SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table")); - - Utf8StringVector columns; - - ASSERT_THROW(sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringLiteral("")), SqlStatementBuilderException); - ASSERT_THROW(sqlStatementBuilder.bind(Utf8StringLiteral("columns"), Utf8StringLiteral("test")), SqlStatementBuilderException); - ASSERT_THROW(sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), columns), SqlStatementBuilderException); - ASSERT_THROW(sqlStatementBuilder.bindWithInsertTemplateParameters(Utf8StringLiteral("$columns"), columns), SqlStatementBuilderException); - ASSERT_THROW(sqlStatementBuilder.bindWithUpdateTemplateParameters(Utf8StringLiteral("$columns"), columns), SqlStatementBuilderException); -} - -TEST(SqlStatementBuilder, BindWithInsertTemplateParameters) -{ - Utf8StringVector columns({Utf8StringLiteral("name"), Utf8StringLiteral("number")}); - - SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("INSERT OR IGNORE INTO $table ($columns) VALUES ($values)")); - sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); - sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), columns); - sqlStatementBuilder.bindWithInsertTemplateParameters(Utf8StringLiteral("$values"), columns); - - ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("INSERT OR IGNORE INTO test (name, number) VALUES (?, ?)")); -} - -TEST(SqlStatementBuilder, BindWithUpdateTemplateParameters) -{ - Utf8StringVector columns({Utf8StringLiteral("name"), Utf8StringLiteral("number")}); - - SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("UPDATE $table SET $columnValues WHERE id=?")); - sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); - sqlStatementBuilder.bindWithUpdateTemplateParameters(Utf8StringLiteral("$columnValues"), columns); - - ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("UPDATE test SET name=?, number=? WHERE id=?")); -} - -TEST(SqlStatementBuilder, BindWithUpdateTemplateNames) -{ - Utf8StringVector columns({Utf8StringLiteral("name"), Utf8StringLiteral("number")}); - - SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("UPDATE $table SET $columnValues WHERE id=@id")); - sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); - sqlStatementBuilder.bindWithUpdateTemplateNames(Utf8StringLiteral("$columnValues"), columns); - - ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("UPDATE test SET name=@name, number=@number WHERE id=@id")); -} - -TEST(SqlStatementBuilder, ClearOnRebinding) -{ - SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table")); - - sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringLiteral("name, number")); - sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); - - ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("SELECT name, number FROM test")); - - sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test2")); - - ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("SELECT name, number FROM test2")); -} - -TEST(SqlStatementBuilder, ClearBinding) -{ - SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table")); - - sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringLiteral("name, number")); - sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); - - ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("SELECT name, number FROM test")); - - sqlStatementBuilder.clear(); - - ASSERT_THROW(sqlStatementBuilder.sqlStatement(), SqlStatementBuilderException); -} - -TEST(SqlStatementBuilder, ColumnType) -{ - ASSERT_THAT(SqlStatementBuilder::columnTypeToString(ColumnType::Numeric), Utf8StringLiteral("NUMERIC")); - ASSERT_THAT(SqlStatementBuilder::columnTypeToString(ColumnType::Integer), Utf8StringLiteral("INTEGER")); - ASSERT_THAT(SqlStatementBuilder::columnTypeToString(ColumnType::Real), Utf8StringLiteral("REAL")); - ASSERT_THAT(SqlStatementBuilder::columnTypeToString(ColumnType::Text), Utf8StringLiteral("TEXT")); - ASSERT_TRUE(SqlStatementBuilder::columnTypeToString(ColumnType::None).isEmpty()); -} - -TEST(SqlStatementBuilder, SqlStatementFailure) -{ - SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table")); - - sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringLiteral("name, number")); - - ASSERT_THROW(sqlStatementBuilder.sqlStatement(), SqlStatementBuilderException); -} - -TEST(SqlStatementBuilder, IsBuild) -{ - SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table")); - - sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringLiteral("name, number")); - sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); - - ASSERT_FALSE(sqlStatementBuilder.isBuild()); - - ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("SELECT name, number FROM test")); - - ASSERT_TRUE(sqlStatementBuilder.isBuild()); - - sqlStatementBuilder.clear(); - - ASSERT_FALSE(sqlStatementBuilder.isBuild()); -} diff --git a/tests/unit/codemodelbackend/unittest/translationunitstest.cpp b/tests/unit/codemodelbackend/unittest/translationunitstest.cpp deleted file mode 100644 index 533b422c3d..0000000000 --- a/tests/unit/codemodelbackend/unittest/translationunitstest.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gmock/gmock-generated-matchers.h" -#include "gtest-qt-printing.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using CodeModelBackEnd::TranslationUnit; -using CodeModelBackEnd::UnsavedFiles; -using CodeModelBackEnd::ProjectPart; - -using testing::IsNull; -using testing::NotNull; -using testing::Gt; -using testing::Not; -using testing::Contains; - -namespace { - -using ::testing::PrintToString; - -MATCHER_P2(IsTranslationUnit, filePath, projectPartId, - std::string(negation ? "isn't" : "is") + " translation unit with file path " - + PrintToString(filePath) + " and project " + PrintToString(projectPartId) - ) -{ - if (arg.filePath() != filePath) { - *result_listener << "file path is " + PrintToString(arg.filePath()) + " and not " + PrintToString(filePath); - return false; - } - - if (arg.projectPartId() != projectPartId) { - *result_listener << "file path is " + PrintToString(arg.projectPartId()) + " and not " + PrintToString(projectPartId); - return false; - } - - return true; -} - -class TranslationUnits : public ::testing::Test -{ -protected: - void SetUp() override; - - CodeModelBackEnd::ProjectParts projects; - CodeModelBackEnd::UnsavedFiles unsavedFiles; - CodeModelBackEnd::TranslationUnits translationUnits = CodeModelBackEnd::TranslationUnits(projects, unsavedFiles); - const Utf8String filePath = Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"); - const Utf8String projectPartId = Utf8StringLiteral("/path/to/projectfile"); - -}; - -void TranslationUnits::SetUp() -{ - projects.createOrUpdate({CodeModelBackEnd::ProjectPartContainer(projectPartId)}); -} - - -TEST_F(TranslationUnits, ThrowForGettingWithWrongFilePath) -{ - ASSERT_THROW(translationUnits.translationUnit(Utf8StringLiteral("foo.cpp"), projectPartId), - CodeModelBackEnd::TranslationUnitDoesNotExistException); - -} - -TEST_F(TranslationUnits, ThrowForGettingWithWrongProjectPartFilePath) -{ - ASSERT_THROW(translationUnits.translationUnit(filePath, Utf8StringLiteral("foo.pro")), - CodeModelBackEnd::ProjectPartDoNotExistException); - -} - -TEST_F(TranslationUnits, ThrowForAddingNonExistingFile) -{ - CodeModelBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), projectPartId); - - ASSERT_THROW(translationUnits.createOrUpdate({fileContainer}), - CodeModelBackEnd::TranslationUnitFileNotExitsException); -} - -TEST_F(TranslationUnits, DoNotThrowForAddingNonExistingFileWithUnsavedContent) -{ - CodeModelBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), projectPartId, Utf8String(), true); - - ASSERT_NO_THROW(translationUnits.createOrUpdate({fileContainer})); -} - -TEST_F(TranslationUnits, Add) -{ - CodeModelBackEnd::FileContainer fileContainer(filePath, projectPartId); - - translationUnits.createOrUpdate({fileContainer}); - - ASSERT_THAT(translationUnits.translationUnit(filePath, projectPartId), - IsTranslationUnit(filePath, projectPartId)); -} - -TEST_F(TranslationUnits, ThrowForRemovingWithWrongFilePath) -{ - CodeModelBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), projectPartId); - - ASSERT_THROW(translationUnits.remove({fileContainer}), - CodeModelBackEnd::TranslationUnitDoesNotExistException); -} - -TEST_F(TranslationUnits, ThrowForRemovingWithWrongProjectPartFilePath) -{ - CodeModelBackEnd::FileContainer fileContainer(filePath, Utf8StringLiteral("foo.pro")); - - ASSERT_THROW(translationUnits.remove({fileContainer}), - CodeModelBackEnd::ProjectPartDoNotExistException); -} - -TEST_F(TranslationUnits, Remove) -{ - CodeModelBackEnd::FileContainer fileContainer(filePath, projectPartId); - translationUnits.createOrUpdate({fileContainer}); - - translationUnits.remove({fileContainer}); - - ASSERT_THROW(translationUnits.translationUnit(filePath, projectPartId), - CodeModelBackEnd::TranslationUnitDoesNotExistException); -} - -TEST_F(TranslationUnits, RemoveAllValidIfExceptionIsThrown) -{ - CodeModelBackEnd::FileContainer fileContainer(filePath, projectPartId); - translationUnits.createOrUpdate({fileContainer}); - - ASSERT_THROW(translationUnits.remove({CodeModelBackEnd::FileContainer(Utf8StringLiteral("dontextist.pro"), projectPartId), fileContainer}), - CodeModelBackEnd::TranslationUnitDoesNotExistException); - - ASSERT_THAT(translationUnits.translationUnits(), - Not(Contains(TranslationUnit(filePath, unsavedFiles, projects.project(projectPartId))))); -} - -} - - diff --git a/tests/unit/codemodelbackend/unittest/translationunittest.cpp b/tests/unit/codemodelbackend/unittest/translationunittest.cpp deleted file mode 100644 index e2a91b6948..0000000000 --- a/tests/unit/codemodelbackend/unittest/translationunittest.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gmock/gmock-generated-matchers.h" -#include "gtest-qt-printing.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -using CodeModelBackEnd::TranslationUnit; -using CodeModelBackEnd::UnsavedFiles; -using CodeModelBackEnd::ProjectPart; - -using testing::IsNull; -using testing::NotNull; -using testing::Gt; - -namespace { - -TEST(TranslationUnit, DefaultTranslationUnitIsInvalid) -{ - TranslationUnit translationUnit; - - ASSERT_TRUE(translationUnit.isNull()); -} - -TEST(TranslationUnit, ThrowExceptionForNonExistingFilePath) -{ - ASSERT_THROW(TranslationUnit(Utf8StringLiteral("file.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile"))), - CodeModelBackEnd::TranslationUnitFileNotExitsException); -} - -TEST(TranslationUnit, ThrowNoExceptionForNonExistingFilePathIfDoNotCheckIfFileExistsIsSet) -{ - ASSERT_NO_THROW(TranslationUnit(Utf8StringLiteral("file.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile")), TranslationUnit::DoNotCheckIfFileExists)); -} - -TEST(TranslationUnit, TranslationUnitIsValid) -{ - TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile"))); - - ASSERT_FALSE(translationUnit.isNull()); -} - - -TEST(TranslationUnit, ThrowExceptionForGettingIndexForInvalidUnit) -{ - TranslationUnit translationUnit; - - ASSERT_THROW(translationUnit.index(), CodeModelBackEnd::TranslationUnitIsNullException); -} - -TEST(TranslationUnit, IndexGetterIsNonNullForValidUnit) -{ - TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile"))); - - ASSERT_THAT(translationUnit.index(), NotNull()); -} - -TEST(TranslationUnit, ThrowExceptionForGettingCxTranslationUnitForInvalidUnit) -{ - TranslationUnit translationUnit; - - ASSERT_THROW(translationUnit.cxTranslationUnit(), CodeModelBackEnd::TranslationUnitIsNullException); -} - -TEST(TranslationUnit, CxTranslationUnitGetterIsNonNullForValidUnit) -{ - UnsavedFiles unsavedFiles; - TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), unsavedFiles, ProjectPart(Utf8StringLiteral("/path/to/projectfile"))); - - ASSERT_THAT(translationUnit.cxTranslationUnit(), NotNull()); -} - -TEST(TranslationUnit, ThrowExceptionIfGettingFilePathForNullUnit) -{ - TranslationUnit translationUnit; - - ASSERT_THROW(translationUnit.filePath(), CodeModelBackEnd::TranslationUnitIsNullException); -} - -TEST(TranslationUnit, ResetedTranslationUnitIsNull) -{ - TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile"))); - - translationUnit.reset(); - - ASSERT_TRUE(translationUnit.isNull()); -} - -TEST(TranslationUnit, TimeStampIsUpdatedAsNewCxTranslationUnitIsGenerated) -{ - TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile"))); - auto lastChangeTimePoint = translationUnit.lastChangeTimePoint(); - std::this_thread::sleep_for(std::chrono::steady_clock::duration(1)); - - translationUnit.cxTranslationUnit(); - - ASSERT_THAT(translationUnit.lastChangeTimePoint(), Gt(lastChangeTimePoint)); -} - - -//TEST(TranslationUnit, ThrowParseErrorForWrongArguments) -//{ -// ProjectPart project(Utf8StringLiteral("/path/to/projectfile")); -// project.setArguments({Utf8StringLiteral("-fblah")}); -// TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), UnsavedFiles(), project); - -// ASSERT_THROW(translationUnit.cxTranslationUnit(), CodeModelBackEnd::TranslationUnitParseErrorException); -//} - -} diff --git a/tests/unit/codemodelbackend/unittest/unittest.pro b/tests/unit/codemodelbackend/unittest/unittest.pro deleted file mode 100644 index 88d946f74f..0000000000 --- a/tests/unit/codemodelbackend/unittest/unittest.pro +++ /dev/null @@ -1,89 +0,0 @@ -QT += core network testlib -QT -= gui - -TARGET = codemodelbackendtest -CONFIG += console c++14 testcase -CONFIG -= app_bundle - -TEMPLATE = app - -GMOCK_DIR = $$(GMOCK_DIR) -GTEST_DIR = $$GMOCK_DIR/gtest - -requires(exists($$GMOCK_DIR)) -!exists($$GMOCK_DIR):message("No gmock is found! To enabe unit tests set GMOCK_DIR") - -INCLUDEPATH += $$GTEST_DIR $$GTEST_DIR/include $$GMOCK_DIR $$GMOCK_DIR/include - -include(../../../../src/libs/sqlite/sqlite-lib.pri) -include(../../../../src/libs/codemodelbackendipc/codemodelbackendipc-lib.pri) -include(../../../../src/tools/codemodelbackend/ipcsource/codemodelbackendclangipc-source.pri) -include(../../../../src/shared/clang/clang_installation.pri) -include(../../../../src/plugins/clangcodemodel/clangcodemodelunittestfiles.pri) - -INCLUDEPATH += $$PWD/../../../../src/libs $$PWD/../../../../src/plugins - -requires(!isEmpty(LLVM_LIBS)) - -LIBS += $$LLVM_LIBS -INCLUDEPATH += $$LLVM_INCLUDEPATH -INCLUDEPATH += ../../../../src/libs/utils - -osx:QMAKE_CXXFLAGS = -stdlib=libc++ - -SOURCES += main.cpp \ - $$GTEST_DIR/src/gtest-all.cc \ - $$GMOCK_DIR/src/gmock-all.cc \ - utf8test.cpp \ - sqlstatementbuildertest.cpp \ - createtablesqlstatementbuildertest.cpp \ - sqlitecolumntest.cpp \ - sqlitestatementtest.cpp \ - sqlitetabletest.cpp \ - spydummy.cpp \ - sqlitedatabasetest.cpp \ - sqlitedatabasebackendtest.cpp \ - readandwritecommandblocktest.cpp \ - clientserverinprocesstest.cpp \ - clientserveroutsideprocess.cpp \ - gtest-qt-printing.cpp \ - codecompletiontest.cpp \ - ../../../../src/libs/utils/qtcassert.cpp \ - clangstringtest.cpp \ - translationunittest.cpp \ - clangcodecompleteresultstest.cpp \ - codecompletionsextractortest.cpp \ - unsavedfilestest.cpp \ - projecttest.cpp \ - clangipcservertest.cpp \ - translationunitstest.cpp \ - completionchunkstotextconvertertest.cpp - -HEADERS += \ - gtest-qt-printing.h \ - spydummy.h \ - ../../../../src/libs/utils/qtcassert.h \ - mockipclient.h \ - mockipcserver.h - -OTHER_FILES += data/complete_testfile_1.cpp \ - data/complete_completer.cpp \ - data/complete_completer_unsaved.cpp \ - data/complete_extractor_function.cpp \ - data/complete_extractor_function_unsaved.cpp \ - data/complete_extractor_function_unsaved_2.cpp \ - data/complete_extractor_variable.cpp \ - data/complete_extractor_class.cpp \ - data/complete_extractor_namespace.cpp \ - data/complete_extractor_enumeration.cpp \ - data/complete_extractor_constructor.cpp \ - data/complete_translationunit_parse_error.cpp - -DEFINES += QT_NO_CAST_FROM_ASCII -DEFINES += CODEMODELBACKEND_TESTS -DEFINES += DONT_CHECK_COMMAND_COUNTER -DEFINES += GTEST_HAS_STD_INITIALIZER_LIST_ GTEST_LANG_CXX11 - -DEFINES += TESTDATA_DIR=\"R\\\"xxx($$PWD/data)xxx\\\"\" -win32:DEFINES += ECHOSERVER=\"R\\\"xxx($$OUT_PWD/../echo)xxx\\\"\" -unix:DEFINES += ECHOSERVER=\"R\\\"xxx($$OUT_PWD/../echoserver/echo)xxx\\\"\" diff --git a/tests/unit/codemodelbackend/unittest/unsavedfilestest.cpp b/tests/unit/codemodelbackend/unittest/unsavedfilestest.cpp deleted file mode 100644 index 0da931ec81..0000000000 --- a/tests/unit/codemodelbackend/unittest/unsavedfilestest.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gmock/gmock.h" -#include "gtest-qt-printing.h" - -#include -#include - -#include - -using CodeModelBackEnd::UnsavedFiles; -using CodeModelBackEnd::FileContainer; - -using ::testing::IsNull; -using ::testing::NotNull; -using ::testing::Gt; - -namespace { - -bool operator==(const CodeModelBackEnd::FileContainer &fileContainer, const CXUnsavedFile &cxUnsavedFile) -{ - return fileContainer.filePath() == Utf8String::fromUtf8(cxUnsavedFile.Filename) - && fileContainer.unsavedFileContent() == Utf8String(cxUnsavedFile.Contents, cxUnsavedFile.Length); -} - -bool fileContainersContainsItemMatchingToCxUnsavedFile(const QVector &fileContainers, const CXUnsavedFile &cxUnsavedFile) -{ - for (const FileContainer &fileContainer : fileContainers) - if (fileContainer == cxUnsavedFile) - return true; - - return false; -} - -MATCHER_P(HasUnsavedFiles, fileContainers, "") -{ - CodeModelBackEnd::UnsavedFiles unsavedFiles = arg; - if (unsavedFiles.count() != fileContainers.size()) { - *result_listener << "unsaved count is " << unsavedFiles.count() << " and not " << fileContainers.size(); - return false; - } - - for (const CXUnsavedFile &cxUnsavedFile : unsavedFiles.cxUnsavedFileVector()) { - if (!fileContainersContainsItemMatchingToCxUnsavedFile(fileContainers, cxUnsavedFile)) - return false; - } - - return true; -} - -class UnsavedFiles : public ::testing::Test -{ -protected: - void TearDown() override; - -protected: - ::UnsavedFiles unsavedFiles; -}; - -void UnsavedFiles::TearDown() -{ - unsavedFiles.clear(); -} - -TEST_F(UnsavedFiles, DoNothingForUpdateIfFileHasNoUnsavedContent) -{ - QVector fileContainers({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"))}); - - unsavedFiles.createOrUpdate(fileContainers); - - ASSERT_THAT(unsavedFiles, HasUnsavedFiles(QVector())); -} - -TEST_F(UnsavedFiles, AddUnsavedFileForUpdateWithUnsavedContent) -{ - QVector fileContainers({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro")), - FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo"), true)}); - unsavedFiles.createOrUpdate(fileContainers); - - ASSERT_THAT(unsavedFiles, HasUnsavedFiles(QVector({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo"), true)}))); -} - -TEST_F(UnsavedFiles, RemoveUnsavedFileForUpdateWithUnsavedContent) -{ - QVector fileContainers({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo"), true), - FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"))}); - - unsavedFiles.createOrUpdate(fileContainers); - - ASSERT_THAT(unsavedFiles, HasUnsavedFiles(QVector())); -} - -TEST_F(UnsavedFiles, ExchangeUnsavedFileForUpdateWithUnsavedContent) -{ - QVector fileContainers({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo"), true), - FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo2"), true)}); - unsavedFiles.createOrUpdate(fileContainers); - - ASSERT_THAT(unsavedFiles, HasUnsavedFiles(QVector({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo2"), true)}))); -} - -TEST_F(UnsavedFiles, TimeStampIsUpdatedAsUnsavedFilesChanged) -{ - QVector fileContainers({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo"), true), - FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo2"), true)}); - auto lastChangeTimePoint = unsavedFiles.lastChangeTimePoint(); - - unsavedFiles.createOrUpdate(fileContainers); - - ASSERT_THAT(unsavedFiles.lastChangeTimePoint(), Gt(lastChangeTimePoint)); -} - -TEST_F(UnsavedFiles, RemoveUnsavedFiles) -{ - QVector fileContainers({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo"), true)}); - unsavedFiles.createOrUpdate(fileContainers); - - unsavedFiles.remove(fileContainers); - - ASSERT_THAT(unsavedFiles, HasUnsavedFiles(QVector())); -} -} - - diff --git a/tests/unit/codemodelbackend/unittest/utf8test.cpp b/tests/unit/codemodelbackend/unittest/utf8test.cpp deleted file mode 100644 index db4dcb0e81..0000000000 --- a/tests/unit/codemodelbackend/unittest/utf8test.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://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 Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "gtest/gtest.h" -#include "gmock/gmock-matchers.h" -#include "gtest-qt-printing.h" - -#include - -#include - -using namespace ::testing; - -TEST(Utf8, QStringConversionConstructor) -{ - ASSERT_THAT(Utf8String(QStringLiteral("text")), Utf8StringLiteral("text")); -} - -TEST(Utf8, QByteArrayConversionFunction) -{ - ASSERT_THAT(Utf8String::fromByteArray("text"), Utf8StringLiteral("text")); -} - -TEST(Utf8, QStringConversionFunction) -{ - ASSERT_THAT(Utf8String::fromString(QStringLiteral("text")), Utf8StringLiteral("text")); -} - -TEST(Utf8, Utf8ConversationFunction) -{ - ASSERT_THAT(Utf8String::fromUtf8("text"), Utf8StringLiteral("text")); -} - -TEST(Utf8, Mid) -{ - Utf8String text(Utf8StringLiteral("some text")); - - ASSERT_THAT(text.mid(5, 4), Utf8StringLiteral("text")); - ASSERT_THAT(text.mid(5), Utf8StringLiteral("text")); -} - -TEST(Utf8, ByteSize) -{ - ASSERT_THAT(Utf8StringLiteral("text").byteSize(), 4); -} - -TEST(Utf8, Append) -{ - Utf8String text(Utf8StringLiteral("some ")); - text.append(Utf8StringLiteral("text")); - - ASSERT_THAT(text, Utf8StringLiteral("some text")); -} - -TEST(Utf8, ToByteArray) -{ - Utf8String text(Utf8StringLiteral("some text")); - - ASSERT_THAT(text.toByteArray(), QByteArrayLiteral("some text")); -} - -TEST(Utf8, ToString) -{ - Utf8String text(Utf8StringLiteral("some text")); - - ASSERT_THAT(text.toString(), QStringLiteral("some text")); -} - - -TEST(Utf8, Contains) -{ - Utf8String text(Utf8StringLiteral("some text")); - - ASSERT_TRUE(text.contains(Utf8StringLiteral("text"))); - ASSERT_TRUE(text.contains("text")); - ASSERT_TRUE(text.contains('x')); -} - -TEST(Utf8, EqualOperator) -{ - ASSERT_TRUE(Utf8StringLiteral("text") == Utf8StringLiteral("text")); - ASSERT_FALSE(Utf8StringLiteral("text") == Utf8StringLiteral("text2")); -} - -TEST(Utf8, SmallerOperator) -{ - ASSERT_TRUE(Utf8StringLiteral("some") < Utf8StringLiteral("text")); - ASSERT_TRUE(Utf8StringLiteral("text") < Utf8StringLiteral("texta")); - ASSERT_FALSE(Utf8StringLiteral("text") < Utf8StringLiteral("some")); - ASSERT_FALSE(Utf8StringLiteral("text") < Utf8StringLiteral("text")); -} - -TEST(Utf8, UnequalOperator) -{ - ASSERT_FALSE(Utf8StringLiteral("text") != Utf8StringLiteral("text")); - ASSERT_TRUE(Utf8StringLiteral("text") != Utf8StringLiteral("text2")); -} - -TEST(Utf8, Join) -{ - Utf8StringVector vector; - - vector.append(Utf8StringLiteral("some")); - vector.append(Utf8StringLiteral("text")); - - ASSERT_THAT(Utf8StringLiteral("some, text"), vector.join(Utf8StringLiteral(", "))); -} - -TEST(Utf8, Split) -{ - Utf8String test(Utf8StringLiteral("some text")); - - Utf8StringVector splittedText = test.split(' '); - - ASSERT_THAT(splittedText.at(0), Utf8StringLiteral("some")); - ASSERT_THAT(splittedText.at(1), Utf8StringLiteral("text")); -} - -TEST(Utf8, IsEmpty) -{ - ASSERT_FALSE(Utf8StringLiteral("text").isEmpty()); - ASSERT_TRUE(Utf8String().isEmpty()); -} - -TEST(Utf8, HasContent) -{ - ASSERT_TRUE(Utf8StringLiteral("text").hasContent()); - ASSERT_FALSE(Utf8String().hasContent()); -} - -TEST(Utf8, Replace) -{ - Utf8String text(Utf8StringLiteral("some text")); - - text.replace(Utf8StringLiteral("some"), Utf8StringLiteral("any")); - - ASSERT_THAT(text, Utf8StringLiteral("any text")); -} - -TEST(Utf8, StartsWith) -{ - Utf8String text(Utf8StringLiteral("$column")); - - ASSERT_TRUE(text.startsWith(Utf8StringLiteral("$col"))); - ASSERT_FALSE(text.startsWith(Utf8StringLiteral("col"))); - ASSERT_TRUE(text.startsWith("$col")); - ASSERT_FALSE(text.startsWith("col")); - ASSERT_TRUE(text.startsWith('$')); - ASSERT_FALSE(text.startsWith('@')); -} - -TEST(Utf8, Clear) -{ - Utf8String text(Utf8StringLiteral("$column")); - - text.clear(); - - ASSERT_TRUE(text.isEmpty()); -} - -TEST(Utf8, Number) -{ - ASSERT_THAT(Utf8String::number(20), Utf8StringLiteral("20")); -} - -TEST(Utf8, FromIntegerVector) -{ - QVector integers({1, 2, 3}); - - ASSERT_THAT(Utf8StringVector::fromIntegerVector(integers).join(Utf8StringLiteral(", ")), Utf8StringLiteral("1, 2, 3")); -} - -TEST(Utf8, PlusOperator) -{ - auto text = Utf8StringLiteral("foo") + Utf8StringLiteral("bar"); - - ASSERT_THAT(text, Utf8StringLiteral("foobar")); -} - -TEST(Utf8, PlusAssignmentOperator) -{ - Utf8String text("foo", 3); - - text += Utf8StringLiteral("bar"); - - ASSERT_THAT(text, Utf8StringLiteral("foobar")); -} - -TEST(Utf8, CompareCharPointer) -{ - Utf8String text("foo", 3); - - ASSERT_TRUE(text == "foo"); - ASSERT_FALSE(text == "foo2"); -} - -TEST(Utf8, RemoveFastFromVectorFailed) -{ - Utf8StringVector values({Utf8StringLiteral("a"), - Utf8StringLiteral("b"), - Utf8StringLiteral("c"), - Utf8StringLiteral("d")}); - - ASSERT_FALSE(values.removeFast(Utf8StringLiteral("e"))); -} - -TEST(Utf8, RemoveFastFromVector) -{ - Utf8StringVector values({Utf8StringLiteral("a"), - Utf8StringLiteral("b"), - Utf8StringLiteral("c"), - Utf8StringLiteral("d")}); - - bool removed = values.removeFast(Utf8StringLiteral("b")); - - ASSERT_TRUE(removed); - ASSERT_THAT(values, Not(Contains(Utf8StringLiteral("b")))); -} - -TEST(Utf8, ConverteAutomaticallyFromQString) -{ - QString text(QStringLiteral("foo")); - - Utf8String utf8Text(text); - - ASSERT_THAT(utf8Text, Utf8StringLiteral("foo")); -} - -TEST(Utf8, ConverteAutomaticallyToQString) -{ - Utf8String utf8Text(Utf8StringLiteral("foo")); - - QString text = utf8Text; - - ASSERT_THAT(text, QStringLiteral("foo")); -} - -TEST(Utf8, ConverteAutomaticallyToQByteArray) -{ - Utf8String utf8Text(Utf8StringLiteral("foo")); - - QByteArray bytes = utf8Text; - - ASSERT_THAT(bytes, QByteArrayLiteral("foo")); -} - diff --git a/tests/unit/echoserver/echoipcserver.cpp b/tests/unit/echoserver/echoipcserver.cpp new file mode 100644 index 0000000000..81a818d0a5 --- /dev/null +++ b/tests/unit/echoserver/echoipcserver.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "echoipcserver.h" + +#include "cmbendcommand.h" +#include "cmbechocommand.h" +#include "cmbregistertranslationunitsforcodecompletioncommand.h" +#include "cmbunregistertranslationunitsforcodecompletioncommand.h" +#include "cmbregisterprojectsforcodecompletioncommand.h" +#include "cmbunregisterprojectsforcodecompletioncommand.h" +#include "cmbcompletecodecommand.h" +#include "cmbcodecompletedcommand.h" + +#include "connectionserver.h" + +#include + +#include + +namespace ClangBackEnd { + +void EchoIpcServer::dispatch(const QVariant &command) +{ + IpcServerInterface::dispatch(command); +} + +void EchoIpcServer::end() +{ + ConnectionServer::removeServer(); + QCoreApplication::quit(); +} + +void EchoIpcServer::registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) +{ + echoCommand(QVariant::fromValue(command)); +} + +void EchoIpcServer::unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) +{ + echoCommand(QVariant::fromValue(command)); +} + +void EchoIpcServer::registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) +{ + echoCommand(QVariant::fromValue(command)); +} + +void EchoIpcServer::unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) +{ + echoCommand(QVariant::fromValue(command)); +} + +void EchoIpcServer::completeCode(const CompleteCodeCommand &command) +{ + echoCommand(QVariant::fromValue(command)); +} + +void EchoIpcServer::echoCommand(const QVariant &command) +{ + client()->echo(EchoCommand(command)); +} + +} // namespace ClangBackEnd + diff --git a/tests/unit/echoserver/echoipcserver.h b/tests/unit/echoserver/echoipcserver.h new file mode 100644 index 0000000000..55f18994a0 --- /dev/null +++ b/tests/unit/echoserver/echoipcserver.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_ECHOIPCSERVER_H +#define CLANGBACKEND_ECHOIPCSERVER_H + +#include + +namespace ClangBackEnd { + +class EchoIpcServer : public IpcServerInterface +{ +public: + void dispatch(const QVariant &command) override; + void end() override; + void registerTranslationUnitsForCodeCompletion(const RegisterTranslationUnitForCodeCompletionCommand &command) override; + void unregisterTranslationUnitsForCodeCompletion(const UnregisterTranslationUnitsForCodeCompletionCommand &command) override; + void registerProjectPartsForCodeCompletion(const RegisterProjectPartsForCodeCompletionCommand &command) override; + void unregisterProjectPartsForCodeCompletion(const UnregisterProjectPartsForCodeCompletionCommand &command) override; + void completeCode(const CompleteCodeCommand &command) override; + +private: + void echoCommand(const QVariant &command); +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_ECHOIPCSERVER_H diff --git a/tests/unit/echoserver/echoserver.pro b/tests/unit/echoserver/echoserver.pro new file mode 100644 index 0000000000..7c3db335b9 --- /dev/null +++ b/tests/unit/echoserver/echoserver.pro @@ -0,0 +1,28 @@ +QT += core network + +QT -= gui + +TARGET = echo +CONFIG += console c++14 +CONFIG -= app_bundle + +TEMPLATE = app + +unix:LIBS += -ldl + +osx:QMAKE_CXXFLAGS = -stdlib=libc++ + +include(../../../src/libs/clangbackendipc/clangbackendipc-lib.pri) +include(../../../src/libs/sqlite/sqlite-lib.pri) + +SOURCES += \ + echoipcserver.cpp \ + echoserverprocessmain.cpp + +HEADERS += \ + echoipcserver.h + +DEFINES += CLANGBACKENDIPC_TESTS +DEFINES += DONT_CHECK_COMMAND_COUNTER + +win32:DESTDIR = .. diff --git a/tests/unit/echoserver/echoserverprocessmain.cpp b/tests/unit/echoserver/echoserverprocessmain.cpp new file mode 100644 index 0000000000..3a8b0b1ed5 --- /dev/null +++ b/tests/unit/echoserver/echoserverprocessmain.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include + +#include "echoipcserver.h" +#include "connectionserver.h" +#include "cmbcommands.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication::setOrganizationName("QtProject"); + QCoreApplication::setOrganizationDomain("qt-project.org"); + QCoreApplication::setApplicationName("EchoCodeModelBackend"); + QCoreApplication::setApplicationVersion("1.0.0"); + + QCoreApplication application(argc, argv); + + if (application.arguments().count() != 2) { + qWarning() << "wrong argument count"; + return 1; + } + + ClangBackEnd::Commands::registerCommands(); + + ClangBackEnd::EchoIpcServer echoIpcServer; + ClangBackEnd::ConnectionServer connectionServer(application.arguments()[1]); + connectionServer.start(); + connectionServer.setIpcServer(&echoIpcServer); + + return application.exec(); +} diff --git a/tests/unit/unit.pro b/tests/unit/unit.pro new file mode 100644 index 0000000000..cbd0d9bb05 --- /dev/null +++ b/tests/unit/unit.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs + +SUBDIRS = echoserver unittest + +unittest.depends = echoserver diff --git a/tests/unit/unittest/clangcodecompleteresultstest.cpp b/tests/unit/unittest/clangcodecompleteresultstest.cpp new file mode 100644 index 0000000000..228ec8ce87 --- /dev/null +++ b/tests/unit/unittest/clangcodecompleteresultstest.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gmock/gmock.h" +#include "gtest-qt-printing.h" + +#include + +#include +#include +#include +#include +#include + +namespace { + +using ClangBackEnd::ClangCodeCompleteResults; +using ClangBackEnd::TranslationUnit; +using ClangBackEnd::UnsavedFiles; +using ClangBackEnd::ProjectPart; + +TEST(ClangCodeCompleteResults, GetData) +{ + ProjectPart projectPart(Utf8StringLiteral("projectPartId")); + UnsavedFiles unsavedFiles; + TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), unsavedFiles, projectPart); + CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(translationUnit.cxTranslationUnit(), translationUnit.filePath().constData(), 49, 1, 0, 0, 0); + + ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults); + + ASSERT_THAT(codeCompleteResults.data(), cxCodeCompleteResults); +} + +TEST(ClangCodeCompleteResults, GetInvalidData) +{ + CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(nullptr, "file.cpp", 49, 1, 0, 0, 0); + + ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults); + + ASSERT_THAT(codeCompleteResults.data(), cxCodeCompleteResults); +} + +TEST(ClangCodeCompleteResults, MoveClangCodeCompleteResults) +{ + ProjectPart projectPart(Utf8StringLiteral("projectPartId")); + UnsavedFiles unsavedFiles; + TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), unsavedFiles, projectPart); + CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(translationUnit.cxTranslationUnit(), translationUnit.filePath().constData(), 49, 1, 0, 0, 0); + + ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults); + + const ClangCodeCompleteResults codeCompleteResults2 = std::move(codeCompleteResults); + + ASSERT_TRUE(codeCompleteResults.isNull()); + ASSERT_FALSE(codeCompleteResults2.isNull()); +} + +} diff --git a/tests/unit/unittest/clangipcservertest.cpp b/tests/unit/unittest/clangipcservertest.cpp new file mode 100644 index 0000000000..4070ad0579 --- /dev/null +++ b/tests/unit/unittest/clangipcservertest.cpp @@ -0,0 +1,382 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gmock/gmock.h" + +#include "gtest-qt-printing.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mockipclient.h" + +using testing::Property; +using testing::Contains; +using testing::Not; +using testing::Eq; + +namespace { + +using ClangBackEnd::RegisterTranslationUnitForCodeCompletionCommand; +using ClangBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand; +using ClangBackEnd::RegisterProjectPartsForCodeCompletionCommand; +using ClangBackEnd::UnregisterProjectPartsForCodeCompletionCommand; +using ClangBackEnd::CompleteCodeCommand; +using ClangBackEnd::CodeCompletedCommand; +using ClangBackEnd::CodeCompletion; +using ClangBackEnd::FileContainer; +using ClangBackEnd::ProjectPartContainer; +using ClangBackEnd::TranslationUnitDoesNotExistCommand; +using ClangBackEnd::ProjectPartsDoNotExistCommand; + +class ClangIpcServer : public ::testing::Test +{ +protected: + void SetUp() override; + + void registerFiles(); + void registerProjectPart(); + void changeProjectPartArguments(); + void changeProjectPartArgumentsToWrongValues(); + static const Utf8String unsavedContent(const QString &unsavedFilePath); + +protected: + MockIpcClient mockIpcClient; + ClangBackEnd::ClangIpcServer clangServer; + const Utf8String projectPartId = Utf8StringLiteral("pathToProjectPart.pro"); + const Utf8String functionTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"); + const Utf8String variableTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp"); + const QString unsavedTestFilePath = QStringLiteral(TESTDATA_DIR) + QStringLiteral("/complete_extractor_function_unsaved.cpp"); + const QString updatedUnsavedTestFilePath = QStringLiteral(TESTDATA_DIR) + QStringLiteral("/complete_extractor_function_unsaved_2.cpp"); + const Utf8String parseErrorTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_translationunit_parse_error.cpp"); +}; + + +void ClangIpcServer::SetUp() +{ + clangServer.addClient(&mockIpcClient); + registerProjectPart(); + registerFiles(); +} + +void ClangIpcServer::registerFiles() +{ + RegisterTranslationUnitForCodeCompletionCommand command({FileContainer(functionTestFilePath, projectPartId, unsavedContent(unsavedTestFilePath), true), + FileContainer(variableTestFilePath, projectPartId)}); + + clangServer.registerTranslationUnitsForCodeCompletion(command); +} + +void ClangIpcServer::registerProjectPart() +{ + RegisterProjectPartsForCodeCompletionCommand command({ProjectPartContainer(projectPartId)}); + + clangServer.registerProjectPartsForCodeCompletion(command); +} + +void ClangIpcServer::changeProjectPartArguments() +{ + RegisterProjectPartsForCodeCompletionCommand command({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DArgumentDefinition")})}); + + clangServer.registerProjectPartsForCodeCompletion(command); +} + +void ClangIpcServer::changeProjectPartArgumentsToWrongValues() +{ + RegisterProjectPartsForCodeCompletionCommand command({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-blah")})}); + + clangServer.registerProjectPartsForCodeCompletion(command); +} + +const Utf8String ClangIpcServer::unsavedContent(const QString &unsavedFilePath) +{ + QFile unsavedFileContentFile(unsavedFilePath); + bool isOpen = unsavedFileContentFile.open(QIODevice::ReadOnly | QIODevice::Text); + if (!isOpen) + ADD_FAILURE() << "File with the unsaved content cannot be opened!"; + + return Utf8String::fromByteArray(unsavedFileContentFile.readAll()); +} + +TEST_F(ClangIpcServer, GetCodeCompletion) +{ + CompleteCodeCommand completeCodeCommand(functionTestFilePath, + 20, + 1, + projectPartId); + CodeCompletion codeCompletion(Utf8StringLiteral("Function"), + Utf8String(), + Utf8String(), + 34, + CodeCompletion::FunctionCompletionKind); + + EXPECT_CALL(mockIpcClient, codeCompleted(Property(&CodeCompletedCommand::codeCompletions, Contains(codeCompletion)))) + .Times(1); + + clangServer.completeCode(completeCodeCommand); +} + +TEST_F(ClangIpcServer, GetCodeCompletionDependingOnArgumets) +{ + CompleteCodeCommand completeCodeCommand(variableTestFilePath, + 35, + 1, + projectPartId); + CodeCompletion codeCompletion(Utf8StringLiteral("ArgumentDefinitionVariable"), + Utf8String(), + Utf8String(), + 34, + CodeCompletion::VariableCompletionKind); + + EXPECT_CALL(mockIpcClient, codeCompleted(Property(&CodeCompletedCommand::codeCompletions, Contains(codeCompletion)))) + .Times(1); + + changeProjectPartArguments(); + clangServer.completeCode(completeCodeCommand); +} + +TEST_F(ClangIpcServer, GetTranslationUnitDoesNotExistForCodeCompletionOnNonExistingTranslationUnit) +{ + CompleteCodeCommand completeCodeCommand(Utf8StringLiteral("dontexists.cpp"), + 34, + 1, + projectPartId); + TranslationUnitDoesNotExistCommand translationUnitDoesNotExistCommand(Utf8StringLiteral("dontexists.cpp"), projectPartId); + + EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(translationUnitDoesNotExistCommand)) + .Times(1); + + clangServer.completeCode(completeCodeCommand); +} + +TEST_F(ClangIpcServer, GetTranslationUnitDoesNotExistForCompletingUnregisteredFile) +{ + CompleteCodeCommand completeCodeCommand(parseErrorTestFilePath, + 20, + 1, + projectPartId); + TranslationUnitDoesNotExistCommand translationUnitDoesNotExistCommand(parseErrorTestFilePath, projectPartId); + + EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(translationUnitDoesNotExistCommand)) + .Times(1); + + clangServer.completeCode(completeCodeCommand); +} + +TEST_F(ClangIpcServer, GetCodeCompletionForUnsavedFile) +{ + CompleteCodeCommand completeCodeCommand(functionTestFilePath, + 20, + 1, + projectPartId); + CodeCompletion codeCompletion(Utf8StringLiteral("Method2"), + Utf8String(), + Utf8String(), + 34, + CodeCompletion::FunctionCompletionKind); + + EXPECT_CALL(mockIpcClient, codeCompleted(Property(&CodeCompletedCommand::codeCompletions, Contains(codeCompletion)))) + .Times(1); + + clangServer.completeCode(completeCodeCommand); +} + +TEST_F(ClangIpcServer, GetNoCodeCompletionAfterRemovingUnsavedFile) +{ + clangServer.registerTranslationUnitsForCodeCompletion(RegisterTranslationUnitForCodeCompletionCommand({FileContainer(functionTestFilePath, projectPartId)})); + CompleteCodeCommand completeCodeCommand(functionTestFilePath, + 20, + 1, + projectPartId); + CodeCompletion codeCompletion(Utf8StringLiteral("Method2"), + Utf8String(), + Utf8String(), + 34, + CodeCompletion::FunctionCompletionKind); + + EXPECT_CALL(mockIpcClient, codeCompleted(Property(&CodeCompletedCommand::codeCompletions, Not(Contains(codeCompletion))))) + .Times(1); + + clangServer.completeCode(completeCodeCommand); +} + +TEST_F(ClangIpcServer, GetNewCodeCompletionAfterUpdatingUnsavedFile) +{ + clangServer.registerTranslationUnitsForCodeCompletion(RegisterTranslationUnitForCodeCompletionCommand({FileContainer(functionTestFilePath, + projectPartId, + unsavedContent(updatedUnsavedTestFilePath), + true)})); + CompleteCodeCommand completeCodeCommand(functionTestFilePath, + 20, + 1, + projectPartId); + CodeCompletion codeCompletion(Utf8StringLiteral("Method3"), + Utf8String(), + Utf8String(), + 34, + CodeCompletion::FunctionCompletionKind); + + EXPECT_CALL(mockIpcClient, codeCompleted(Property(&CodeCompletedCommand::codeCompletions, Contains(codeCompletion)))) + .Times(1); + + clangServer.completeCode(completeCodeCommand); +} + +TEST_F(ClangIpcServer, GetTranslationUnitDoesNotExistForUnregisterTranslationUnitWithWrongFilePath) +{ + FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), projectPartId); + UnregisterTranslationUnitsForCodeCompletionCommand command({fileContainer}); + TranslationUnitDoesNotExistCommand translationUnitDoesNotExistCommand(fileContainer); + + EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(translationUnitDoesNotExistCommand)) + .Times(1); + + clangServer.unregisterTranslationUnitsForCodeCompletion(command); +} + +TEST_F(ClangIpcServer, UnregisterTranslationUnitAndTestFailingCompletion) +{ + FileContainer fileContainer(functionTestFilePath, projectPartId); + UnregisterTranslationUnitsForCodeCompletionCommand command({fileContainer}); + clangServer.unregisterTranslationUnitsForCodeCompletion(command); + CompleteCodeCommand completeCodeCommand(functionTestFilePath, + 20, + 1, + projectPartId); + TranslationUnitDoesNotExistCommand translationUnitDoesNotExistCommand(fileContainer); + + EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(translationUnitDoesNotExistCommand)) + .Times(1); + + clangServer.completeCode(completeCodeCommand); +} + +TEST_F(ClangIpcServer, GetProjectPartDoesNotExistUnregisterProjectPartInexistingProjectPart) +{ + Utf8StringVector inexistingProjectPartFilePath = {Utf8StringLiteral("projectpartsdoesnotexist.pro"), Utf8StringLiteral("project2doesnotexists.pro")}; + UnregisterProjectPartsForCodeCompletionCommand unregisterProjectPartsForCodeCompletionCommand(inexistingProjectPartFilePath); + ProjectPartsDoNotExistCommand projectPartsDoNotExistCommand(inexistingProjectPartFilePath); + + EXPECT_CALL(mockIpcClient, projectPartsDoNotExist(projectPartsDoNotExistCommand)) + .Times(1); + + clangServer.unregisterProjectPartsForCodeCompletion(unregisterProjectPartsForCodeCompletionCommand); +} + +TEST_F(ClangIpcServer, GetProjectPartDoesNotExistRegisterTranslationUnitWithInexistingProjectPart) +{ + Utf8String inexistingProjectPartFilePath = Utf8StringLiteral("projectpartsdoesnotexist.pro"); + RegisterTranslationUnitForCodeCompletionCommand registerFileForCodeCompletionCommand({FileContainer(variableTestFilePath, inexistingProjectPartFilePath)}); + ProjectPartsDoNotExistCommand projectPartsDoNotExistCommand({inexistingProjectPartFilePath}); + + EXPECT_CALL(mockIpcClient, projectPartsDoNotExist(projectPartsDoNotExistCommand)) + .Times(1); + + clangServer.registerTranslationUnitsForCodeCompletion(registerFileForCodeCompletionCommand); +} + +TEST_F(ClangIpcServer, GetProjectPartDoesNotExistUnregisterTranslationUnitWithInexistingProjectPart) +{ + Utf8String inexistingProjectPartFilePath = Utf8StringLiteral("projectpartsdoesnotexist.pro"); + UnregisterTranslationUnitsForCodeCompletionCommand unregisterFileForCodeCompletionCommand({FileContainer(variableTestFilePath, inexistingProjectPartFilePath)}); + ProjectPartsDoNotExistCommand projectPartsDoNotExistCommand({inexistingProjectPartFilePath}); + + EXPECT_CALL(mockIpcClient, projectPartsDoNotExist(projectPartsDoNotExistCommand)) + .Times(1); + + clangServer.unregisterTranslationUnitsForCodeCompletion(unregisterFileForCodeCompletionCommand); +} + +TEST_F(ClangIpcServer, GetProjectPartDoesNotExistForCompletingProjectPartFile) +{ + Utf8String inexistingProjectPartFilePath = Utf8StringLiteral("projectpartsdoesnotexist.pro"); + CompleteCodeCommand completeCodeCommand(variableTestFilePath, + 20, + 1, + inexistingProjectPartFilePath); + ProjectPartsDoNotExistCommand projectPartsDoNotExistCommand({inexistingProjectPartFilePath}); + + EXPECT_CALL(mockIpcClient, projectPartsDoNotExist(projectPartsDoNotExistCommand)) + .Times(1); + + clangServer.completeCode(completeCodeCommand); +} + +TEST_F(ClangIpcServer, GetProjectPartDoesNotExistForCompletingUnregisteredFile) +{ + CompleteCodeCommand completeCodeCommand(parseErrorTestFilePath, + 20, + 1, + projectPartId); + TranslationUnitDoesNotExistCommand translationUnitDoesNotExistCommand(parseErrorTestFilePath, projectPartId); + + EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(translationUnitDoesNotExistCommand)) + .Times(1); + + clangServer.completeCode(completeCodeCommand); +} + +TEST_F(ClangIpcServer, TicketNumberIsForwarded) +{ + CompleteCodeCommand completeCodeCommand(functionTestFilePath, + 20, + 1, + projectPartId); + CodeCompletion codeCompletion(Utf8StringLiteral("Function"), + Utf8String(), + Utf8String(), + 34, + CodeCompletion::FunctionCompletionKind); + + EXPECT_CALL(mockIpcClient, codeCompleted(Property(&CodeCompletedCommand::ticketNumber, Eq(completeCodeCommand.ticketNumber())))) + .Times(1); + + clangServer.completeCode(completeCodeCommand); +} +} diff --git a/tests/unit/unittest/clangstringtest.cpp b/tests/unit/unittest/clangstringtest.cpp new file mode 100644 index 0000000000..a7b5f86767 --- /dev/null +++ b/tests/unit/unittest/clangstringtest.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gmock/gmock.h" +#include "gtest-qt-printing.h" + +#include +#include + +#include +#include + +namespace { + +using ClangBackEnd::ClangString; + +TEST(ClangString, ConvertToUtf8String) +{ + const CXString cxString = { "text", 0}; + + ASSERT_THAT(Utf8String(ClangString(cxString)), Utf8StringLiteral("text")); +} + +TEST(ClangString, ConvertNullStringToUtf8String) +{ + const CXString cxString = { 0, 0}; + + ASSERT_THAT(Utf8String(ClangString(cxString)), Utf8String()); +} + +TEST(ClangString, MoveClangString) +{ + ClangString text(CXString{ "text", 0}); + + const ClangString text2 = std::move(text); + + ASSERT_TRUE(text.isNull()); + ASSERT_FALSE(text2.isNull()); +} + +} diff --git a/tests/unit/unittest/clientserverinprocesstest.cpp b/tests/unit/unittest/clientserverinprocesstest.cpp new file mode 100644 index 0000000000..3d29e596f0 --- /dev/null +++ b/tests/unit/unittest/clientserverinprocesstest.cpp @@ -0,0 +1,234 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gmock/gmock.h" + +#include "gtest-qt-printing.h" +#include "translationunitdoesnotexistcommand.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mockipclient.h" +#include "mockipcserver.h" + +using namespace ClangBackEnd; + +namespace { + +using ::testing::Args; +using ::testing::Property; +using ::testing::Eq; + +class ClientServerInProcess : public ::testing::Test +{ +protected: + ClientServerInProcess(); + + void SetUp(); + void TearDown(); + + + void scheduleServerCommands(); + void scheduleClientCommands(); + + QBuffer buffer; + MockIpcClient mockIpcClient; + MockIpcServer mockIpcServer; + + ClangBackEnd::IpcServerProxy serverProxy; + ClangBackEnd::IpcClientProxy clientProxy; +}; + +TEST_F(ClientServerInProcess, SendEndCommand) +{ + EXPECT_CALL(mockIpcServer, end()) + .Times(1); + + serverProxy.end(); + scheduleServerCommands(); +} + +TEST_F(ClientServerInProcess, SendAliveCommand) +{ + EXPECT_CALL(mockIpcClient, alive()) + .Times(1); + + clientProxy.alive(); + scheduleClientCommands(); +} + +TEST_F(ClientServerInProcess, SendRegisterTranslationUnitForCodeCompletionCommand) +{ + ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"), + Utf8StringLiteral("pathToProjectPart.pro")); + ClangBackEnd::RegisterTranslationUnitForCodeCompletionCommand command({fileContainer}); + + EXPECT_CALL(mockIpcServer, registerTranslationUnitsForCodeCompletion(command)) + .Times(1); + + serverProxy.registerTranslationUnitsForCodeCompletion(command); + scheduleServerCommands(); +} + +TEST_F(ClientServerInProcess, SendUnregisterTranslationUnitsForCodeCompletionCommand) +{ + ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("pathToProjectPart.pro")); + ClangBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand command({fileContainer}); + + EXPECT_CALL(mockIpcServer, unregisterTranslationUnitsForCodeCompletion(command)) + .Times(1); + + serverProxy.unregisterTranslationUnitsForCodeCompletion(command); + scheduleServerCommands(); +} + +TEST_F(ClientServerInProcess, SendCompleteCodeCommand) +{ + ClangBackEnd::CompleteCodeCommand command(Utf8StringLiteral("foo.cpp"), 24, 33, Utf8StringLiteral("do what I want")); + + EXPECT_CALL(mockIpcServer, completeCode(command)) + .Times(1); + + serverProxy.completeCode(command); + scheduleServerCommands(); +} + +TEST_F(ClientServerInProcess, SendCodeCompletedCommand) +{ + QVector codeCompletions({Utf8StringLiteral("newFunction()")}); + ClangBackEnd::CodeCompletedCommand command(codeCompletions, 1); + + EXPECT_CALL(mockIpcClient, codeCompleted(command)) + .Times(1); + + clientProxy.codeCompleted(command); + scheduleClientCommands(); +} + +TEST_F(ClientServerInProcess, SendRegisterProjectPartsForCodeCompletionCommand) +{ + ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral(TESTDATA_DIR"/complete.pro")); + ClangBackEnd::RegisterProjectPartsForCodeCompletionCommand command({projectContainer}); + + EXPECT_CALL(mockIpcServer, registerProjectPartsForCodeCompletion(command)) + .Times(1); + + serverProxy.registerProjectPartsForCodeCompletion(command); + scheduleServerCommands(); +} + +TEST_F(ClientServerInProcess, SendUnregisterProjectPartsForCodeCompletionCommand) +{ + ClangBackEnd::UnregisterProjectPartsForCodeCompletionCommand command({Utf8StringLiteral(TESTDATA_DIR"/complete.pro")}); + + EXPECT_CALL(mockIpcServer, unregisterProjectPartsForCodeCompletion(command)) + .Times(1); + + serverProxy.unregisterProjectPartsForCodeCompletion(command); + scheduleServerCommands(); +} + +TEST_F(ClientServerInProcess, SendTranslationUnitDoesNotExistCommand) +{ + ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"), + Utf8StringLiteral("pathToProjectPart.pro")); + ClangBackEnd::TranslationUnitDoesNotExistCommand command(fileContainer); + + EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(command)) + .Times(1); + + clientProxy.translationUnitDoesNotExist(command); + scheduleClientCommands(); +} + + +TEST_F(ClientServerInProcess, SendProjectPartDoesNotExistCommand) +{ + ClangBackEnd::ProjectPartsDoNotExistCommand command({Utf8StringLiteral("pathToProjectPart.pro")}); + + EXPECT_CALL(mockIpcClient, projectPartsDoNotExist(command)) + .Times(1); + + clientProxy.projectPartsDoNotExist(command); + scheduleClientCommands(); +} +ClientServerInProcess::ClientServerInProcess() + : serverProxy(&mockIpcClient, &buffer), + clientProxy(&mockIpcServer, &buffer) +{ +} + +void ClientServerInProcess::SetUp() +{ + buffer.open(QIODevice::ReadWrite); +} + +void ClientServerInProcess::TearDown() +{ + buffer.close(); +} + +void ClientServerInProcess::scheduleServerCommands() +{ + buffer.seek(0); + clientProxy.readCommands(); + buffer.buffer().clear(); +} + +void ClientServerInProcess::scheduleClientCommands() +{ + buffer.seek(0); + serverProxy.readCommands(); + buffer.buffer().clear(); +} + +} diff --git a/tests/unit/unittest/clientserveroutsideprocess.cpp b/tests/unit/unittest/clientserveroutsideprocess.cpp new file mode 100644 index 0000000000..22be5abce8 --- /dev/null +++ b/tests/unit/unittest/clientserveroutsideprocess.cpp @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gmock/gmock.h" + +#include +#include +#include +#include +#include + +#include + +#include "gtest-qt-printing.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#ifdef Q_OS_WIN +#define QTC_HOST_EXE_SUFFIX L".exe" +#else +#define QTC_HOST_EXE_SUFFIX "" +#endif + +using namespace ClangBackEnd; + +using ::testing::Eq; + +class ClientServerOutsideProcess : public ::testing::Test +{ +protected: + void SetUp(); + void TearDown(); + + static void SetUpTestCase(); + static void TearDownTestCase(); + + static MockIpcClient mockIpcClient; + static ClangBackEnd::ConnectionClient client; +}; + +MockIpcClient ClientServerOutsideProcess::mockIpcClient; +ClangBackEnd::ConnectionClient ClientServerOutsideProcess::client(&ClientServerOutsideProcess::mockIpcClient); + +TEST_F(ClientServerOutsideProcess, RestartProcess) +{ + client.restartProcess(); + + ASSERT_TRUE(client.isProcessIsRunning()); + ASSERT_TRUE(client.isConnected()); +} + +TEST_F(ClientServerOutsideProcess, RestartProcessAfterAliveTimeout) +{ + QSignalSpy clientSpy(&client, SIGNAL(processRestarted())); + + client.setProcessAliveTimerInterval(1); + + ASSERT_TRUE(clientSpy.wait(100000)); +} + +TEST_F(ClientServerOutsideProcess, RestartProcessAfterTermination) +{ + QSignalSpy clientSpy(&client, SIGNAL(processRestarted())); + + client.processForTestOnly()->kill(); + + ASSERT_TRUE(clientSpy.wait(100000)); +} + +TEST_F(ClientServerOutsideProcess, SendRegisterTranslationUnitForCodeCompletionCommand) +{ + ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo"), Utf8StringLiteral("pathToProjectPart.pro")); + ClangBackEnd::RegisterTranslationUnitForCodeCompletionCommand registerTranslationUnitForCodeCompletionCommand({fileContainer}); + EchoCommand echoCommand(QVariant::fromValue(registerTranslationUnitForCodeCompletionCommand)); + + EXPECT_CALL(mockIpcClient, echo(echoCommand)) + .Times(1); + + client.serverProxy().registerTranslationUnitsForCodeCompletion(registerTranslationUnitForCodeCompletionCommand); + ASSERT_TRUE(client.waitForEcho()); +} + +TEST_F(ClientServerOutsideProcess, SendUnregisterTranslationUnitsForCodeCompletionCommand) +{ + FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("bar.pro")); + ClangBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand unregisterTranslationUnitsForCodeCompletionCommand ({fileContainer}); + EchoCommand echoCommand(QVariant::fromValue(unregisterTranslationUnitsForCodeCompletionCommand)); + + EXPECT_CALL(mockIpcClient, echo(echoCommand)) + .Times(1); + + client.serverProxy().unregisterTranslationUnitsForCodeCompletion(unregisterTranslationUnitsForCodeCompletionCommand); + ASSERT_TRUE(client.waitForEcho()); +} + +TEST_F(ClientServerOutsideProcess, SendCompleteCodeCommand) +{ + CompleteCodeCommand codeCompleteCommand(Utf8StringLiteral("foo.cpp"), 24, 33, Utf8StringLiteral("do what I want")); + EchoCommand echoCommand(QVariant::fromValue(codeCompleteCommand)); + + EXPECT_CALL(mockIpcClient, echo(echoCommand)) + .Times(1); + + client.serverProxy().completeCode(codeCompleteCommand); + ASSERT_TRUE(client.waitForEcho()); +} + +TEST_F(ClientServerOutsideProcess, SendRegisterProjectPartsForCodeCompletionCommand) +{ + ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral(TESTDATA_DIR"/complete.pro")); + ClangBackEnd::RegisterProjectPartsForCodeCompletionCommand registerProjectPartsForCodeCompletionCommand({projectContainer}); + EchoCommand echoCommand(QVariant::fromValue(registerProjectPartsForCodeCompletionCommand)); + + EXPECT_CALL(mockIpcClient, echo(echoCommand)) + .Times(1); + + client.serverProxy().registerProjectPartsForCodeCompletion(registerProjectPartsForCodeCompletionCommand); + ASSERT_TRUE(client.waitForEcho()); +} + +TEST_F(ClientServerOutsideProcess, SendUnregisterProjectPartsForCodeCompletionCommand) +{ + ClangBackEnd::UnregisterProjectPartsForCodeCompletionCommand unregisterProjectPartsForCodeCompletionCommand({Utf8StringLiteral(TESTDATA_DIR"/complete.pro")}); + EchoCommand echoCommand(QVariant::fromValue(unregisterProjectPartsForCodeCompletionCommand)); + + EXPECT_CALL(mockIpcClient, echo(echoCommand)) + .Times(1); + + client.serverProxy().unregisterProjectPartsForCodeCompletion(unregisterProjectPartsForCodeCompletionCommand); + ASSERT_TRUE(client.waitForEcho()); +} + +void ClientServerOutsideProcess::SetUpTestCase() +{ + client.setProcessPath(QStringLiteral(ECHOSERVER QTC_HOST_EXE_SUFFIX)); + + ASSERT_TRUE(client.connectToServer()); +} + +void ClientServerOutsideProcess::TearDownTestCase() +{ + client.finishProcess(); +} +void ClientServerOutsideProcess::SetUp() +{ + client.setProcessAliveTimerInterval(1000000); + + ASSERT_TRUE(client.isConnected()); +} + +void ClientServerOutsideProcess::TearDown() +{ + ASSERT_TRUE(client.isProcessIsRunning()); + ASSERT_TRUE(client.isConnected()); +} diff --git a/tests/unit/unittest/codecompletionsextractortest.cpp b/tests/unit/unittest/codecompletionsextractortest.cpp new file mode 100644 index 0000000000..e9a4f26856 --- /dev/null +++ b/tests/unit/unittest/codecompletionsextractortest.cpp @@ -0,0 +1,663 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" + +#include "gmock/gmock-matchers.h" +#include "gmock/gmock-generated-matchers.h" +#include "gtest-qt-printing.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using ClangBackEnd::CodeCompletionsExtractor; +using ClangBackEnd::ClangCodeCompleteResults; +using ClangBackEnd::TranslationUnit; +using ClangBackEnd::CodeCompletion; +using ClangBackEnd::UnsavedFiles; +using ClangBackEnd::CodeCompletionChunk; + + + +namespace { + +using ::testing::PrintToString; +using ::testing::Not; + +MATCHER_P3(HasCompletion, name, kind, availability, + std::string(negation ? "hasn't" : "has") + " completion of name " + PrintToString(name) + + ", kind " + PrintToString(kind)) +{ + ::CodeCompletionsExtractor &extractor = const_cast<::CodeCompletionsExtractor&>(arg); + while (extractor.next()) { + if (extractor.currentCodeCompletion().text() == name) { + if (extractor.currentCodeCompletion().completionKind() == kind) { + if (extractor.currentCodeCompletion().availability() == availability) { + return true; + } else if (!extractor.peek(name)) { + *result_listener << "availability is " << PrintToString(extractor.currentCodeCompletion().availability()) << " and not " << PrintToString(availability); + return false; + } + } else if (!extractor.peek(name)) { + *result_listener << "kind is " << PrintToString(extractor.currentCodeCompletion().completionKind()) << " and not " << PrintToString(kind); + return false; + } + } + } + + return false; +} + +MATCHER_P2(HasCompletionChunks, name, chunks, + std::string(negation ? "hasn't" : "has") + " completion of name " + PrintToString(name) + + " with the chunks " + PrintToString(chunks)) +{ + ::CodeCompletionsExtractor &extractor = const_cast<::CodeCompletionsExtractor&>(arg); + while (extractor.next()) { + if (extractor.currentCodeCompletion().text() == name) { + if (extractor.currentCodeCompletion().chunks() == chunks) { + return true; + } else if (!extractor.peek(name)) { + *result_listener << "chunks are " << PrintToString(arg.currentCodeCompletion().chunks()) << " and not " << PrintToString(chunks); + return false; + } + } + } + + return false; +} + +const Utf8String unsavedFileContent(const char *unsavedFilePath) +{ + QFile unsavedFileContentFile(QString::fromUtf8(unsavedFilePath)); + bool isOpen = unsavedFileContentFile.open(QIODevice::ReadOnly | QIODevice::Text); + if (!isOpen) + ADD_FAILURE() << "File with the unsaved content cannot be opened!"; + + return Utf8String::fromByteArray(unsavedFileContentFile.readAll()); +} + +const ClangBackEnd::FileContainer unsavedDataFileContainer(const char *filePath, + const char *unsavedFilePath) +{ + return ClangBackEnd::FileContainer(Utf8String::fromUtf8(filePath), + Utf8String(), + unsavedFileContent(unsavedFilePath), + true); +} + +ClangCodeCompleteResults getResults(const TranslationUnit &translationUnit, uint line, uint column = 1) +{ + return ClangCodeCompleteResults(clang_codeCompleteAt(translationUnit.cxTranslationUnit(), + translationUnit.filePath().constData(), + line, + column, + translationUnit.cxUnsavedFiles(), + translationUnit.unsavedFilesCount(), + CXCodeComplete_IncludeMacros | CXCodeComplete_IncludeCodePatterns)); +} + +class CodeCompletionsExtractor : public ::testing::Test +{ +public: + static void TearDownTestCase(); + +protected: + static ClangBackEnd::ProjectPart project; + static ClangBackEnd::UnsavedFiles unsavedFiles; + static TranslationUnit functionTranslationUnit; + static TranslationUnit variableTranslationUnit; + static TranslationUnit classTranslationUnit ; + static TranslationUnit namespaceTranslationUnit; + static TranslationUnit enumerationTranslationUnit; + static TranslationUnit constructorTranslationUnit; +}; + +ClangBackEnd::ProjectPart CodeCompletionsExtractor::project(Utf8StringLiteral("/path/to/projectfile")); +ClangBackEnd::UnsavedFiles CodeCompletionsExtractor::unsavedFiles; +TranslationUnit CodeCompletionsExtractor::functionTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"), unsavedFiles, project); +TranslationUnit CodeCompletionsExtractor::variableTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp"), unsavedFiles, project); +TranslationUnit CodeCompletionsExtractor::classTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_class.cpp"), unsavedFiles, project); +TranslationUnit CodeCompletionsExtractor::namespaceTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_namespace.cpp"), unsavedFiles, project); +TranslationUnit CodeCompletionsExtractor::enumerationTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_enumeration.cpp"), unsavedFiles, project); +TranslationUnit CodeCompletionsExtractor::constructorTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_constructor.cpp"), unsavedFiles, project); + +void CodeCompletionsExtractor::TearDownTestCase() +{ + functionTranslationUnit.reset(); + variableTranslationUnit.reset(); + classTranslationUnit.reset(); + namespaceTranslationUnit.reset(); + enumerationTranslationUnit.reset(); + constructorTranslationUnit.reset(); +} + +TEST_F(CodeCompletionsExtractor, Function) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Function"), + CodeCompletion::FunctionCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, TemplateFunction) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("TemplateFunction"), + CodeCompletion::TemplateFunctionCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Variable) +{ + ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 4)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Var"), + CodeCompletion::VariableCompletionKind, + CodeCompletion::Available)); +} + + +TEST_F(CodeCompletionsExtractor, NonTypeTemplateParameter) +{ + ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 25, 19)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("NonTypeTemplateParameter"), + CodeCompletion::VariableCompletionKind, + CodeCompletion::Available)); +} + + +TEST_F(CodeCompletionsExtractor, VariableReference) +{ + ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 12)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Var"), + CodeCompletion::VariableCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Parameter) +{ + ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 4)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Parameter"), + CodeCompletion::VariableCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Field) +{ + ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Field"), + CodeCompletion::VariableCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Class) +{ + ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Class"), + CodeCompletion::ClassCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Struct) +{ + ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Struct"), + CodeCompletion::ClassCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Union) +{ + ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Union"), + CodeCompletion::ClassCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, TemplateTypeParameter) +{ + ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("TemplateTypeParameter"), + CodeCompletion::ClassCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, TemplateClass) +{ + ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("TemplateClass"), + CodeCompletion::TemplateClassCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, TemplateTemplateParameter) +{ + ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("TemplateTemplateParameter"), + CodeCompletion::TemplateClassCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, ClassTemplatePartialSpecialization) +{ + ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("ClassTemplatePartialSpecialization"), + CodeCompletion::TemplateClassCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Namespace) +{ + ClangCodeCompleteResults completeResults(getResults(namespaceTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Namespace"), + CodeCompletion::NamespaceCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, NamespaceAlias) +{ + ClangCodeCompleteResults completeResults(getResults(namespaceTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("NamespaceAlias"), + CodeCompletion::NamespaceCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Enumeration) +{ + ClangCodeCompleteResults completeResults(getResults(enumerationTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Enumeration"), + CodeCompletion::EnumerationCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Enumerator) +{ + ClangCodeCompleteResults completeResults(getResults(enumerationTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Enumerator"), + CodeCompletion::EnumeratorCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Constructor) +{ + ClangCodeCompleteResults completeResults(getResults(constructorTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Constructor"), + CodeCompletion::ConstructorCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Destructor) +{ + ClangCodeCompleteResults completeResults(getResults(constructorTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("~Constructor"), + CodeCompletion::DestructorCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Method) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Method"), + CodeCompletion::FunctionCompletionKind, + CodeCompletion::Available)); + ASSERT_FALSE(extractor.currentCodeCompletion().hasParameters()); +} + +TEST_F(CodeCompletionsExtractor, MethodWithParameters) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("MethodWithParameters"), + CodeCompletion::FunctionCompletionKind, + CodeCompletion::Available)); + ASSERT_TRUE(extractor.currentCodeCompletion().hasParameters()); +} + +TEST_F(CodeCompletionsExtractor, Slot) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Slot"), + CodeCompletion::SlotCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, Signal) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Signal"), + CodeCompletion::SignalCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, MacroDefinition) +{ + ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("MacroDefinition"), + CodeCompletion::PreProcessorCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, FunctionMacro) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("FunctionMacro"), + CodeCompletion::FunctionCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, IntKeyword) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("int"), + CodeCompletion::KeywordCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, SwitchKeyword) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("switch"), + CodeCompletion::KeywordCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, ClassKeyword) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("class"), + CodeCompletion::KeywordCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, DeprecatedFunction) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("DeprecatedFunction"), + CodeCompletion::FunctionCompletionKind, + CodeCompletion::Deprecated)); +} + +TEST_F(CodeCompletionsExtractor, NotAccessibleFunction) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("NotAccessibleFunction"), + CodeCompletion::FunctionCompletionKind, + CodeCompletion::NotAccessible)); +} + +TEST_F(CodeCompletionsExtractor, NotAvailableFunction) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("NotAvailableFunction"), + CodeCompletion::FunctionCompletionKind, + CodeCompletion::NotAvailable)); +} + +TEST_F(CodeCompletionsExtractor, UnsavedFile) +{ + ClangBackEnd::UnsavedFiles unsavedFiles; + ClangBackEnd::ProjectPart project(Utf8StringLiteral("/path/to/projectfile")); + TranslationUnit translationUnit(Utf8String::fromUtf8(TESTDATA_DIR"/complete_extractor_function.cpp"), unsavedFiles, project); + unsavedFiles.createOrUpdate({unsavedDataFileContainer(TESTDATA_DIR"/complete_extractor_function.cpp", + TESTDATA_DIR"/complete_extractor_function_unsaved.cpp")}); + ClangCodeCompleteResults completeResults(getResults(translationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Method2"), + CodeCompletion::FunctionCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, ChangeUnsavedFile) +{ + ClangBackEnd::UnsavedFiles unsavedFiles; + ClangBackEnd::ProjectPart project(Utf8StringLiteral("/path/to/projectfile")); + TranslationUnit translationUnit(Utf8String::fromUtf8(TESTDATA_DIR"/complete_extractor_function.cpp"), unsavedFiles, project); + unsavedFiles.createOrUpdate({unsavedDataFileContainer(TESTDATA_DIR"/complete_extractor_function.cpp", + TESTDATA_DIR"/complete_extractor_function_unsaved.cpp")}); + ClangCodeCompleteResults completeResults(getResults(translationUnit, 20)); + unsavedFiles.createOrUpdate({unsavedDataFileContainer(TESTDATA_DIR"/complete_extractor_function.cpp", + TESTDATA_DIR"/complete_extractor_function_unsaved_2.cpp")}); + completeResults = getResults(translationUnit, 20); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Method3"), + CodeCompletion::FunctionCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, ArgumentDefinition) +{ + variableTranslationUnit.cxTranslationUnit(); + project.setArguments({Utf8StringLiteral("-DArgumentDefinition")}); + ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("ArgumentDefinitionVariable"), + CodeCompletion::VariableCompletionKind, + CodeCompletion::Available)); +} + +TEST_F(CodeCompletionsExtractor, NoArgumentDefinition) +{ + variableTranslationUnit.cxTranslationUnit(); + project.setArguments(Utf8StringVector()); + ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, Not(HasCompletion(Utf8StringLiteral("ArgumentDefinitionVariable"), + CodeCompletion::VariableCompletionKind, + CodeCompletion::Available))); +} + +TEST_F(CodeCompletionsExtractor, CompletionChunksFunction) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Function"), + QVector({{CodeCompletionChunk::ResultType, Utf8StringLiteral("void")}, + {CodeCompletionChunk::TypedText, Utf8StringLiteral("Function")}, + {CodeCompletionChunk::LeftParen, Utf8StringLiteral("(")}, + {CodeCompletionChunk::RightParen, Utf8StringLiteral(")")}}))); +} + +TEST_F(CodeCompletionsExtractor, CompletionChunksFunctionWithOptionalChunks) +{ + ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("FunctionWithOptional"), + QVector({{CodeCompletionChunk::ResultType, Utf8StringLiteral("void")}, + {CodeCompletionChunk::TypedText, Utf8StringLiteral("FunctionWithOptional")}, + {CodeCompletionChunk::LeftParen, Utf8StringLiteral("(")}, + {CodeCompletionChunk::Placeholder, Utf8StringLiteral("int x")}, + {CodeCompletionChunk::Optional, Utf8String(), QVector({ + {CodeCompletionChunk::Comma, Utf8StringLiteral(", ")}, + {CodeCompletionChunk::Placeholder, Utf8StringLiteral("char y")}, + {CodeCompletionChunk::Comma, Utf8StringLiteral(", ")}, + {CodeCompletionChunk::Placeholder, Utf8StringLiteral("int z")}})}, + {CodeCompletionChunk::RightParen, Utf8StringLiteral(")")}}))); +} + +TEST_F(CodeCompletionsExtractor, CompletionChunksField) +{ + ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Field"), + QVector({{CodeCompletionChunk::ResultType, Utf8StringLiteral("int")}, + {CodeCompletionChunk::TypedText, Utf8StringLiteral("Field")}}))); +} + +TEST_F(CodeCompletionsExtractor, CompletionChunksEnumerator) +{ + ClangCodeCompleteResults completeResults(getResults(enumerationTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Enumerator"), + QVector({{CodeCompletionChunk::ResultType, Utf8StringLiteral("Enumeration")}, + {CodeCompletionChunk::TypedText, Utf8StringLiteral("Enumerator")}}))); +} + +TEST_F(CodeCompletionsExtractor, CompletionChunksEnumeration) +{ + ClangCodeCompleteResults completeResults(getResults(enumerationTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Enumeration"), + QVector({{CodeCompletionChunk::TypedText, Utf8StringLiteral("Enumeration")}}))); +} + +TEST_F(CodeCompletionsExtractor, CompletionChunksClass) +{ + ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20)); + + ::CodeCompletionsExtractor extractor(completeResults.data()); + + ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Class"), + QVector({{CodeCompletionChunk::TypedText, Utf8StringLiteral("Class")}}))); +} + + +} diff --git a/tests/unit/unittest/codecompletiontest.cpp b/tests/unit/unittest/codecompletiontest.cpp new file mode 100644 index 0000000000..efb4551a0a --- /dev/null +++ b/tests/unit/unittest/codecompletiontest.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gtest-qt-printing.h" + +#include +#include +#include +#include +#include +#include + +#include + + +using ::testing::ElementsAreArray; +using ::testing::Contains; +using ::testing::AllOf; +using ::testing::Not; + +using ClangBackEnd::CodeCompletion; +using ClangBackEnd::CodeCompleter; + +namespace { + +class CodeCompleter : public ::testing::Test +{ +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + +protected: + static ClangBackEnd::ProjectPart projectPart; + static ClangBackEnd::UnsavedFiles unsavedFiles; + static ClangBackEnd::TranslationUnit translationUnit; + static ClangBackEnd::CodeCompleter completer; +}; + +ClangBackEnd::ProjectPart CodeCompleter::projectPart(Utf8StringLiteral("projectPartId")); +ClangBackEnd::UnsavedFiles CodeCompleter::unsavedFiles; +ClangBackEnd::TranslationUnit CodeCompleter::translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_completer.cpp"), unsavedFiles, projectPart); +ClangBackEnd::CodeCompleter CodeCompleter::completer = translationUnit; + +void CodeCompleter::SetUpTestCase() +{ + QFile unsavedFileContentFile(QStringLiteral(TESTDATA_DIR) + QStringLiteral("/complete_completer_unsaved.cpp")); + unsavedFileContentFile.open(QIODevice::ReadOnly); + + const Utf8String unsavedFileContent = Utf8String::fromByteArray(unsavedFileContentFile.readAll()); + const ClangBackEnd::FileContainer unsavedDataFileContainer(translationUnit.filePath(), + projectPart.projectPartId(), + unsavedFileContent, + true); + + unsavedFiles.createOrUpdate({unsavedDataFileContainer}); +} + +void CodeCompleter::TearDownTestCase() +{ + translationUnit.reset(); + completer = ClangBackEnd::CodeCompleter(); +} + + +TEST_F(CodeCompleter, FunctionInUnsavedFile) +{ + ASSERT_THAT(completer.complete(100, 1), + AllOf(Contains(CodeCompletion(Utf8StringLiteral("functionWithArguments"), + Utf8String(), + Utf8String(), + 0, + CodeCompletion::FunctionCompletionKind)), + Contains(CodeCompletion(Utf8StringLiteral("function"), + Utf8String(), + Utf8String(), + 0, + CodeCompletion::FunctionCompletionKind)), + Contains(CodeCompletion(Utf8StringLiteral("newFunction"), + Utf8String(), + Utf8String(), + 0, + CodeCompletion::FunctionCompletionKind)), + Contains(CodeCompletion(Utf8StringLiteral("f"), + Utf8String(), + Utf8String(), + 0, + CodeCompletion::FunctionCompletionKind)), + Not(Contains(CodeCompletion(Utf8StringLiteral("otherFunction"), + Utf8String(), + Utf8String(), + 0, + CodeCompletion::FunctionCompletionKind))))); +} + + +TEST_F(CodeCompleter, Macro) +{ + ASSERT_THAT(completer.complete(100, 1), + Contains(CodeCompletion(Utf8StringLiteral("Macro"), + Utf8String(), + Utf8String(), + 0, + CodeCompletion::PreProcessorCompletionKind))); +} + +TEST_F(CodeCompleter, Keyword) +{ + ASSERT_THAT(completer.complete(100, 1), + Contains(CodeCompletion(Utf8StringLiteral("switch"), + Utf8String(), + Utf8String(), + 0, + CodeCompletion::KeywordCompletionKind))); +} + + +} + + diff --git a/tests/unit/unittest/completionchunkstotextconvertertest.cpp b/tests/unit/unittest/completionchunkstotextconvertertest.cpp new file mode 100644 index 0000000000..c5c7f596e9 --- /dev/null +++ b/tests/unit/unittest/completionchunkstotextconvertertest.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gmock/gmock-generated-matchers.h" +#include "gtest-qt-printing.h" + +#include +#include + +namespace { + +using ClangBackEnd::CodeCompletionChunk; + +class CompletionChunksToTextConverter : public ::testing::Test +{ +protected: + ClangCodeModel::Internal::CompletionChunksToTextConverter converter; + CodeCompletionChunk integerResultType{CodeCompletionChunk::ResultType, Utf8StringLiteral("int")}; + CodeCompletionChunk enumerationResultType{CodeCompletionChunk::ResultType, Utf8StringLiteral("Enumeration")}; + CodeCompletionChunk functionName{CodeCompletionChunk::TypedText, Utf8StringLiteral("Function")}; + CodeCompletionChunk variableName{CodeCompletionChunk::TypedText, Utf8StringLiteral("Variable")}; + CodeCompletionChunk enumeratorName{CodeCompletionChunk::TypedText, Utf8StringLiteral("Enumerator")}; + CodeCompletionChunk enumerationName{CodeCompletionChunk::TypedText, Utf8StringLiteral("Enumeration")}; + CodeCompletionChunk className{CodeCompletionChunk::TypedText, Utf8StringLiteral("Class")}; + CodeCompletionChunk leftParen{CodeCompletionChunk::LeftParen, Utf8StringLiteral("(")}; + CodeCompletionChunk rightParen{CodeCompletionChunk::LeftParen, Utf8StringLiteral(")")}; + CodeCompletionChunk comma{CodeCompletionChunk::Comma, Utf8StringLiteral(", ")}; + CodeCompletionChunk functionArgumentX{CodeCompletionChunk::Placeholder, Utf8StringLiteral("char x")}; + CodeCompletionChunk functionArgumentY{CodeCompletionChunk::Placeholder, Utf8StringLiteral("int y")}; + CodeCompletionChunk functionArgumentZ{CodeCompletionChunk::Placeholder, Utf8StringLiteral("int z")}; + CodeCompletionChunk optional{CodeCompletionChunk::Optional, Utf8String(), {comma, functionArgumentY, comma, functionArgumentZ}}; +}; + +TEST_F(CompletionChunksToTextConverter, ParseIsClearingText) +{ + QVector completionChunks({integerResultType, functionName, leftParen, rightParen}); + converter.parseChunks(completionChunks); + + converter.parseChunks(completionChunks); + + ASSERT_THAT(converter.text(), QStringLiteral("int Function()")); +} + +TEST_F(CompletionChunksToTextConverter, ConvertFunction) +{ + QVector completionChunks({integerResultType, functionName, leftParen, rightParen}); + + converter.parseChunks(completionChunks); + + ASSERT_THAT(converter.text(), QStringLiteral("int Function()")); +} + +TEST_F(CompletionChunksToTextConverter, ConvertFunctionWithParameters) +{ + QVector completionChunks({integerResultType, functionName, leftParen, functionArgumentX,rightParen}); + + converter.parseChunks(completionChunks); + + ASSERT_THAT(converter.text(), QStringLiteral("int Function(char x)")); +} + +TEST_F(CompletionChunksToTextConverter, ConvertFunctionWithOptionalParameter) +{ + QVector completionChunks({integerResultType, functionName, leftParen, functionArgumentX, optional,rightParen}); + + converter.parseChunks(completionChunks); + + ASSERT_THAT(converter.text(), QStringLiteral("int Function(char x, int y, int z)")); +} + +TEST_F(CompletionChunksToTextConverter, ConvertVariable) +{ + QVector completionChunks({integerResultType, variableName}); + + converter.parseChunks(completionChunks); + + ASSERT_THAT(converter.text(), QStringLiteral("int Variable")); +} + +TEST_F(CompletionChunksToTextConverter, Enumerator) +{ + QVector completionChunks({enumerationResultType, enumeratorName}); + + converter.parseChunks(completionChunks); + + ASSERT_THAT(converter.text(), QStringLiteral("Enumeration Enumerator")); +} + +TEST_F(CompletionChunksToTextConverter, Enumeration) +{ + QVector completionChunks({className}); + + converter.parseChunks(completionChunks); + + ASSERT_THAT(converter.text(), QStringLiteral("Class")); +} + +} diff --git a/tests/unit/unittest/createtablesqlstatementbuildertest.cpp b/tests/unit/unittest/createtablesqlstatementbuildertest.cpp new file mode 100644 index 0000000000..87dbb84189 --- /dev/null +++ b/tests/unit/unittest/createtablesqlstatementbuildertest.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gtest-qt-printing.h" + +#include + +#include +#include + +#include + +class CreateTableSqlStatementBuilder : public ::testing::Test +{ +protected: + void SetUp() override; + + void bindValues(); + static const QVector createColumnDefintions(); + static const Internal::ColumnDefinition createColumnDefintion(const Utf8String &name, + ColumnType type, + bool isPrimaryKey = false); + + Internal::CreateTableSqlStatementBuilder builder; +}; + +TEST_F(CreateTableSqlStatementBuilder, IsNotValidAfterCreation) +{ + ASSERT_FALSE(builder.isValid()); +} + +TEST_F(CreateTableSqlStatementBuilder, IsValidAfterBinding) +{ + bindValues(); + + ASSERT_TRUE(builder.isValid()); +} + +TEST_F(CreateTableSqlStatementBuilder, InvalidAfterClear) +{ + bindValues(); + + builder.clear(); + + ASSERT_TRUE(!builder.isValid()); +} + +TEST_F(CreateTableSqlStatementBuilder, NoSqlStatementAfterClear) +{ + bindValues(); + builder.sqlStatement(); + + builder.clear(); + + ASSERT_THROW(builder.sqlStatement(), SqlStatementBuilderException); +} + +TEST_F(CreateTableSqlStatementBuilder, SqlStatement) +{ + bindValues(); + + ASSERT_THAT(builder.sqlStatement(), + Utf8StringLiteral("CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY, name TEXT, number NUMERIC)"));} + +TEST_F(CreateTableSqlStatementBuilder, AddColumnToExistingColumns) +{ + bindValues(); + + builder.addColumnDefinition(Utf8StringLiteral("number2"), ColumnType::Real); + + ASSERT_THAT(builder.sqlStatement(), + Utf8StringLiteral("CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY, name TEXT, number NUMERIC, number2 REAL)"));} + +TEST_F(CreateTableSqlStatementBuilder, ChangeTable) +{ + bindValues(); + + builder.setTable(Utf8StringLiteral("test2")); + + ASSERT_THAT(builder.sqlStatement(), + Utf8StringLiteral("CREATE TABLE IF NOT EXISTS test2(id INTEGER PRIMARY KEY, name TEXT, number NUMERIC)")); +} + +TEST_F(CreateTableSqlStatementBuilder, IsInvalidAfterClearColumsOnly) +{ + bindValues(); + builder.sqlStatement(); + + builder.clearColumns(); + + ASSERT_THROW(builder.sqlStatement(), SqlStatementBuilderException); +} + +TEST_F(CreateTableSqlStatementBuilder, ClearColumnsAndAddColumnNewColumns) +{ + bindValues(); + builder.clearColumns(); + + builder.addColumnDefinition(Utf8StringLiteral("name3"), ColumnType::Text); + builder.addColumnDefinition(Utf8StringLiteral("number3"), ColumnType::Real); + + ASSERT_THAT(builder.sqlStatement(), + Utf8StringLiteral("CREATE TABLE IF NOT EXISTS test(name3 TEXT, number3 REAL)")); +} + +TEST_F(CreateTableSqlStatementBuilder, SetWitoutRowId) +{ + bindValues(); + + builder.setUseWithoutRowId(true); + + ASSERT_THAT(builder.sqlStatement(), + Utf8StringLiteral("CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY, name TEXT, number NUMERIC) WITHOUT ROWID")); +} + +TEST_F(CreateTableSqlStatementBuilder, SetColumnDefinitions) +{ + builder.clear(); + builder.setTable(Utf8StringLiteral("test")); + + builder.setColumnDefinitions(createColumnDefintions()); + + ASSERT_THAT(builder.sqlStatement(), + Utf8StringLiteral("CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY, name TEXT, number NUMERIC)")); +} + +void CreateTableSqlStatementBuilder::SetUp() +{ + builder = Internal::CreateTableSqlStatementBuilder(); +} + +void CreateTableSqlStatementBuilder::bindValues() +{ + builder.clear(); + builder.setTable(Utf8StringLiteral("test")); + builder.addColumnDefinition(Utf8StringLiteral("id"), ColumnType::Integer, true); + builder.addColumnDefinition(Utf8StringLiteral("name"), ColumnType::Text); + builder.addColumnDefinition(Utf8StringLiteral("number"),ColumnType:: Numeric); +} + +const QVector CreateTableSqlStatementBuilder::createColumnDefintions() +{ + QVector columnDefinitions; + columnDefinitions.append(createColumnDefintion(Utf8StringLiteral("id"), ColumnType::Integer, true)); + columnDefinitions.append(createColumnDefintion(Utf8StringLiteral("name"), ColumnType::Text)); + columnDefinitions.append(createColumnDefintion(Utf8StringLiteral("number"), ColumnType::Numeric)); + + return columnDefinitions; +} + +const Internal::ColumnDefinition CreateTableSqlStatementBuilder::createColumnDefintion(const Utf8String &name, ColumnType type, bool isPrimaryKey) +{ + Internal::ColumnDefinition columnDefinition; + + columnDefinition.setName(name); + columnDefinition.setType(type); + columnDefinition.setIsPrimaryKey(isPrimaryKey); + + return columnDefinition; +} diff --git a/tests/unit/unittest/data/complete_completer.cpp b/tests/unit/unittest/data/complete_completer.cpp new file mode 100644 index 0000000000..a764b7adb4 --- /dev/null +++ b/tests/unit/unittest/data/complete_completer.cpp @@ -0,0 +1,101 @@ +void function() +{ + +} + +class Foo; +void functionWithArguments(int i, char *c, const Foo &ref) +{ + +} + +void otherFunction() +{ + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void f() +{ + +} diff --git a/tests/unit/unittest/data/complete_completer_unsaved.cpp b/tests/unit/unittest/data/complete_completer_unsaved.cpp new file mode 100644 index 0000000000..9ec3fed8f4 --- /dev/null +++ b/tests/unit/unittest/data/complete_completer_unsaved.cpp @@ -0,0 +1,100 @@ +void function() +{ + +} + +class Foo; +void functionWithArguments(int i, char *c, const Foo &ref) +{ + +} + +void newFunction() +{ + +} + +#define Macro + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void f() +{ + +} diff --git a/tests/unit/unittest/data/complete_extractor_class.cpp b/tests/unit/unittest/data/complete_extractor_class.cpp new file mode 100644 index 0000000000..becfdc3292 --- /dev/null +++ b/tests/unit/unittest/data/complete_extractor_class.cpp @@ -0,0 +1,21 @@ +class Class {}; +struct Struct{}; +union Union{}; +typedef Class TypeDef; +template class TemplateClass{}; +template class ClassTemplatePartialSpecialization; +template class ClassTemplatePartialSpecialization; + + + + + + + + + +template class TemplateTemplateParameter> +void function() +{ + +} diff --git a/tests/unit/unittest/data/complete_extractor_constructor.cpp b/tests/unit/unittest/data/complete_extractor_constructor.cpp new file mode 100644 index 0000000000..e28ccaea82 --- /dev/null +++ b/tests/unit/unittest/data/complete_extractor_constructor.cpp @@ -0,0 +1,22 @@ +class Constructor { + Constructor(); + ~Constructor(); + + + + + + + + + + + + + + + void function() + { + + } +}; diff --git a/tests/unit/unittest/data/complete_extractor_enumeration.cpp b/tests/unit/unittest/data/complete_extractor_enumeration.cpp new file mode 100644 index 0000000000..79973a616b --- /dev/null +++ b/tests/unit/unittest/data/complete_extractor_enumeration.cpp @@ -0,0 +1,22 @@ +enum Enumeration { + Enumerator +}; + + + + + + + + + + + + + + +void function() +{ + +} + diff --git a/tests/unit/unittest/data/complete_extractor_function.cpp b/tests/unit/unittest/data/complete_extractor_function.cpp new file mode 100644 index 0000000000..a4d34fb04a --- /dev/null +++ b/tests/unit/unittest/data/complete_extractor_function.cpp @@ -0,0 +1,22 @@ +void Function(); +template void TemplateFunction(); +void FunctionWithOptional(int x, char y = 1, int z = 5); +#define FunctionMacro(X, Y) X + Y + +class base { + void NotAccessibleFunction(); +}; +class Class : public base { + void Method(); + void MethodWithParameters(int x = 30); + __attribute__((annotate("qt_slot"))) void Slot(); + __attribute__((annotate("qt_signal"))) void Signal(); + __attribute__ ((deprecated)) void DeprecatedFunction(); + void NotAvailableFunction() = delete; + +public: + void function() + { + + } +}; diff --git a/tests/unit/unittest/data/complete_extractor_function_unsaved.cpp b/tests/unit/unittest/data/complete_extractor_function_unsaved.cpp new file mode 100644 index 0000000000..adab53527b --- /dev/null +++ b/tests/unit/unittest/data/complete_extractor_function_unsaved.cpp @@ -0,0 +1,22 @@ +void Function(); +template void TemplateFunction(); + +#define FunctionMacro(X, Y) X + Y + +class base { + void NotAccessibleFunction(); +}; +class Class : public base { + void Method2(); + void MethodWithParameters(int x = 30); + __attribute__((annotate("qt_slot"))) void Slot(); + __attribute__((annotate("qt_signal"))) void Signal(); + __attribute__ ((deprecated)) void DeprecatedFunction(); + void NotAvailableFunction() = delete; + +public: + void function() + { + + } +}; diff --git a/tests/unit/unittest/data/complete_extractor_function_unsaved_2.cpp b/tests/unit/unittest/data/complete_extractor_function_unsaved_2.cpp new file mode 100644 index 0000000000..08153184f4 --- /dev/null +++ b/tests/unit/unittest/data/complete_extractor_function_unsaved_2.cpp @@ -0,0 +1,22 @@ +void Function(); +template void TemplateFunction(); + +#define FunctionMacro(X, Y) X + Y + +class base { + void NotAccessibleFunction(); +}; +class Class : public base { + void Method3(); + void MethodWithParameters(int x = 30); + __attribute__((annotate("qt_slot"))) void Slot(); + __attribute__((annotate("qt_signal"))) void Signal(); + __attribute__ ((deprecated)) void DeprecatedFunction(); + void NotAvailableFunction() = delete; + +public: + void function() + { + + } +}; diff --git a/tests/unit/unittest/data/complete_extractor_namespace.cpp b/tests/unit/unittest/data/complete_extractor_namespace.cpp new file mode 100644 index 0000000000..46d273da9d --- /dev/null +++ b/tests/unit/unittest/data/complete_extractor_namespace.cpp @@ -0,0 +1,22 @@ +namespace Namespace {} +namespace NamespaceAlias = Namespace; + + + + + + + + + + + + + + + +void function() +{ + +} + diff --git a/tests/unit/unittest/data/complete_extractor_variable.cpp b/tests/unit/unittest/data/complete_extractor_variable.cpp new file mode 100644 index 0000000000..e8a67f9c6c --- /dev/null +++ b/tests/unit/unittest/data/complete_extractor_variable.cpp @@ -0,0 +1,36 @@ +void function(int Parameter) +{ + int Var = 0; + +} + +void function2() +{ + int Var = 0; + auto Lambda = [&Var]() + { + + }; +} + +class Class { + int Field; + + void function() { + + } +}; + +template +void function3() {} + +#define MacroDefinition + + +void function4() +{ +#ifdef ArgumentDefinition + int ArgumentDefinitionVariable; +#endif + +} diff --git a/tests/unit/unittest/data/complete_testfile_1.cpp b/tests/unit/unittest/data/complete_testfile_1.cpp new file mode 100644 index 0000000000..7804bc5fd6 --- /dev/null +++ b/tests/unit/unittest/data/complete_testfile_1.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +void function() +{ + +} + +class Foo; +void functionWithArguments(int i, char *c, const Foo &ref) +{ + +} + +void otherFunction() +{ + +} + +void f() +{ + +} diff --git a/tests/unit/unittest/data/complete_translationunit_parse_error.cpp b/tests/unit/unittest/data/complete_translationunit_parse_error.cpp new file mode 100644 index 0000000000..288cef2a33 --- /dev/null +++ b/tests/unit/unittest/data/complete_translationunit_parse_error.cpp @@ -0,0 +1,2 @@ +NAMESPACE { + diff --git a/tests/unit/unittest/gtest-qt-printing.cpp b/tests/unit/unittest/gtest-qt-printing.cpp new file mode 100644 index 0000000000..da82cd2595 --- /dev/null +++ b/tests/unit/unittest/gtest-qt-printing.cpp @@ -0,0 +1,31 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +//#include "gtest-qt-printing.h" diff --git a/tests/unit/unittest/gtest-qt-printing.h b/tests/unit/unittest/gtest-qt-printing.h new file mode 100644 index 0000000000..353efad9ea --- /dev/null +++ b/tests/unit/unittest/gtest-qt-printing.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include +#include + +#include + +#include + +#ifndef GTESTQTPRINTING_H +#define GTESTQTPRINTING_H + +QT_BEGIN_NAMESPACE +class QVariant; +inline void PrintTo(const QVariant &variant, ::std::ostream *os) +{ + QString output; + QDebug debug(&output); + + debug << variant; + + *os << output.toUtf8().constData(); +} + +inline void PrintTo(const QString &text, ::std::ostream *os) +{ + *os << text.toUtf8().constData(); +} + +QT_END_NAMESPACE + +//namespace testing { +//namespace internal { + +// void PrintTo(const QVariant &variant, ::std::ostream *os); + +//} +//} +#endif // GTESTQTPRINTING_H + diff --git a/tests/unit/unittest/main.cpp b/tests/unit/unittest/main.cpp new file mode 100644 index 0000000000..a1b332e7d7 --- /dev/null +++ b/tests/unit/unittest/main.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" + +#include +#include + +#include + +int main(int argc, char *argv[]) +{ + ClangBackEnd::Commands::registerCommands(); + Sqlite::registerTypes(); + + QCoreApplication application(argc, argv); + + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/unit/unittest/mockipclient.h b/tests/unit/unittest/mockipclient.h new file mode 100644 index 0000000000..9a09a06cc2 --- /dev/null +++ b/tests/unit/unittest/mockipclient.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MOCKIPCLIENT_H +#define MOCKIPCLIENT_H + +#include + + +class MockIpcClient : public ClangBackEnd::IpcClientInterface { + public: + MOCK_METHOD0(alive, + void()); + MOCK_METHOD1(echo, + void(const ClangBackEnd::EchoCommand &command)); + MOCK_METHOD1(codeCompleted, + void(const ClangBackEnd::CodeCompletedCommand &command)); + MOCK_METHOD1(translationUnitDoesNotExist, + void(const ClangBackEnd::TranslationUnitDoesNotExistCommand &command)); + MOCK_METHOD1(projectPartsDoNotExist, + void(const ClangBackEnd::ProjectPartsDoNotExistCommand &command)); +}; + +#endif // MOCKIPCLIENT_H + diff --git a/tests/unit/unittest/mockipcserver.h b/tests/unit/unittest/mockipcserver.h new file mode 100644 index 0000000000..276ee1aa8a --- /dev/null +++ b/tests/unit/unittest/mockipcserver.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MOCKIPCSERVER_H +#define MOCKIPCSERVER_H + +#include + +class MockIpcServer : public ClangBackEnd::IpcServerInterface { + public: + MOCK_METHOD0(end, + void()); + MOCK_METHOD1(registerTranslationUnitsForCodeCompletion, + void(const ClangBackEnd::RegisterTranslationUnitForCodeCompletionCommand &command)); + MOCK_METHOD1(unregisterTranslationUnitsForCodeCompletion, + void(const ClangBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand &command)); + MOCK_METHOD1(registerProjectPartsForCodeCompletion, + void(const ClangBackEnd::RegisterProjectPartsForCodeCompletionCommand &command)); + MOCK_METHOD1(unregisterProjectPartsForCodeCompletion, + void(const ClangBackEnd::UnregisterProjectPartsForCodeCompletionCommand &command)); + MOCK_METHOD1(completeCode, + void(const ClangBackEnd::CompleteCodeCommand &command)); +}; + +#endif // MOCKIPCSERVER_H + diff --git a/tests/unit/unittest/projecttest.cpp b/tests/unit/unittest/projecttest.cpp new file mode 100644 index 0000000000..daab4e8816 --- /dev/null +++ b/tests/unit/unittest/projecttest.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" + +#include "gmock/gmock-matchers.h" +#include "gmock/gmock-generated-matchers.h" +#include "gtest-qt-printing.h" + +#include +#include +#include +#include + +#include +#include + +using testing::ElementsAre; +using testing::StrEq; +using testing::Pointwise; +using testing::Contains; +using testing::Gt; +using testing::Not; + +namespace { + +TEST(ProjectPart, CreateProjectPart) +{ + Utf8String projectPath(Utf8StringLiteral("/tmp/blah.pro")); + + ClangBackEnd::ProjectPart project(projectPath); + + ASSERT_THAT(project.projectPartId(), projectPath); +} + +TEST(ProjectPart, CreateProjectPartWithProjectPartContainer) +{ + ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); + + ClangBackEnd::ProjectPart project(projectContainer); + + ASSERT_THAT(project.projectPartId(), Utf8StringLiteral("pathToProjectPart.pro")); + ASSERT_THAT(project.arguments(), Contains(StrEq("-O"))); +} + +TEST(ProjectPart, SetArguments) +{ + ClangBackEnd::ProjectPart project(Utf8StringLiteral("/tmp/blah.pro")); + + project.setArguments(Utf8StringVector({Utf8StringLiteral("-O"), Utf8StringLiteral("-fast")})); + + ASSERT_THAT(project.arguments(), ElementsAre(StrEq("-O"), StrEq("-fast"))); +} + +TEST(ProjectPart, ArgumentCount) +{ + ClangBackEnd::ProjectPart project(Utf8StringLiteral("/tmp/blah.pro")); + + project.setArguments(Utf8StringVector({Utf8StringLiteral("-O"), Utf8StringLiteral("-fast")})); + + ASSERT_THAT(project.argumentCount(), 2); +} + +TEST(ProjectPart, TimeStampIsUpdatedAsArgumentChanged) +{ + ClangBackEnd::ProjectPart project(Utf8StringLiteral("/tmp/blah.pro")); + auto lastChangeTimePoint = project.lastChangeTimePoint(); + std::this_thread::sleep_for(std::chrono::steady_clock::duration(1)); + + project.setArguments(Utf8StringVector({Utf8StringLiteral("-O"), Utf8StringLiteral("-fast")})); + + ASSERT_THAT(project.lastChangeTimePoint(), Gt(lastChangeTimePoint)); + +} + +TEST(ProjectPart, GetNonExistingPoject) +{ + ClangBackEnd::ProjectParts projects; + + ASSERT_THROW(projects.project(Utf8StringLiteral("pathToProjectPart.pro")), ClangBackEnd::ProjectPartDoNotExistException); +} + +TEST(ProjectPart, AddProjectParts) +{ + ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); + ClangBackEnd::ProjectParts projects; + + projects.createOrUpdate({projectContainer}); + + ASSERT_THAT(projects.project(projectContainer.projectPartId()), ClangBackEnd::ProjectPart(projectContainer)); + ASSERT_THAT(projects.project(projectContainer.projectPartId()).arguments(), ElementsAre(StrEq("-O"))); +} + +TEST(ProjectPart, UpdateProjectParts) +{ + ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); + ClangBackEnd::ProjectPartContainer projectContainerWithNewArguments(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-fast")}); + ClangBackEnd::ProjectParts projects; + projects.createOrUpdate({projectContainer}); + + projects.createOrUpdate({projectContainerWithNewArguments}); + + ASSERT_THAT(projects.project(projectContainer.projectPartId()), ClangBackEnd::ProjectPart(projectContainer)); + ASSERT_THAT(projects.project(projectContainer.projectPartId()).arguments(), ElementsAre(StrEq("-fast"))); +} + +TEST(ProjectPart, ThrowExceptionForAccesingRemovedProjectParts) +{ + ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); + ClangBackEnd::ProjectParts projects; + projects.createOrUpdate({projectContainer}); + + projects.remove({projectContainer.projectPartId()}); + + ASSERT_THROW(projects.project(projectContainer.projectPartId()), ClangBackEnd::ProjectPartDoNotExistException); +} + +TEST(ProjectPart, ProjectPartProjectPartIdIsEmptyfterRemoving) +{ + ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); + ClangBackEnd::ProjectParts projects; + projects.createOrUpdate({projectContainer}); + ClangBackEnd::ProjectPart project(projects.project(projectContainer.projectPartId())); + + projects.remove({projectContainer.projectPartId()}); + + ASSERT_TRUE(project.projectPartId().isEmpty()); +} + +TEST(Project, ThrowsForNotExistingProjectPartButRemovesAllExistingProject) +{ + ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro")); + ClangBackEnd::ProjectParts projects; + projects.createOrUpdate({projectContainer}); + ClangBackEnd::ProjectPart project = *projects.findProjectPart(Utf8StringLiteral("pathToProjectPart.pro")); + + EXPECT_THROW(projects.remove({Utf8StringLiteral("doesnotexist.pro"), projectContainer.projectPartId()}), ClangBackEnd::ProjectPartDoNotExistException); + + ASSERT_THAT(projects.projects(), Not(Contains(project))); +} + +TEST(ProjectPart, HasProjectPart) +{ + ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro")); + ClangBackEnd::ProjectParts projects; + projects.createOrUpdate({projectContainer}); + + ASSERT_TRUE(projects.hasProjectPart(projectContainer.projectPartId())); +} + +TEST(ProjectPart, DoNotHasProjectPart) +{ + ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro")); + ClangBackEnd::ProjectParts projects; + projects.createOrUpdate({projectContainer}); + + ASSERT_FALSE(projects.hasProjectPart(Utf8StringLiteral("doesnotexist.pro"))); +} + + +} diff --git a/tests/unit/unittest/readandwritecommandblocktest.cpp b/tests/unit/unittest/readandwritecommandblocktest.cpp new file mode 100644 index 0000000000..d9de87b529 --- /dev/null +++ b/tests/unit/unittest/readandwritecommandblocktest.cpp @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gtest-qt-printing.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gtest-qt-printing.h" + +using namespace testing; +namespace CodeModelBackeEndTest { + +class ReadAndWriteCommandBlockTest : public ::testing::Test +{ +protected: + ReadAndWriteCommandBlockTest(); + + virtual void SetUp() override; + virtual void TearDown() override; + + template + void CompareCommand(const Type &command); + + QVariant writeCodeCompletedCommand(); + void popLastCharacterFromBuffer(); + void pushLastCharacterToBuffer(); + void readPartialCommand(); + +protected: + QBuffer buffer; + ClangBackEnd::WriteCommandBlock writeCommandBlock; + ClangBackEnd::ReadCommandBlock readCommandBlock; + char lastCharacter = 0; +}; + +ReadAndWriteCommandBlockTest::ReadAndWriteCommandBlockTest() + : writeCommandBlock(&buffer), + readCommandBlock(&buffer) +{ +} + +void ReadAndWriteCommandBlockTest::SetUp() +{ + buffer.open(QIODevice::ReadWrite); + writeCommandBlock = ClangBackEnd::WriteCommandBlock(&buffer); + readCommandBlock = ClangBackEnd::ReadCommandBlock(&buffer); +} + +void ReadAndWriteCommandBlockTest::TearDown() +{ + buffer.close(); +} + +TEST_F(ReadAndWriteCommandBlockTest, WriteCommandAndTestSize) +{ + writeCommandBlock.write(QVariant::fromValue(ClangBackEnd::EndCommand())); + + ASSERT_EQ(46, buffer.size()); +} + +TEST_F(ReadAndWriteCommandBlockTest, WriteSecondCommandAndTestSize) +{ + writeCommandBlock.write(QVariant::fromValue(ClangBackEnd::EndCommand())); + + ASSERT_EQ(46, buffer.size()); +} + +TEST_F(ReadAndWriteCommandBlockTest, WriteTwoCommandsAndTestCount) +{ + writeCommandBlock.write(QVariant::fromValue(ClangBackEnd::EndCommand())); + writeCommandBlock.write(QVariant::fromValue(ClangBackEnd::EndCommand())); + + ASSERT_EQ(2, writeCommandBlock.counter()); +} + +TEST_F(ReadAndWriteCommandBlockTest, ReadThreeCommandsAndTestCount) +{ + writeCommandBlock.write(QVariant::fromValue(ClangBackEnd::EndCommand())); + writeCommandBlock.write(QVariant::fromValue(ClangBackEnd::EndCommand())); + writeCommandBlock.write(QVariant::fromValue(ClangBackEnd::EndCommand())); + buffer.seek(0); + + ASSERT_EQ(3, readCommandBlock.readAll().count()); +} + +TEST_F(ReadAndWriteCommandBlockTest, CompareEndCommand) +{ + CompareCommand(ClangBackEnd::EndCommand()); +} + +TEST_F(ReadAndWriteCommandBlockTest, CompareAliveCommand) +{ + CompareCommand(ClangBackEnd::AliveCommand()); +} + +TEST_F(ReadAndWriteCommandBlockTest, CompareRegisterTranslationUnitForCodeCompletionCommand) +{ + ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("pathToProject.pro")); + QVector fileContainers({fileContainer}); + + CompareCommand(ClangBackEnd::RegisterTranslationUnitForCodeCompletionCommand(fileContainers)); +} + +TEST_F(ReadAndWriteCommandBlockTest, CompareUnregisterFileForCodeCompletionCommand) +{ + ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("pathToProject.pro")); + + CompareCommand(ClangBackEnd::UnregisterTranslationUnitsForCodeCompletionCommand({fileContainer})); +} + +TEST_F(ReadAndWriteCommandBlockTest, CompareCompleteCodeCommand) +{ + CompareCommand(ClangBackEnd::CompleteCodeCommand(Utf8StringLiteral("foo.cpp"), 24, 33, Utf8StringLiteral("do what I want"))); +} + +TEST_F(ReadAndWriteCommandBlockTest, CompareCodeCompletedCommand) +{ + QVector codeCompletions({Utf8StringLiteral("newFunction()")}); + + CompareCommand(ClangBackEnd::CodeCompletedCommand(codeCompletions, 1)); +} + +TEST_F(ReadAndWriteCommandBlockTest, GetInvalidCommandForAPartialBuffer) +{ + writeCodeCompletedCommand(); + popLastCharacterFromBuffer(); + buffer.seek(0); + + readPartialCommand(); +} + +TEST_F(ReadAndWriteCommandBlockTest, ReadCommandAfterInterruption) +{ + const QVariant writeCommand = writeCodeCompletedCommand(); + popLastCharacterFromBuffer(); + buffer.seek(0); + readPartialCommand(); + pushLastCharacterToBuffer(); + + ASSERT_EQ(readCommandBlock.read(), writeCommand); +} + +QVariant ReadAndWriteCommandBlockTest::writeCodeCompletedCommand() +{ + ClangBackEnd::CodeCompletedCommand command(QVector({Utf8StringLiteral("newFunction()")}), 1); + const QVariant writeCommand = QVariant::fromValue(command); + writeCommandBlock.write(writeCommand); + + return writeCommand; +} + +void ReadAndWriteCommandBlockTest::popLastCharacterFromBuffer() +{ + auto &internalBuffer = buffer.buffer(); + lastCharacter = internalBuffer.at(internalBuffer.size() - 1); + internalBuffer.chop(1); +} + +void ReadAndWriteCommandBlockTest::pushLastCharacterToBuffer() +{ + buffer.buffer().push_back(lastCharacter); +} + +void ReadAndWriteCommandBlockTest::readPartialCommand() +{ + QVariant readCommand = readCommandBlock.read(); + + ASSERT_FALSE(readCommand.isValid()); +} + +template +void ReadAndWriteCommandBlockTest::CompareCommand(const Type &command) +{ + const QVariant writeCommand = QVariant::fromValue(command); + writeCommandBlock.write(writeCommand); + buffer.seek(0); + + const QVariant readCommand = readCommandBlock.read(); + + ASSERT_EQ(writeCommand, readCommand); +} + +} diff --git a/tests/unit/unittest/spydummy.cpp b/tests/unit/unittest/spydummy.cpp new file mode 100644 index 0000000000..758c8b0762 --- /dev/null +++ b/tests/unit/unittest/spydummy.cpp @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "spydummy.h" + +SpyDummy::SpyDummy(QObject *parent) : QObject(parent) +{ + +} + +SpyDummy::~SpyDummy() +{ + +} + diff --git a/tests/unit/unittest/spydummy.h b/tests/unit/unittest/spydummy.h new file mode 100644 index 0000000000..6d17f49472 --- /dev/null +++ b/tests/unit/unittest/spydummy.h @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef SPYDUMMY_H +#define SPYDUMMY_H + +#include + +class SpyDummy : public QObject +{ + Q_OBJECT +public: + explicit SpyDummy(QObject *parent = 0); + ~SpyDummy(); + +signals: + void tableIsReady(); + void databaseIsOpened(); + void databaseIsClosed(); +}; + +#endif // SPYDUMMY_H diff --git a/tests/unit/unittest/sqlitecolumntest.cpp b/tests/unit/unittest/sqlitecolumntest.cpp new file mode 100644 index 0000000000..a716dc5f3d --- /dev/null +++ b/tests/unit/unittest/sqlitecolumntest.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + +#include +#include +#include "gtest-qt-printing.h" + +#include + +namespace { + +class SqliteColumn : public ::testing::Test +{ +protected: + void SetUp() override; + + ::SqliteColumn column; +}; + +TEST_F(SqliteColumn, ChangeName) +{ + column.setName(Utf8StringLiteral("Claudia")); + + ASSERT_THAT(column.name(), Utf8StringLiteral("Claudia")); +} + +TEST_F(SqliteColumn, DefaultType) +{ + ASSERT_THAT(column.type(), ColumnType::Numeric); +} + +TEST_F(SqliteColumn, ChangeType) +{ + column.setType(ColumnType::Text); + + ASSERT_THAT(column.type(), ColumnType::Text); +} + +TEST_F(SqliteColumn, DefaultPrimaryKey) +{ + ASSERT_FALSE(column.isPrimaryKey()); +} + +TEST_F(SqliteColumn, SetPrimaryKey) +{ + column.setIsPrimaryKey(true); + + ASSERT_TRUE(column.isPrimaryKey()); +} + +TEST_F(SqliteColumn, GetColumnDefinition) +{ + column.setName(Utf8StringLiteral("Claudia")); + + Internal::ColumnDefinition columnDefintion = column.columnDefintion(); + + ASSERT_THAT(columnDefintion.name(), Utf8StringLiteral("Claudia")); + ASSERT_THAT(columnDefintion.type(), ColumnType::Numeric); + ASSERT_FALSE(columnDefintion.isPrimaryKey()); +} + +void SqliteColumn::SetUp() +{ + column.clear(); +} + +} diff --git a/tests/unit/unittest/sqlitedatabasebackendtest.cpp b/tests/unit/unittest/sqlitedatabasebackendtest.cpp new file mode 100644 index 0000000000..c023d85268 --- /dev/null +++ b/tests/unit/unittest/sqlitedatabasebackendtest.cpp @@ -0,0 +1,154 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gtest-qt-printing.h" + +#include + +#include "sqlitedatabasebackend.h" +#include "sqliteexception.h" +#include "sqlitewritestatement.h" + +namespace { + +class SqliteDatabaseBackend : public ::testing::Test +{ +protected: + void SetUp() override; + void TearDown() override; + + QString databaseFilePath = QDir::tempPath() + QStringLiteral("/SqliteDatabaseBackendTest.db"); + ::SqliteDatabaseBackend databaseBackend; +}; + +TEST_F(SqliteDatabaseBackend, OpenAlreadyOpenDatabase) +{ + ASSERT_THROW(databaseBackend.open(databaseFilePath), SqliteException); +} + +TEST_F(SqliteDatabaseBackend, CloseAlreadyClosedDatabase) +{ + databaseBackend.close(); + ASSERT_THROW(databaseBackend.close(), SqliteException); +} + +TEST_F(SqliteDatabaseBackend, OpenWithWrongPath) +{ + ASSERT_THROW(databaseBackend.open(QStringLiteral("/xxx/SqliteDatabaseBackendTest.db")), SqliteException); +} + +TEST_F(SqliteDatabaseBackend, DefaultJournalMode) +{ + ASSERT_THAT(databaseBackend.journalMode(), JournalMode::Delete); +} + +TEST_F(SqliteDatabaseBackend, WalJournalMode) +{ + databaseBackend.setJournalMode(JournalMode::Wal); + + ASSERT_THAT(databaseBackend.journalMode(), JournalMode::Wal); +} + +TEST_F(SqliteDatabaseBackend, TruncateJournalMode) +{ + databaseBackend.setJournalMode(JournalMode::Truncate); + + ASSERT_THAT(databaseBackend.journalMode(), JournalMode::Truncate); +} + +TEST_F(SqliteDatabaseBackend, MemoryJournalMode) +{ + databaseBackend.setJournalMode(JournalMode::Memory); + + ASSERT_THAT(databaseBackend.journalMode(), JournalMode::Memory); +} + +TEST_F(SqliteDatabaseBackend, PersistJournalMode) +{ + databaseBackend.setJournalMode(JournalMode::Persist); + + ASSERT_THAT(databaseBackend.journalMode(), JournalMode::Persist); +} + +TEST_F(SqliteDatabaseBackend, DefaultTextEncoding) +{ + ASSERT_THAT(databaseBackend.textEncoding(), Utf8); +} + +TEST_F(SqliteDatabaseBackend, Utf16TextEncoding) +{ + databaseBackend.setTextEncoding(Utf16); + + ASSERT_THAT(databaseBackend.textEncoding(), Utf16); +} + +TEST_F(SqliteDatabaseBackend, Utf16beTextEncoding) +{ + databaseBackend.setTextEncoding(Utf16be); + + ASSERT_THAT(databaseBackend.textEncoding(), Utf16be); +} + +TEST_F(SqliteDatabaseBackend, Utf16leTextEncoding) +{ + databaseBackend.setTextEncoding(Utf16le); + + ASSERT_THAT(databaseBackend.textEncoding(), Utf16le); +} + +TEST_F(SqliteDatabaseBackend, Utf8TextEncoding) +{ + databaseBackend.setTextEncoding(Utf8); + + ASSERT_THAT(databaseBackend.textEncoding(), Utf8); +} + +TEST_F(SqliteDatabaseBackend, TextEncodingCannotBeChangedAfterTouchingDatabase) +{ + databaseBackend.setJournalMode(JournalMode::Memory); + + SqliteWriteStatement::execute(Utf8StringLiteral("CREATE TABLE text(name, number)")); + + ASSERT_THROW(databaseBackend.setTextEncoding(Utf16), SqliteException); +} + +void SqliteDatabaseBackend::SetUp() +{ + QDir::temp().remove(QStringLiteral("SqliteDatabaseBackendTest.db")); + databaseBackend.open(databaseFilePath); +} + +void SqliteDatabaseBackend::TearDown() +{ + databaseBackend.closeWithoutException(); +} +} diff --git a/tests/unit/unittest/sqlitedatabasetest.cpp b/tests/unit/unittest/sqlitedatabasetest.cpp new file mode 100644 index 0000000000..b4c979fe17 --- /dev/null +++ b/tests/unit/unittest/sqlitedatabasetest.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gtest-qt-printing.h" + +#include +#include + +#include +#include +#include + +#include "spydummy.h" + +namespace { + +class SqliteDatabase : public ::testing::Test +{ +protected: + void SetUp() override; + void TearDown() override; + + SpyDummy spyDummy; + QString databaseFilePath = QStringLiteral(":memory:"); + ::SqliteDatabase database; +}; + +TEST_F(SqliteDatabase, SetDatabaseFilePath) +{ + ASSERT_THAT(database.databaseFilePath(), databaseFilePath); +} + +TEST_F(SqliteDatabase, SetJournalMode) +{ + database.setJournalMode(JournalMode::Memory); + + ASSERT_THAT(database.journalMode(), JournalMode::Memory); +} + +TEST_F(SqliteDatabase, OpenDatabase) +{ + database.close(); + QSignalSpy signalSpy(&spyDummy, &SpyDummy::databaseIsOpened); + database.open(); + + ASSERT_TRUE(signalSpy.wait(100000)); + ASSERT_TRUE(database.isOpen()); +} + +TEST_F(SqliteDatabase, CloseDatabase) +{ + QSignalSpy signalSpy(&spyDummy, &SpyDummy::databaseIsClosed); + + database.close(); + + ASSERT_TRUE(signalSpy.wait(100000)); + ASSERT_FALSE(database.isOpen()); +} + +TEST_F(SqliteDatabase, AddTable) +{ + SqliteTable *sqliteTable = new SqliteTable; + + database.addTable(sqliteTable); + + ASSERT_THAT(database.tables().first(), sqliteTable); +} + +void SqliteDatabase::SetUp() +{ + QObject::connect(&database, &::SqliteDatabase::databaseIsOpened, &spyDummy, &SpyDummy::databaseIsOpened); + QObject::connect(&database, &::SqliteDatabase::databaseIsClosed, &spyDummy, &SpyDummy::databaseIsClosed); + + database.setJournalMode(JournalMode::Memory); + database.setDatabaseFilePath(databaseFilePath); +} + +void SqliteDatabase::TearDown() +{ + database.close(); +} +} diff --git a/tests/unit/unittest/sqlitestatementtest.cpp b/tests/unit/unittest/sqlitestatementtest.cpp new file mode 100644 index 0000000000..5e218168ee --- /dev/null +++ b/tests/unit/unittest/sqlitestatementtest.cpp @@ -0,0 +1,570 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gtest-qt-printing.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace { +class SqliteStatement : public ::testing::Test +{ +protected: + void SetUp() override; + void TearDown() override; + + SqliteDatabaseBackend databaseBackend; +}; + +TEST_F(SqliteStatement, PrepareFailure) +{ + ASSERT_THROW(SqliteReadStatement(Utf8StringLiteral("blah blah blah")), SqliteException); + ASSERT_THROW(SqliteWriteStatement(Utf8StringLiteral("blah blah blah")), SqliteException); + ASSERT_THROW(SqliteReadStatement(Utf8StringLiteral("INSERT INTO test(name, number) VALUES (?, ?)")), SqliteException); + ASSERT_THROW(SqliteWriteStatement(Utf8StringLiteral("SELECT name, number FROM test '")), SqliteException); +} + +TEST_F(SqliteStatement, CountRows) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT * FROM test")); + int nextCount = 0; + while (statement.next()) + ++nextCount; + + int sqlCount = SqliteReadStatement::toValue(Utf8StringLiteral("SELECT count(*) FROM test")); + + ASSERT_THAT(nextCount, sqlCount); +} + +TEST_F(SqliteStatement, Value) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test ORDER BY name")); + + statement.next(); + + ASSERT_THAT(statement.value(1).type(), QVariant::ByteArray); + + statement.next(); + + ASSERT_THAT(statement.value(0), 0); + ASSERT_THAT(statement.value(0), 0); + ASSERT_THAT(statement.value(0), 0.0); + ASSERT_THAT(statement.value(0), QStringLiteral("foo")); + ASSERT_THAT(statement.value(0), Utf8StringLiteral("foo")); + ASSERT_THAT(statement.value(0), QVariant::fromValue(QStringLiteral("foo"))); + ASSERT_THAT(statement.value(0).type(), QVariant::String); + + ASSERT_THAT(statement.value(1), 23); + ASSERT_THAT(statement.value(1), 23); + ASSERT_THAT(statement.value(1), 23.3); + ASSERT_THAT(statement.value(1), QStringLiteral("23.3")); + ASSERT_THAT(statement.value(1), Utf8StringLiteral("23.3")); + ASSERT_THAT(statement.value(1), QVariant::fromValue(23.3)); + ASSERT_THAT(statement.value(1).type(), QVariant::Double); + + statement.next(); + + ASSERT_THAT(statement.value(1).type(), QVariant::LongLong); +} + +TEST_F(SqliteStatement, ValueFailure) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test")); + ASSERT_THROW(statement.value(0), SqliteException); + + statement.reset(); + + while (statement.next()) {} + ASSERT_THROW(statement.value(0), SqliteException); + + statement.reset(); + + statement.next(); + ASSERT_THROW(statement.value(-1), SqliteException); + ASSERT_THROW(statement.value(2), SqliteException); +} + +TEST_F(SqliteStatement, ToIntergerValue) +{ + ASSERT_THAT(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT number FROM test WHERE name='foo'")), 23); +} + +TEST_F(SqliteStatement, ToLongIntergerValue) +{ + ASSERT_THAT(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT number FROM test WHERE name='foo'")), 23LL); +} + +TEST_F(SqliteStatement, ToDoubleValue) +{ + ASSERT_THAT(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT number FROM test WHERE name='foo'")), 23.3); +} + +TEST_F(SqliteStatement, ToQStringValue) +{ + ASSERT_THAT(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT name FROM test WHERE name='foo'")), QStringLiteral("foo")); +} + +TEST_F(SqliteStatement, ToUtf8StringValue) +{ + ASSERT_THAT(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT name FROM test WHERE name='foo'")), Utf8StringLiteral("foo")); +} + +TEST_F(SqliteStatement, ToQByteArrayValueIsNull) +{ + ASSERT_TRUE(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT name FROM test WHERE name='foo'")).isNull()); +} + +TEST_F(SqliteStatement, ToQVariantValue) +{ + ASSERT_THAT(SqliteReadStatement::toValue(Utf8StringLiteral("SELECT name FROM test WHERE name='foo'")), QVariant::fromValue(QStringLiteral("foo"))); +} + +TEST_F(SqliteStatement, Utf8Values) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test ORDER by name")); + + Utf8StringVector values = statement.values(); + ASSERT_THAT(values.count(), 3); + ASSERT_THAT(values.at(0), Utf8StringLiteral("bar")); + ASSERT_THAT(values.at(1), Utf8StringLiteral("foo")); + ASSERT_THAT(values.at(2), Utf8StringLiteral("poo")); +} +TEST_F(SqliteStatement, DoubleValues) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test ORDER by name")); + + QVector values = statement.values>(1); + + ASSERT_THAT(values.count(), 3); + ASSERT_THAT(values.at(0), 0.0); + ASSERT_THAT(values.at(1), 23.3); + ASSERT_THAT(values.at(2), 40.0); +} + +TEST_F(SqliteStatement, QVariantValues) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test ORDER by name")); + + QVector values = statement.values>(QVector() << 0 << 1); + + ASSERT_THAT(values.count(), 6); + ASSERT_THAT(values.at(0), QVariant::fromValue(QStringLiteral("bar"))); + ASSERT_THAT(values.at(1), QVariant::fromValue(QByteArray::fromHex("0500"))); + ASSERT_THAT(values.at(2), QVariant::fromValue(QStringLiteral("foo"))); + ASSERT_THAT(values.at(3), QVariant::fromValue(23.3)); + ASSERT_THAT(values.at(4), QVariant::fromValue(QStringLiteral("poo"))); + ASSERT_THAT(values.at(5), QVariant::fromValue(40)); +} + +TEST_F(SqliteStatement, RowColumnValueMapCountForValidRow) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE rowid=1")); + + QMap values = statement.rowColumnValueMap(); + + ASSERT_THAT(values.count(), 2); +} + +TEST_F(SqliteStatement, RowColumnValueMapCountForInvalidRow) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE rowid=100")); + + QMap values = statement.rowColumnValueMap(); + + ASSERT_THAT(values.count(), 0); +} + +TEST_F(SqliteStatement, RowColumnValueMapValues) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE rowid=2")); + + QMap values = statement.rowColumnValueMap(); + + ASSERT_THAT(values.value(QStringLiteral("name")).toString(), QStringLiteral("foo")); + ASSERT_THAT(values.value(QStringLiteral("number")).toDouble(), 23.3); +} + +TEST_F(SqliteStatement, TwoColumnValueMapCount) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test")); + + QMap values = statement.twoColumnValueMap(); + + ASSERT_THAT(values.count(), 3); +} + +TEST_F(SqliteStatement, TwoColumnValueMapValues) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test")); + + QMap values = statement.twoColumnValueMap(); + + ASSERT_THAT(values.value(QStringLiteral("foo")).toDouble(), 23.3); +} + +TEST_F(SqliteStatement, ValuesFailure) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test")); + + ASSERT_THROW(statement.values>(QVector() << 1 << 2);, SqliteException); + ASSERT_THROW(statement.values>(QVector() << -1 << 1);, SqliteException); +} + +TEST_F(SqliteStatement, ColumnNames) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test")); + + Utf8StringVector columnNames = statement.columnNames(); + + ASSERT_THAT(columnNames.count(), statement.columnCount()); + + ASSERT_THAT(columnNames.at(0), Utf8StringLiteral("name")); + ASSERT_THAT(columnNames.at(1), Utf8StringLiteral("number")); +} + +TEST_F(SqliteStatement, BindQString) +{ + + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE name=?")); + + statement.bind(1, QStringLiteral("foo")); + + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("foo")); + ASSERT_THAT(statement.value(1), 23.3); +} + +TEST_F(SqliteStatement, BindInteger) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); + + statement.bind(1, 40); + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("poo")); +} + +TEST_F(SqliteStatement, BindLongInteger) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); + + statement.bind(1, qint64(40)); + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("poo")); +} + +TEST_F(SqliteStatement, BindByteArray) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); + + statement.bind(1, QByteArray::fromHex("0500")); + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("bar")); +} + +TEST_F(SqliteStatement, BindDouble) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); + + statement.bind(1, 23.3); + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("foo")); +} + +TEST_F(SqliteStatement, BindIntergerQVariant) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); + + statement.bind(1, QVariant::fromValue(40)); + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("poo")); +} + +TEST_F(SqliteStatement, BindLongIntergerQVariant) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); + + statement.bind(1, QVariant::fromValue(qint64(40))); + statement.next(); + ASSERT_THAT(statement.value(0), QStringLiteral("poo")); +} + +TEST_F(SqliteStatement, BindDoubleQVariant) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); + + statement.bind(1, QVariant::fromValue(23.3)); + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("foo")); + } + +TEST_F(SqliteStatement, BindByteArrayQVariant) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=?")); + + statement.bind(1, QVariant::fromValue(QByteArray::fromHex("0500"))); + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("bar")); +} + +TEST_F(SqliteStatement, BindIntegerByParameter) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=@number")); + + statement.bind(Utf8StringLiteral("@number"), 40); + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("poo")); +} + +TEST_F(SqliteStatement, BindLongIntegerByParameter) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=@number")); + + statement.bind(Utf8StringLiteral("@number"), qint64(40)); + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("poo")); +} + +TEST_F(SqliteStatement, BindByteArrayByParameter) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=@number")); + + statement.bind(Utf8StringLiteral("@number"), QByteArray::fromHex("0500")); + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("bar")); +} + +TEST_F(SqliteStatement, BindDoubleByIndex) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=@number")); + + statement.bind(statement.bindingIndexForName(Utf8StringLiteral("@number")), 23.3); + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("foo")); +} + +TEST_F(SqliteStatement, BindQVariantByIndex) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=@number")); + + statement.bind(statement.bindingIndexForName(Utf8StringLiteral("@number")), QVariant::fromValue((40))); + statement.next(); + + ASSERT_THAT(statement.value(0), QStringLiteral("poo")); + +} + +TEST_F(SqliteStatement, BindFailure) +{ + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE number=@number")); + + ASSERT_THROW(statement.bind(0, 40), SqliteException); + ASSERT_THROW(statement.bind(2, 40), SqliteException); + ASSERT_THROW(statement.bind(Utf8StringLiteral("@name"), 40), SqliteException); +} + +TEST_F(SqliteStatement, RequestBindingNamesFromStatement) +{ + Utf8StringVector expectedValues({Utf8StringLiteral("name"), Utf8StringLiteral("number"), Utf8StringLiteral("id")}); + + SqliteWriteStatement statement(Utf8StringLiteral("UPDATE test SET name=@name, number=@number WHERE rowid=@id")); + + ASSERT_THAT(statement.bindingColumnNames(), expectedValues); +} + +TEST_F(SqliteStatement, WriteUpdateWidthUnamedParameter) +{ + { + int startTotalCount = databaseBackend.totalChangesCount(); + RowDictionary firstValueMap; + firstValueMap.insert(Utf8StringLiteral("name"), QStringLiteral("foo")); + firstValueMap.insert(Utf8StringLiteral("number"), 66.6); + + RowDictionary secondValueMap; + secondValueMap.insert(Utf8StringLiteral("name"), QStringLiteral("bar")); + secondValueMap.insert(Utf8StringLiteral("number"), 77.7); + + SqliteWriteStatement statement(Utf8StringLiteral("UPDATE test SET number=? WHERE name=?")); + statement.setBindingColumnNames(Utf8StringVector() << Utf8StringLiteral("number") << Utf8StringLiteral("name")); + + statement.write(firstValueMap); + + ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 1); + + statement.write(firstValueMap); + + ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 2); + + statement.write(secondValueMap); + + ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 3); + } + + { + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE name='foo'")); + + statement.next(); + + ASSERT_THAT(statement.value(1), 66.6); + } +} + +TEST_F(SqliteStatement, WriteUpdateWidthNamedParameter) +{ + { + int startTotalCount = databaseBackend.totalChangesCount(); + RowDictionary firstValueMap; + firstValueMap.insert(Utf8StringLiteral("name"), QStringLiteral("foo")); + firstValueMap.insert(Utf8StringLiteral("number"), 99.9); + + SqliteWriteStatement statement(Utf8StringLiteral("UPDATE test SET number=@number WHERE name=@name")); + statement.write(firstValueMap); + ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 1); + } + + { + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE name='foo'")); + statement.next(); + ASSERT_THAT(statement.value(1), 99.9); + } +} + +TEST_F(SqliteStatement, WriteUpdateWidthNamedParameterAndBindNotAllParameter) +{ + { + int startTotalCount = databaseBackend.totalChangesCount(); + RowDictionary firstValueMap; + firstValueMap.insert(Utf8StringLiteral("name"), QStringLiteral("foo")); + + SqliteWriteStatement statement(Utf8StringLiteral("UPDATE test SET number=@number WHERE name=@name")); + statement.writeUnchecked(firstValueMap); + ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 1); + } + + { + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE name='foo'")); + statement.next(); + ASSERT_THAT(statement.value(1), 0.0); + } +} + +TEST_F(SqliteStatement, WriteInsert) +{ + { + int startTotalCount = databaseBackend.totalChangesCount(); + + RowDictionary valueMap; + valueMap.insert(Utf8StringLiteral("name"), QStringLiteral("jane")); + valueMap.insert(Utf8StringLiteral("number"), 232.3); + + SqliteWriteStatement statement(Utf8StringLiteral("INSERT OR IGNORE INTO test(name, number) VALUES (?, ?)")); + statement.setBindingColumnNames(Utf8StringVector() << Utf8StringLiteral("name") << Utf8StringLiteral("number")); + statement.write(valueMap); + ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 1); + statement.write(valueMap); + ASSERT_THAT(databaseBackend.totalChangesCount(), startTotalCount + 1); + } + + { + SqliteReadStatement statement(Utf8StringLiteral("SELECT name, number FROM test WHERE name='jane'")); + statement.next(); + ASSERT_THAT(statement.value(1), 232.3); + } +} + +TEST_F(SqliteStatement, WriteFailure) +{ + { + RowDictionary valueMap; + valueMap.insert(Utf8StringLiteral("name"), QStringLiteral("foo")); + valueMap.insert(Utf8StringLiteral("number"), 323.3); + + SqliteWriteStatement statement(Utf8StringLiteral("INSERT INTO test(name, number) VALUES (?, ?)")); + statement.setBindingColumnNames(Utf8StringVector() << Utf8StringLiteral("name") << Utf8StringLiteral("number")); + ASSERT_THROW(statement.write(valueMap), SqliteException); + } + + { + RowDictionary valueMap; + valueMap.insert(Utf8StringLiteral("name"), QStringLiteral("bar")); + + SqliteWriteStatement statement(Utf8StringLiteral("INSERT OR IGNORE INTO test(name, number) VALUES (?, ?)")); + statement.setBindingColumnNames(Utf8StringVector() << Utf8StringLiteral("name") << Utf8StringLiteral("number")); + ASSERT_THROW(statement.write(valueMap), SqliteException); + } +} + +TEST_F(SqliteStatement, ClosedDatabase) +{ + databaseBackend.close(); + ASSERT_THROW(SqliteWriteStatement(Utf8StringLiteral("INSERT INTO test(name, number) VALUES (?, ?)")), SqliteException); + ASSERT_THROW(SqliteReadStatement(Utf8StringLiteral("SELECT * FROM test")), SqliteException); + ASSERT_THROW(SqliteReadWriteStatement(Utf8StringLiteral("INSERT INTO test(name, number) VALUES (?, ?)")), SqliteException); + databaseBackend.open(QDir::tempPath() + QStringLiteral("/SqliteStatementTest.db")); +} + +void SqliteStatement::SetUp() +{ + databaseBackend.open(QStringLiteral(":memory:")); + SqliteWriteStatement::execute(Utf8StringLiteral("CREATE TABLE test(name TEXT UNIQUE, number NUMERIC)")); + SqliteWriteStatement::execute(Utf8StringLiteral("INSERT INTO test VALUES ('bar', x'0500')")); + SqliteWriteStatement::execute(Utf8StringLiteral("INSERT INTO test VALUES ('foo', 23.3)")); + SqliteWriteStatement::execute(Utf8StringLiteral("INSERT INTO test VALUES ('poo', 40)")); +} + +void SqliteStatement::TearDown() +{ + databaseBackend.close(); +} + +} diff --git a/tests/unit/unittest/sqlitetabletest.cpp b/tests/unit/unittest/sqlitetabletest.cpp new file mode 100644 index 0000000000..fa5e671163 --- /dev/null +++ b/tests/unit/unittest/sqlitetabletest.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gtest-qt-printing.h" + +#include +#include + +#include +#include +#include +#include + +#include "spydummy.h" + +namespace { + +class SqliteTable : public ::testing::Test +{ +protected: + void SetUp() override; + void TearDown() override; + + SqliteColumn *addColumn(const Utf8String &columnName); + + SpyDummy spyDummy; + SqliteDatabase *database = nullptr; + ::SqliteTable *table = nullptr; + Utf8String tableName = Utf8StringLiteral("testTable"); +}; + + +TEST_F(SqliteTable, ColumnIsAddedToTable) +{ + table->setUseWithoutRowId(true); + + ASSERT_TRUE(table->useWithoutRowId()); +} + +TEST_F(SqliteTable, SetTableName) +{ + table->setName(tableName); + + ASSERT_THAT(table->name(), tableName); +} + +TEST_F(SqliteTable, SetUseWithoutRowid) +{ + table->setUseWithoutRowId(true); + + ASSERT_TRUE(table->useWithoutRowId()); +} + +TEST_F(SqliteTable, TableIsReadyAfterOpenDatabase) +{ + QSignalSpy signalSpy(&spyDummy, &SpyDummy::tableIsReady); + table->setName(tableName); + addColumn(Utf8StringLiteral("name")); + + database->open(); + + ASSERT_TRUE(signalSpy.wait(100000)); +} + +void SqliteTable::SetUp() +{ + table = new ::SqliteTable; + QObject::connect(table, &::SqliteTable::tableIsReady, &spyDummy, &SpyDummy::tableIsReady); + + database = new SqliteDatabase; + database->setJournalMode(JournalMode::Memory); + database->setDatabaseFilePath( QStringLiteral(":memory:")); + database->addTable(table); +} + +void SqliteTable::TearDown() +{ + database->close(); + delete database; + database = nullptr; + table = nullptr; +} + +SqliteColumn *SqliteTable::addColumn(const Utf8String &columnName) +{ + SqliteColumn *newSqliteColum = new SqliteColumn; + + newSqliteColum->setName(columnName); + + table->addColumn(newSqliteColum); + + return newSqliteColum; +} +} diff --git a/tests/unit/unittest/sqlstatementbuildertest.cpp b/tests/unit/unittest/sqlstatementbuildertest.cpp new file mode 100644 index 0000000000..1f04c64f5f --- /dev/null +++ b/tests/unit/unittest/sqlstatementbuildertest.cpp @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gtest-qt-printing.h" + +#include + +#include +#include +#include + +using namespace ::testing; + +TEST(SqlStatementBuilder, Bind) +{ + SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table WHERE $column = 'foo' AND rowid=$row AND rowid IN ($rows)")); + + sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringVector() << Utf8StringLiteral("name") << Utf8StringLiteral("number")); + sqlStatementBuilder.bind(Utf8StringLiteral("$column"), Utf8StringLiteral("name")); + sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); + sqlStatementBuilder.bind(Utf8StringLiteral("$row"), 20); + sqlStatementBuilder.bind(Utf8StringLiteral("$rows"), QVector() << 1 << 2 << 3); + + ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("SELECT name, number FROM test WHERE name = 'foo' AND rowid=20 AND rowid IN (1, 2, 3)")); +} + +TEST(SqlStatementBuilder, BindEmpty) +{ + SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table$emptyPart")); + sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringVector() << Utf8StringLiteral("name") << Utf8StringLiteral("number")); + sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); + + sqlStatementBuilder.bindEmptyText(Utf8StringLiteral("$emptyPart")); + + ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("SELECT name, number FROM test")); +} + +TEST(SqlStatementBuilder, BindFailure) +{ + SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table")); + + Utf8StringVector columns; + + ASSERT_THROW(sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringLiteral("")), SqlStatementBuilderException); + ASSERT_THROW(sqlStatementBuilder.bind(Utf8StringLiteral("columns"), Utf8StringLiteral("test")), SqlStatementBuilderException); + ASSERT_THROW(sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), columns), SqlStatementBuilderException); + ASSERT_THROW(sqlStatementBuilder.bindWithInsertTemplateParameters(Utf8StringLiteral("$columns"), columns), SqlStatementBuilderException); + ASSERT_THROW(sqlStatementBuilder.bindWithUpdateTemplateParameters(Utf8StringLiteral("$columns"), columns), SqlStatementBuilderException); +} + +TEST(SqlStatementBuilder, BindWithInsertTemplateParameters) +{ + Utf8StringVector columns({Utf8StringLiteral("name"), Utf8StringLiteral("number")}); + + SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("INSERT OR IGNORE INTO $table ($columns) VALUES ($values)")); + sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); + sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), columns); + sqlStatementBuilder.bindWithInsertTemplateParameters(Utf8StringLiteral("$values"), columns); + + ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("INSERT OR IGNORE INTO test (name, number) VALUES (?, ?)")); +} + +TEST(SqlStatementBuilder, BindWithUpdateTemplateParameters) +{ + Utf8StringVector columns({Utf8StringLiteral("name"), Utf8StringLiteral("number")}); + + SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("UPDATE $table SET $columnValues WHERE id=?")); + sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); + sqlStatementBuilder.bindWithUpdateTemplateParameters(Utf8StringLiteral("$columnValues"), columns); + + ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("UPDATE test SET name=?, number=? WHERE id=?")); +} + +TEST(SqlStatementBuilder, BindWithUpdateTemplateNames) +{ + Utf8StringVector columns({Utf8StringLiteral("name"), Utf8StringLiteral("number")}); + + SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("UPDATE $table SET $columnValues WHERE id=@id")); + sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); + sqlStatementBuilder.bindWithUpdateTemplateNames(Utf8StringLiteral("$columnValues"), columns); + + ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("UPDATE test SET name=@name, number=@number WHERE id=@id")); +} + +TEST(SqlStatementBuilder, ClearOnRebinding) +{ + SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table")); + + sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringLiteral("name, number")); + sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); + + ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("SELECT name, number FROM test")); + + sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test2")); + + ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("SELECT name, number FROM test2")); +} + +TEST(SqlStatementBuilder, ClearBinding) +{ + SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table")); + + sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringLiteral("name, number")); + sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); + + ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("SELECT name, number FROM test")); + + sqlStatementBuilder.clear(); + + ASSERT_THROW(sqlStatementBuilder.sqlStatement(), SqlStatementBuilderException); +} + +TEST(SqlStatementBuilder, ColumnType) +{ + ASSERT_THAT(SqlStatementBuilder::columnTypeToString(ColumnType::Numeric), Utf8StringLiteral("NUMERIC")); + ASSERT_THAT(SqlStatementBuilder::columnTypeToString(ColumnType::Integer), Utf8StringLiteral("INTEGER")); + ASSERT_THAT(SqlStatementBuilder::columnTypeToString(ColumnType::Real), Utf8StringLiteral("REAL")); + ASSERT_THAT(SqlStatementBuilder::columnTypeToString(ColumnType::Text), Utf8StringLiteral("TEXT")); + ASSERT_TRUE(SqlStatementBuilder::columnTypeToString(ColumnType::None).isEmpty()); +} + +TEST(SqlStatementBuilder, SqlStatementFailure) +{ + SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table")); + + sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringLiteral("name, number")); + + ASSERT_THROW(sqlStatementBuilder.sqlStatement(), SqlStatementBuilderException); +} + +TEST(SqlStatementBuilder, IsBuild) +{ + SqlStatementBuilder sqlStatementBuilder(Utf8StringLiteral("SELECT $columns FROM $table")); + + sqlStatementBuilder.bind(Utf8StringLiteral("$columns"), Utf8StringLiteral("name, number")); + sqlStatementBuilder.bind(Utf8StringLiteral("$table"), Utf8StringLiteral("test")); + + ASSERT_FALSE(sqlStatementBuilder.isBuild()); + + ASSERT_THAT(sqlStatementBuilder.sqlStatement(), Utf8StringLiteral("SELECT name, number FROM test")); + + ASSERT_TRUE(sqlStatementBuilder.isBuild()); + + sqlStatementBuilder.clear(); + + ASSERT_FALSE(sqlStatementBuilder.isBuild()); +} diff --git a/tests/unit/unittest/translationunitstest.cpp b/tests/unit/unittest/translationunitstest.cpp new file mode 100644 index 0000000000..3b74c5a166 --- /dev/null +++ b/tests/unit/unittest/translationunitstest.cpp @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gmock/gmock-generated-matchers.h" +#include "gtest-qt-printing.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using ClangBackEnd::TranslationUnit; +using ClangBackEnd::UnsavedFiles; +using ClangBackEnd::ProjectPart; + +using testing::IsNull; +using testing::NotNull; +using testing::Gt; +using testing::Not; +using testing::Contains; + +namespace { + +using ::testing::PrintToString; + +MATCHER_P2(IsTranslationUnit, filePath, projectPartId, + std::string(negation ? "isn't" : "is") + " translation unit with file path " + + PrintToString(filePath) + " and project " + PrintToString(projectPartId) + ) +{ + if (arg.filePath() != filePath) { + *result_listener << "file path is " + PrintToString(arg.filePath()) + " and not " + PrintToString(filePath); + return false; + } + + if (arg.projectPartId() != projectPartId) { + *result_listener << "file path is " + PrintToString(arg.projectPartId()) + " and not " + PrintToString(projectPartId); + return false; + } + + return true; +} + +class TranslationUnits : public ::testing::Test +{ +protected: + void SetUp() override; + + ClangBackEnd::ProjectParts projects; + ClangBackEnd::UnsavedFiles unsavedFiles; + ClangBackEnd::TranslationUnits translationUnits = ClangBackEnd::TranslationUnits(projects, unsavedFiles); + const Utf8String filePath = Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"); + const Utf8String projectPartId = Utf8StringLiteral("/path/to/projectfile"); + +}; + +void TranslationUnits::SetUp() +{ + projects.createOrUpdate({ClangBackEnd::ProjectPartContainer(projectPartId)}); +} + + +TEST_F(TranslationUnits, ThrowForGettingWithWrongFilePath) +{ + ASSERT_THROW(translationUnits.translationUnit(Utf8StringLiteral("foo.cpp"), projectPartId), + ClangBackEnd::TranslationUnitDoesNotExistException); + +} + +TEST_F(TranslationUnits, ThrowForGettingWithWrongProjectPartFilePath) +{ + ASSERT_THROW(translationUnits.translationUnit(filePath, Utf8StringLiteral("foo.pro")), + ClangBackEnd::ProjectPartDoNotExistException); + +} + +TEST_F(TranslationUnits, ThrowForAddingNonExistingFile) +{ + ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), projectPartId); + + ASSERT_THROW(translationUnits.createOrUpdate({fileContainer}), + ClangBackEnd::TranslationUnitFileNotExitsException); +} + +TEST_F(TranslationUnits, DoNotThrowForAddingNonExistingFileWithUnsavedContent) +{ + ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), projectPartId, Utf8String(), true); + + ASSERT_NO_THROW(translationUnits.createOrUpdate({fileContainer})); +} + +TEST_F(TranslationUnits, Add) +{ + ClangBackEnd::FileContainer fileContainer(filePath, projectPartId); + + translationUnits.createOrUpdate({fileContainer}); + + ASSERT_THAT(translationUnits.translationUnit(filePath, projectPartId), + IsTranslationUnit(filePath, projectPartId)); +} + +TEST_F(TranslationUnits, ThrowForRemovingWithWrongFilePath) +{ + ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), projectPartId); + + ASSERT_THROW(translationUnits.remove({fileContainer}), + ClangBackEnd::TranslationUnitDoesNotExistException); +} + +TEST_F(TranslationUnits, ThrowForRemovingWithWrongProjectPartFilePath) +{ + ClangBackEnd::FileContainer fileContainer(filePath, Utf8StringLiteral("foo.pro")); + + ASSERT_THROW(translationUnits.remove({fileContainer}), + ClangBackEnd::ProjectPartDoNotExistException); +} + +TEST_F(TranslationUnits, Remove) +{ + ClangBackEnd::FileContainer fileContainer(filePath, projectPartId); + translationUnits.createOrUpdate({fileContainer}); + + translationUnits.remove({fileContainer}); + + ASSERT_THROW(translationUnits.translationUnit(filePath, projectPartId), + ClangBackEnd::TranslationUnitDoesNotExistException); +} + +TEST_F(TranslationUnits, RemoveAllValidIfExceptionIsThrown) +{ + ClangBackEnd::FileContainer fileContainer(filePath, projectPartId); + translationUnits.createOrUpdate({fileContainer}); + + ASSERT_THROW(translationUnits.remove({ClangBackEnd::FileContainer(Utf8StringLiteral("dontextist.pro"), projectPartId), fileContainer}), + ClangBackEnd::TranslationUnitDoesNotExistException); + + ASSERT_THAT(translationUnits.translationUnits(), + Not(Contains(TranslationUnit(filePath, unsavedFiles, projects.project(projectPartId))))); +} + +} + + diff --git a/tests/unit/unittest/translationunittest.cpp b/tests/unit/unittest/translationunittest.cpp new file mode 100644 index 0000000000..72cd39cf29 --- /dev/null +++ b/tests/unit/unittest/translationunittest.cpp @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gmock/gmock-generated-matchers.h" +#include "gtest-qt-printing.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using ClangBackEnd::TranslationUnit; +using ClangBackEnd::UnsavedFiles; +using ClangBackEnd::ProjectPart; + +using testing::IsNull; +using testing::NotNull; +using testing::Gt; + +namespace { + +TEST(TranslationUnit, DefaultTranslationUnitIsInvalid) +{ + TranslationUnit translationUnit; + + ASSERT_TRUE(translationUnit.isNull()); +} + +TEST(TranslationUnit, ThrowExceptionForNonExistingFilePath) +{ + ASSERT_THROW(TranslationUnit(Utf8StringLiteral("file.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile"))), + ClangBackEnd::TranslationUnitFileNotExitsException); +} + +TEST(TranslationUnit, ThrowNoExceptionForNonExistingFilePathIfDoNotCheckIfFileExistsIsSet) +{ + ASSERT_NO_THROW(TranslationUnit(Utf8StringLiteral("file.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile")), TranslationUnit::DoNotCheckIfFileExists)); +} + +TEST(TranslationUnit, TranslationUnitIsValid) +{ + TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile"))); + + ASSERT_FALSE(translationUnit.isNull()); +} + + +TEST(TranslationUnit, ThrowExceptionForGettingIndexForInvalidUnit) +{ + TranslationUnit translationUnit; + + ASSERT_THROW(translationUnit.index(), ClangBackEnd::TranslationUnitIsNullException); +} + +TEST(TranslationUnit, IndexGetterIsNonNullForValidUnit) +{ + TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile"))); + + ASSERT_THAT(translationUnit.index(), NotNull()); +} + +TEST(TranslationUnit, ThrowExceptionForGettingCxTranslationUnitForInvalidUnit) +{ + TranslationUnit translationUnit; + + ASSERT_THROW(translationUnit.cxTranslationUnit(), ClangBackEnd::TranslationUnitIsNullException); +} + +TEST(TranslationUnit, CxTranslationUnitGetterIsNonNullForValidUnit) +{ + UnsavedFiles unsavedFiles; + TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), unsavedFiles, ProjectPart(Utf8StringLiteral("/path/to/projectfile"))); + + ASSERT_THAT(translationUnit.cxTranslationUnit(), NotNull()); +} + +TEST(TranslationUnit, ThrowExceptionIfGettingFilePathForNullUnit) +{ + TranslationUnit translationUnit; + + ASSERT_THROW(translationUnit.filePath(), ClangBackEnd::TranslationUnitIsNullException); +} + +TEST(TranslationUnit, ResetedTranslationUnitIsNull) +{ + TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile"))); + + translationUnit.reset(); + + ASSERT_TRUE(translationUnit.isNull()); +} + +TEST(TranslationUnit, TimeStampIsUpdatedAsNewCxTranslationUnitIsGenerated) +{ + TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), UnsavedFiles(), ProjectPart(Utf8StringLiteral("/path/to/projectfile"))); + auto lastChangeTimePoint = translationUnit.lastChangeTimePoint(); + std::this_thread::sleep_for(std::chrono::steady_clock::duration(1)); + + translationUnit.cxTranslationUnit(); + + ASSERT_THAT(translationUnit.lastChangeTimePoint(), Gt(lastChangeTimePoint)); +} + + +//TEST(TranslationUnit, ThrowParseErrorForWrongArguments) +//{ +// ProjectPart project(Utf8StringLiteral("/path/to/projectfile")); +// project.setArguments({Utf8StringLiteral("-fblah")}); +// TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"), UnsavedFiles(), project); + +// ASSERT_THROW(translationUnit.cxTranslationUnit(), ClangBackEnd::TranslationUnitParseErrorException); +//} + +} diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro new file mode 100644 index 0000000000..330a4f3d5b --- /dev/null +++ b/tests/unit/unittest/unittest.pro @@ -0,0 +1,89 @@ +QT += core network testlib +QT -= gui + +TARGET = unittest +CONFIG += console c++14 testcase +CONFIG -= app_bundle + +TEMPLATE = app + +GMOCK_DIR = $$(GMOCK_DIR) +GTEST_DIR = $$GMOCK_DIR/gtest + +requires(exists($$GMOCK_DIR)) +!exists($$GMOCK_DIR):message("No gmock is found! To enabe unit tests set GMOCK_DIR") + +INCLUDEPATH += $$GTEST_DIR $$GTEST_DIR/include $$GMOCK_DIR $$GMOCK_DIR/include + +include(../../../src/libs/sqlite/sqlite-lib.pri) +include(../../../src/libs/clangbackendipc/clangbackendipc-lib.pri) +include(../../../src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri) +include(../../../src/shared/clang/clang_installation.pri) +include(../../../src/plugins/clangcodemodel/clangcodemodelunittestfiles.pri) + +INCLUDEPATH += $$PWD/../../../src/libs $$PWD/../../../src/plugins + +requires(!isEmpty(LLVM_LIBS)) + +LIBS += $$LLVM_LIBS +INCLUDEPATH += $$LLVM_INCLUDEPATH +INCLUDEPATH += ../../../../src/libs/utils + +osx:QMAKE_CXXFLAGS = -stdlib=libc++ + +SOURCES += main.cpp \ + $$GTEST_DIR/src/gtest-all.cc \ + $$GMOCK_DIR/src/gmock-all.cc \ + utf8test.cpp \ + sqlstatementbuildertest.cpp \ + createtablesqlstatementbuildertest.cpp \ + sqlitecolumntest.cpp \ + sqlitestatementtest.cpp \ + sqlitetabletest.cpp \ + spydummy.cpp \ + sqlitedatabasetest.cpp \ + sqlitedatabasebackendtest.cpp \ + readandwritecommandblocktest.cpp \ + clientserverinprocesstest.cpp \ + clientserveroutsideprocess.cpp \ + gtest-qt-printing.cpp \ + codecompletiontest.cpp \ + ../../../src/libs/utils/qtcassert.cpp \ + clangstringtest.cpp \ + translationunittest.cpp \ + clangcodecompleteresultstest.cpp \ + codecompletionsextractortest.cpp \ + unsavedfilestest.cpp \ + projecttest.cpp \ + clangipcservertest.cpp \ + translationunitstest.cpp \ + completionchunkstotextconvertertest.cpp + +HEADERS += \ + gtest-qt-printing.h \ + spydummy.h \ + ../../../src/libs/utils/qtcassert.h \ + mockipclient.h \ + mockipcserver.h + +OTHER_FILES += data/complete_testfile_1.cpp \ + data/complete_completer.cpp \ + data/complete_completer_unsaved.cpp \ + data/complete_extractor_function.cpp \ + data/complete_extractor_function_unsaved.cpp \ + data/complete_extractor_function_unsaved_2.cpp \ + data/complete_extractor_variable.cpp \ + data/complete_extractor_class.cpp \ + data/complete_extractor_namespace.cpp \ + data/complete_extractor_enumeration.cpp \ + data/complete_extractor_constructor.cpp \ + data/complete_translationunit_parse_error.cpp + +DEFINES += QT_NO_CAST_FROM_ASCII +DEFINES += CLANGBACKEND_TESTS +DEFINES += DONT_CHECK_COMMAND_COUNTER +DEFINES += GTEST_HAS_STD_INITIALIZER_LIST_ GTEST_LANG_CXX11 + +DEFINES += TESTDATA_DIR=\"R\\\"xxx($$PWD/data)xxx\\\"\" +win32:DEFINES += ECHOSERVER=\"R\\\"xxx($$OUT_PWD/../echo)xxx\\\"\" +unix:DEFINES += ECHOSERVER=\"R\\\"xxx($$OUT_PWD/../echoserver/echo)xxx\\\"\" diff --git a/tests/unit/unittest/unsavedfilestest.cpp b/tests/unit/unittest/unsavedfilestest.cpp new file mode 100644 index 0000000000..0b843c6011 --- /dev/null +++ b/tests/unit/unittest/unsavedfilestest.cpp @@ -0,0 +1,154 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gmock/gmock.h" +#include "gtest-qt-printing.h" + +#include +#include + +#include + +using ClangBackEnd::UnsavedFiles; +using ClangBackEnd::FileContainer; + +using ::testing::IsNull; +using ::testing::NotNull; +using ::testing::Gt; + +namespace { + +bool operator==(const ClangBackEnd::FileContainer &fileContainer, const CXUnsavedFile &cxUnsavedFile) +{ + return fileContainer.filePath() == Utf8String::fromUtf8(cxUnsavedFile.Filename) + && fileContainer.unsavedFileContent() == Utf8String(cxUnsavedFile.Contents, cxUnsavedFile.Length); +} + +bool fileContainersContainsItemMatchingToCxUnsavedFile(const QVector &fileContainers, const CXUnsavedFile &cxUnsavedFile) +{ + for (const FileContainer &fileContainer : fileContainers) + if (fileContainer == cxUnsavedFile) + return true; + + return false; +} + +MATCHER_P(HasUnsavedFiles, fileContainers, "") +{ + ClangBackEnd::UnsavedFiles unsavedFiles = arg; + if (unsavedFiles.count() != fileContainers.size()) { + *result_listener << "unsaved count is " << unsavedFiles.count() << " and not " << fileContainers.size(); + return false; + } + + for (const CXUnsavedFile &cxUnsavedFile : unsavedFiles.cxUnsavedFileVector()) { + if (!fileContainersContainsItemMatchingToCxUnsavedFile(fileContainers, cxUnsavedFile)) + return false; + } + + return true; +} + +class UnsavedFiles : public ::testing::Test +{ +protected: + void TearDown() override; + +protected: + ::UnsavedFiles unsavedFiles; +}; + +void UnsavedFiles::TearDown() +{ + unsavedFiles.clear(); +} + +TEST_F(UnsavedFiles, DoNothingForUpdateIfFileHasNoUnsavedContent) +{ + QVector fileContainers({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"))}); + + unsavedFiles.createOrUpdate(fileContainers); + + ASSERT_THAT(unsavedFiles, HasUnsavedFiles(QVector())); +} + +TEST_F(UnsavedFiles, AddUnsavedFileForUpdateWithUnsavedContent) +{ + QVector fileContainers({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro")), + FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo"), true)}); + unsavedFiles.createOrUpdate(fileContainers); + + ASSERT_THAT(unsavedFiles, HasUnsavedFiles(QVector({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo"), true)}))); +} + +TEST_F(UnsavedFiles, RemoveUnsavedFileForUpdateWithUnsavedContent) +{ + QVector fileContainers({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo"), true), + FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"))}); + + unsavedFiles.createOrUpdate(fileContainers); + + ASSERT_THAT(unsavedFiles, HasUnsavedFiles(QVector())); +} + +TEST_F(UnsavedFiles, ExchangeUnsavedFileForUpdateWithUnsavedContent) +{ + QVector fileContainers({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo"), true), + FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo2"), true)}); + unsavedFiles.createOrUpdate(fileContainers); + + ASSERT_THAT(unsavedFiles, HasUnsavedFiles(QVector({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo2"), true)}))); +} + +TEST_F(UnsavedFiles, TimeStampIsUpdatedAsUnsavedFilesChanged) +{ + QVector fileContainers({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo"), true), + FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo2"), true)}); + auto lastChangeTimePoint = unsavedFiles.lastChangeTimePoint(); + + unsavedFiles.createOrUpdate(fileContainers); + + ASSERT_THAT(unsavedFiles.lastChangeTimePoint(), Gt(lastChangeTimePoint)); +} + +TEST_F(UnsavedFiles, RemoveUnsavedFiles) +{ + QVector fileContainers({FileContainer(Utf8StringLiteral("file.cpp"), Utf8StringLiteral("pathToProject.pro"), Utf8StringLiteral("foo"), true)}); + unsavedFiles.createOrUpdate(fileContainers); + + unsavedFiles.remove(fileContainers); + + ASSERT_THAT(unsavedFiles, HasUnsavedFiles(QVector())); +} +} + + diff --git a/tests/unit/unittest/utf8test.cpp b/tests/unit/unittest/utf8test.cpp new file mode 100644 index 0000000000..db4dcb0e81 --- /dev/null +++ b/tests/unit/unittest/utf8test.cpp @@ -0,0 +1,273 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock-matchers.h" +#include "gtest-qt-printing.h" + +#include + +#include + +using namespace ::testing; + +TEST(Utf8, QStringConversionConstructor) +{ + ASSERT_THAT(Utf8String(QStringLiteral("text")), Utf8StringLiteral("text")); +} + +TEST(Utf8, QByteArrayConversionFunction) +{ + ASSERT_THAT(Utf8String::fromByteArray("text"), Utf8StringLiteral("text")); +} + +TEST(Utf8, QStringConversionFunction) +{ + ASSERT_THAT(Utf8String::fromString(QStringLiteral("text")), Utf8StringLiteral("text")); +} + +TEST(Utf8, Utf8ConversationFunction) +{ + ASSERT_THAT(Utf8String::fromUtf8("text"), Utf8StringLiteral("text")); +} + +TEST(Utf8, Mid) +{ + Utf8String text(Utf8StringLiteral("some text")); + + ASSERT_THAT(text.mid(5, 4), Utf8StringLiteral("text")); + ASSERT_THAT(text.mid(5), Utf8StringLiteral("text")); +} + +TEST(Utf8, ByteSize) +{ + ASSERT_THAT(Utf8StringLiteral("text").byteSize(), 4); +} + +TEST(Utf8, Append) +{ + Utf8String text(Utf8StringLiteral("some ")); + text.append(Utf8StringLiteral("text")); + + ASSERT_THAT(text, Utf8StringLiteral("some text")); +} + +TEST(Utf8, ToByteArray) +{ + Utf8String text(Utf8StringLiteral("some text")); + + ASSERT_THAT(text.toByteArray(), QByteArrayLiteral("some text")); +} + +TEST(Utf8, ToString) +{ + Utf8String text(Utf8StringLiteral("some text")); + + ASSERT_THAT(text.toString(), QStringLiteral("some text")); +} + + +TEST(Utf8, Contains) +{ + Utf8String text(Utf8StringLiteral("some text")); + + ASSERT_TRUE(text.contains(Utf8StringLiteral("text"))); + ASSERT_TRUE(text.contains("text")); + ASSERT_TRUE(text.contains('x')); +} + +TEST(Utf8, EqualOperator) +{ + ASSERT_TRUE(Utf8StringLiteral("text") == Utf8StringLiteral("text")); + ASSERT_FALSE(Utf8StringLiteral("text") == Utf8StringLiteral("text2")); +} + +TEST(Utf8, SmallerOperator) +{ + ASSERT_TRUE(Utf8StringLiteral("some") < Utf8StringLiteral("text")); + ASSERT_TRUE(Utf8StringLiteral("text") < Utf8StringLiteral("texta")); + ASSERT_FALSE(Utf8StringLiteral("text") < Utf8StringLiteral("some")); + ASSERT_FALSE(Utf8StringLiteral("text") < Utf8StringLiteral("text")); +} + +TEST(Utf8, UnequalOperator) +{ + ASSERT_FALSE(Utf8StringLiteral("text") != Utf8StringLiteral("text")); + ASSERT_TRUE(Utf8StringLiteral("text") != Utf8StringLiteral("text2")); +} + +TEST(Utf8, Join) +{ + Utf8StringVector vector; + + vector.append(Utf8StringLiteral("some")); + vector.append(Utf8StringLiteral("text")); + + ASSERT_THAT(Utf8StringLiteral("some, text"), vector.join(Utf8StringLiteral(", "))); +} + +TEST(Utf8, Split) +{ + Utf8String test(Utf8StringLiteral("some text")); + + Utf8StringVector splittedText = test.split(' '); + + ASSERT_THAT(splittedText.at(0), Utf8StringLiteral("some")); + ASSERT_THAT(splittedText.at(1), Utf8StringLiteral("text")); +} + +TEST(Utf8, IsEmpty) +{ + ASSERT_FALSE(Utf8StringLiteral("text").isEmpty()); + ASSERT_TRUE(Utf8String().isEmpty()); +} + +TEST(Utf8, HasContent) +{ + ASSERT_TRUE(Utf8StringLiteral("text").hasContent()); + ASSERT_FALSE(Utf8String().hasContent()); +} + +TEST(Utf8, Replace) +{ + Utf8String text(Utf8StringLiteral("some text")); + + text.replace(Utf8StringLiteral("some"), Utf8StringLiteral("any")); + + ASSERT_THAT(text, Utf8StringLiteral("any text")); +} + +TEST(Utf8, StartsWith) +{ + Utf8String text(Utf8StringLiteral("$column")); + + ASSERT_TRUE(text.startsWith(Utf8StringLiteral("$col"))); + ASSERT_FALSE(text.startsWith(Utf8StringLiteral("col"))); + ASSERT_TRUE(text.startsWith("$col")); + ASSERT_FALSE(text.startsWith("col")); + ASSERT_TRUE(text.startsWith('$')); + ASSERT_FALSE(text.startsWith('@')); +} + +TEST(Utf8, Clear) +{ + Utf8String text(Utf8StringLiteral("$column")); + + text.clear(); + + ASSERT_TRUE(text.isEmpty()); +} + +TEST(Utf8, Number) +{ + ASSERT_THAT(Utf8String::number(20), Utf8StringLiteral("20")); +} + +TEST(Utf8, FromIntegerVector) +{ + QVector integers({1, 2, 3}); + + ASSERT_THAT(Utf8StringVector::fromIntegerVector(integers).join(Utf8StringLiteral(", ")), Utf8StringLiteral("1, 2, 3")); +} + +TEST(Utf8, PlusOperator) +{ + auto text = Utf8StringLiteral("foo") + Utf8StringLiteral("bar"); + + ASSERT_THAT(text, Utf8StringLiteral("foobar")); +} + +TEST(Utf8, PlusAssignmentOperator) +{ + Utf8String text("foo", 3); + + text += Utf8StringLiteral("bar"); + + ASSERT_THAT(text, Utf8StringLiteral("foobar")); +} + +TEST(Utf8, CompareCharPointer) +{ + Utf8String text("foo", 3); + + ASSERT_TRUE(text == "foo"); + ASSERT_FALSE(text == "foo2"); +} + +TEST(Utf8, RemoveFastFromVectorFailed) +{ + Utf8StringVector values({Utf8StringLiteral("a"), + Utf8StringLiteral("b"), + Utf8StringLiteral("c"), + Utf8StringLiteral("d")}); + + ASSERT_FALSE(values.removeFast(Utf8StringLiteral("e"))); +} + +TEST(Utf8, RemoveFastFromVector) +{ + Utf8StringVector values({Utf8StringLiteral("a"), + Utf8StringLiteral("b"), + Utf8StringLiteral("c"), + Utf8StringLiteral("d")}); + + bool removed = values.removeFast(Utf8StringLiteral("b")); + + ASSERT_TRUE(removed); + ASSERT_THAT(values, Not(Contains(Utf8StringLiteral("b")))); +} + +TEST(Utf8, ConverteAutomaticallyFromQString) +{ + QString text(QStringLiteral("foo")); + + Utf8String utf8Text(text); + + ASSERT_THAT(utf8Text, Utf8StringLiteral("foo")); +} + +TEST(Utf8, ConverteAutomaticallyToQString) +{ + Utf8String utf8Text(Utf8StringLiteral("foo")); + + QString text = utf8Text; + + ASSERT_THAT(text, QStringLiteral("foo")); +} + +TEST(Utf8, ConverteAutomaticallyToQByteArray) +{ + Utf8String utf8Text(Utf8StringLiteral("foo")); + + QByteArray bytes = utf8Text; + + ASSERT_THAT(bytes, QByteArrayLiteral("foo")); +} + -- cgit v1.2.1