logic: added "serialize" method for indexer commands
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
#include "data/indexer/IndexerCommand.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
std::wstring IndexerCommand::serialize(std::shared_ptr<const IndexerCommand> indexerCommand, bool compact)
|
||||
{
|
||||
QJsonDocument jsonDocument(indexerCommand->doSerialize());
|
||||
return QString::fromUtf8(jsonDocument.toJson(compact ? QJsonDocument::Compact : QJsonDocument::Indented)).toStdWString();
|
||||
}
|
||||
|
||||
IndexerCommand::IndexerCommand(
|
||||
const FilePath& sourceFilePath
|
||||
)
|
||||
@@ -18,3 +27,17 @@ const FilePath& IndexerCommand::getSourceFilePath() const
|
||||
{
|
||||
return m_sourceFilePath;
|
||||
}
|
||||
|
||||
QJsonObject IndexerCommand::doSerialize() const
|
||||
{
|
||||
QJsonObject jsonObject;
|
||||
|
||||
{
|
||||
jsonObject["type"] = QString::fromStdString(indexerCommandTypeToString(getIndexerCommandType()));
|
||||
}
|
||||
{
|
||||
jsonObject["source_file_path"] = QString::fromStdWString(m_sourceFilePath.wstr());
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,13 @@
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/file/FilePathFilter.h"
|
||||
|
||||
class QJsonObject;
|
||||
|
||||
class IndexerCommand
|
||||
{
|
||||
public:
|
||||
static std::wstring serialize(std::shared_ptr<const IndexerCommand> indexerCommand, bool compact = true);
|
||||
|
||||
IndexerCommand(const FilePath& sourceFilePath);
|
||||
virtual ~IndexerCommand() = default;
|
||||
|
||||
@@ -20,6 +24,9 @@ public:
|
||||
|
||||
const FilePath& getSourceFilePath() const;
|
||||
|
||||
protected:
|
||||
virtual QJsonObject doSerialize() const;
|
||||
|
||||
private:
|
||||
FilePath m_sourceFilePath;
|
||||
};
|
||||
|
||||
@@ -5,13 +5,22 @@ std::string indexerCommandTypeToString(IndexerCommandType type)
|
||||
switch(type)
|
||||
{
|
||||
case INDEXER_COMMAND_CXX_EMPTY:
|
||||
return "indexer command cxx empty";
|
||||
return "indexer_command_cxx_empty";
|
||||
case INDEXER_COMMAND_CXX_CDB:
|
||||
return "indexer command cxx cdb";
|
||||
return "indexer_command_cxx_cdb";
|
||||
case INDEXER_COMMAND_JAVA:
|
||||
return "indexer command java";
|
||||
return "indexer_command_java";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "indexer command unknown";
|
||||
return "indexer_command_unknown";
|
||||
}
|
||||
|
||||
IndexerCommandType stringToIndexerCommandType(const std::string& s)
|
||||
{
|
||||
if (s == indexerCommandTypeToString(INDEXER_COMMAND_CXX_EMPTY)) return INDEXER_COMMAND_CXX_EMPTY;
|
||||
if (s == indexerCommandTypeToString(INDEXER_COMMAND_CXX_CDB)) return INDEXER_COMMAND_CXX_CDB;
|
||||
if (s == indexerCommandTypeToString(INDEXER_COMMAND_JAVA)) return INDEXER_COMMAND_JAVA;
|
||||
return INDEXER_COMMAND_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,5 +12,6 @@ enum IndexerCommandType
|
||||
};
|
||||
|
||||
std::string indexerCommandTypeToString(IndexerCommandType type);
|
||||
IndexerCommandType stringToIndexerCommandType(const std::string& s);
|
||||
|
||||
#endif // INDEXER_COMMAND_TYPE_H
|
||||
|
||||
@@ -15,10 +15,6 @@ InterprocessIndexer::InterprocessIndexer(const std::string& uuid, Id processId)
|
||||
{
|
||||
}
|
||||
|
||||
InterprocessIndexer::~InterprocessIndexer()
|
||||
{
|
||||
}
|
||||
|
||||
void InterprocessIndexer::work()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -9,7 +9,6 @@ class InterprocessIndexer
|
||||
{
|
||||
public:
|
||||
InterprocessIndexer(const std::string& uuid, Id processId);
|
||||
~InterprocessIndexer();
|
||||
|
||||
void work();
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "data/indexer/IndexerCommandCxx.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
IndexerCommandCxx::IndexerCommandCxx(
|
||||
@@ -94,3 +97,62 @@ const FilePath& IndexerCommandCxx::getWorkingDirectory() const
|
||||
{
|
||||
return m_workingDirectory;
|
||||
}
|
||||
|
||||
QJsonObject IndexerCommandCxx::doSerialize() const
|
||||
{
|
||||
QJsonObject jsonObject = IndexerCommand::doSerialize();
|
||||
|
||||
{
|
||||
QJsonArray indexedPathsArray;
|
||||
for (const FilePath& indexedPath : m_indexedPaths)
|
||||
{
|
||||
indexedPathsArray.append(QString::fromStdWString(indexedPath.wstr()));
|
||||
}
|
||||
jsonObject["indexed_paths"] = indexedPathsArray;
|
||||
}
|
||||
{
|
||||
QJsonArray excludeFiltersArray;
|
||||
for (const FilePathFilter& excludeFilter : m_excludeFilters)
|
||||
{
|
||||
excludeFiltersArray.append(QString::fromStdWString(excludeFilter.wstr()));
|
||||
}
|
||||
jsonObject["exclude_filters"] = excludeFiltersArray;
|
||||
}
|
||||
{
|
||||
QJsonArray includeFiltersArray;
|
||||
for (const FilePathFilter& includeFilter : m_includeFilters)
|
||||
{
|
||||
includeFiltersArray.append(QString::fromStdWString(includeFilter.wstr()));
|
||||
}
|
||||
jsonObject["include_filters"] = includeFiltersArray;
|
||||
}
|
||||
{
|
||||
jsonObject["working_directory"] = QString::fromStdWString(getWorkingDirectory().wstr());
|
||||
}
|
||||
{
|
||||
QJsonArray systemHeaderSearchPathsArray;
|
||||
for (const FilePath& systemHeaderSearchPath : m_systemHeaderSearchPaths)
|
||||
{
|
||||
systemHeaderSearchPathsArray.append(QString::fromStdWString(systemHeaderSearchPath.wstr()));
|
||||
}
|
||||
jsonObject["system_header_search_paths"] = systemHeaderSearchPathsArray;
|
||||
}
|
||||
{
|
||||
QJsonArray frameworkSearchPathsArray;
|
||||
for (const FilePath& frameworkSearchPath : m_frameworkSearchPaths)
|
||||
{
|
||||
frameworkSearchPathsArray.append(QString::fromStdWString(frameworkSearchPath.wstr()));
|
||||
}
|
||||
jsonObject["framework_search_paths"] = frameworkSearchPathsArray;
|
||||
}
|
||||
{
|
||||
QJsonArray compilerFlagsArray;
|
||||
for (const std::wstring& compilerFlag : m_compilerFlags)
|
||||
{
|
||||
compilerFlagsArray.append(QString::fromStdWString(compilerFlag));
|
||||
}
|
||||
jsonObject["compiler_flags"] = compilerFlagsArray;
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ public:
|
||||
const std::vector<std::wstring>& getCompilerFlags() const;
|
||||
const FilePath& getWorkingDirectory() const;
|
||||
|
||||
protected:
|
||||
QJsonObject doSerialize() const override;
|
||||
|
||||
private:
|
||||
std::set<FilePath> m_indexedPaths;
|
||||
std::set<FilePathFilter> m_excludeFilters;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "data/indexer/IndexerCommandCxxEmpty.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
|
||||
IndexerCommandType IndexerCommandCxxEmpty::getStaticIndexerCommandType()
|
||||
{
|
||||
return INDEXER_COMMAND_CXX_EMPTY;
|
||||
@@ -35,3 +37,14 @@ std::string IndexerCommandCxxEmpty::getLanguageStandard() const
|
||||
{
|
||||
return m_languageStandard;
|
||||
}
|
||||
|
||||
QJsonObject IndexerCommandCxxEmpty::doSerialize() const
|
||||
{
|
||||
QJsonObject jsonObject = IndexerCommandCxx::doSerialize();
|
||||
|
||||
{
|
||||
jsonObject["language_standard"] = QString::fromStdString(m_languageStandard);
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ public:
|
||||
|
||||
std::string getLanguageStandard() const;
|
||||
|
||||
protected:
|
||||
QJsonObject doSerialize() const override;
|
||||
|
||||
private:
|
||||
std::string m_languageStandard;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "data/indexer/IndexerCommandJava.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
IndexerCommandType IndexerCommandJava::getStaticIndexerCommandType()
|
||||
@@ -49,3 +52,22 @@ std::vector<FilePath> IndexerCommandJava::getClassPath() const
|
||||
{
|
||||
return m_classPath;
|
||||
}
|
||||
|
||||
QJsonObject IndexerCommandJava::doSerialize() const
|
||||
{
|
||||
QJsonObject jsonObject = IndexerCommand::doSerialize();
|
||||
|
||||
{
|
||||
QJsonArray classPathArray;
|
||||
for (const FilePath& classPath : m_classPath)
|
||||
{
|
||||
classPathArray.append(QString::fromStdWString(classPath.wstr()));
|
||||
}
|
||||
jsonObject["class_path"] = classPathArray;
|
||||
}
|
||||
{
|
||||
jsonObject["language_standard"] = QString::fromStdString(m_languageStandard);
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ public:
|
||||
void setClassPath(std::vector<FilePath> classPath);
|
||||
std::vector<FilePath> getClassPath() const;
|
||||
|
||||
protected:
|
||||
QJsonObject doSerialize() const override;
|
||||
|
||||
private:
|
||||
const std::string m_languageStandard;
|
||||
std::vector<FilePath> m_classPath;
|
||||
|
||||
Reference in New Issue
Block a user