diff --git a/src/app/qt/view/graphElements/QtGraphNodeData.cpp b/src/app/qt/view/graphElements/QtGraphNodeData.cpp index 2ba3c873..06220e25 100644 --- a/src/app/qt/view/graphElements/QtGraphNodeData.cpp +++ b/src/app/qt/view/graphElements/QtGraphNodeData.cpp @@ -5,6 +5,8 @@ #include "utility/messaging/type/MessageFocusOut.h" #include "utility/messaging/type/MessageGraphNodeMove.h" +#include "data/graph/token_component/TokenComponentSignature.h" + QtGraphNodeData::QtGraphNodeData(const Node* data, bool hasParent, bool childVisible) : m_data(data) , m_childVisible(childVisible) @@ -26,6 +28,15 @@ QtGraphNodeData::QtGraphNodeData(const Node* data, bool hasParent, bool childVis toolTip = "undefined " + toolTip; } + if (data->isType(Node::NODE_FUNCTION | Node::NODE_METHOD)) + { + TokenComponentSignature* sig = data->getComponent(); + if (sig) + { + toolTip += ": " + sig->getSignature(); + } + } + this->setToolTip(QString::fromStdString(toolTip)); } diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 4bc5273e..9c9e505b 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -126,6 +126,8 @@ add_files( data/graph/token_component/TokenComponentConst.h data/graph/token_component/TokenComponentFilePath.cpp data/graph/token_component/TokenComponentFilePath.h + data/graph/token_component/TokenComponentSignature.cpp + data/graph/token_component/TokenComponentSignature.h data/graph/token_component/TokenComponentStatic.cpp data/graph/token_component/TokenComponentStatic.h diff --git a/src/lib/data/SqliteStorage.cpp b/src/lib/data/SqliteStorage.cpp index 914188c9..731ee8d5 100644 --- a/src/lib/data/SqliteStorage.cpp +++ b/src/lib/data/SqliteStorage.cpp @@ -606,7 +606,7 @@ NameHierarchy SqliteStorage::getNameHierarchyById(const Id id) const StorageSourceLocation SqliteStorage::getSourceLocationByData(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, bool isScope) const { return getFirstSourceLocation(( - "SELECT * FROM source_location WHERE element_id == " + std::to_string(elementId) + "SELECT * FROM source_location WHERE element_id == " + std::to_string(elementId) + " AND file_node_id == " + std::to_string(fileNodeId) + " AND start_line == " + std::to_string(startLine) + " AND start_column == " + std::to_string(startCol) @@ -752,6 +752,20 @@ Id SqliteStorage::getNodeIdBySignature(const std::string& signature) const return 0; } +std::string SqliteStorage::getSignatureByNodeId(Id nodeId) const +{ + CppSQLite3Query q = m_database.execQuery(( + "SELECT id, signature FROM function_signature WHERE id == " + std::to_string(nodeId) + ";" + ).c_str()); + + while (!q.eof()) + { + return q.getStringField(1, ""); + } + + return 0; +} + std::vector SqliteStorage::getCommentLocationsInFile(const FilePath& filePath) const { Id fileNodeId = getFileByPath(filePath.str()).id; diff --git a/src/lib/data/SqliteStorage.h b/src/lib/data/SqliteStorage.h index d55be866..18b65661 100644 --- a/src/lib/data/SqliteStorage.h +++ b/src/lib/data/SqliteStorage.h @@ -107,6 +107,7 @@ public: StorageComponentAccess getComponentAccessByMemberEdgeId(Id memberEdgeId) const; std::vector getComponentAccessByMemberEdgeIds(const std::vector& memberEdgeIds) const; Id getNodeIdBySignature(const std::string& signature) const; + std::string getSignatureByNodeId(Id nodeId) const; std::vector getCommentLocationsInFile(const FilePath& filePath) const; std::vector getAllErrors() const; diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index b454d514..02a77e0c 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -10,6 +10,7 @@ #include "utility/utilityString.h" #include "data/graph/token_component/TokenComponentAggregation.h" +#include "data/graph/token_component/TokenComponentSignature.h" #include "data/graph/Graph.h" #include "data/location/TokenLocation.h" #include "data/location/TokenLocationFile.h" @@ -1258,11 +1259,11 @@ std::shared_ptr Storage::getCommentLocationsInFile(const File for (size_t i = 0; i < storageLocations.size(); i++) { TokenLocation* loc = file->addTokenLocation( - storageLocations[i].id, + storageLocations[i].id, 0, // comment token location has no element. - storageLocations[i].startLine, - storageLocations[i].startCol, - storageLocations[i].endLine, + storageLocations[i].startLine, + storageLocations[i].startCol, + storageLocations[i].endLine, storageLocations[i].endCol ); } @@ -1612,12 +1613,20 @@ void Storage::addNodesToGraph(const std::vector nodeIds, Graph* graph) const for (const StorageNode& storageNode : storageNodes) { - graph->createNode( + Node::NodeType type = Node::intToType(storageNode.type); + Node* node = graph->createNode( storageNode.id, - Node::intToType(storageNode.type), + type, m_tokenIndex.getNameHierarchyForTokenId(storageNode.id), storageNode.defined ); + + if (type == Node::NODE_FUNCTION || type == Node::NODE_METHOD) + { + node->addComponentSignature( + std::make_shared(m_sqliteStorage.getSignatureByNodeId(storageNode.id)) + ); + } } } diff --git a/src/lib/data/graph/Node.cpp b/src/lib/data/graph/Node.cpp index 54d9f3c4..e05ca9cc 100644 --- a/src/lib/data/graph/Node.cpp +++ b/src/lib/data/graph/Node.cpp @@ -8,6 +8,7 @@ #include "data/graph/token_component/TokenComponentConst.h" #include "data/graph/token_component/TokenComponentStatic.h" #include "data/graph/token_component/TokenComponentFilePath.h" +#include "data/graph/token_component/TokenComponentSignature.h" const Node::NodeTypeMask Node::NODE_NOT_VISIBLE = Node::NODE_UNDEFINED | Node::NODE_NAMESPACE; @@ -395,6 +396,23 @@ void Node::addComponentFilePath(std::shared_ptr componen } } +void Node::addComponentSignature(std::shared_ptr component) +{ + if (getComponent()) + { + LOG_ERROR("TokenComponentSignature has been set before!"); + return; + } + else if (!isType(NODE_FUNCTION | NODE_METHOD)) + { + LOG_ERROR("TokenComponentFilePath can't be set on node of type: " + getTypeString()); + } + else + { + addComponent(component); + } +} + std::string Node::getTypeString() const { return getTypeString(m_type); diff --git a/src/lib/data/graph/Node.h b/src/lib/data/graph/Node.h index 76c8fe1a..dba291c0 100644 --- a/src/lib/data/graph/Node.h +++ b/src/lib/data/graph/Node.h @@ -14,6 +14,7 @@ class TokenComponentAbstraction; class TokenComponentConst; class TokenComponentStatic; class TokenComponentFilePath; +class TokenComponentSignature; class Node : public Token @@ -91,6 +92,7 @@ public: void addComponentConst(std::shared_ptr component); void addComponentStatic(std::shared_ptr component); void addComponentFilePath(std::shared_ptr component); + void addComponentSignature(std::shared_ptr component); // Logging. virtual std::string getTypeString() const; diff --git a/src/lib/data/graph/token_component/TokenComponentSignature.cpp b/src/lib/data/graph/token_component/TokenComponentSignature.cpp new file mode 100644 index 00000000..25e7273f --- /dev/null +++ b/src/lib/data/graph/token_component/TokenComponentSignature.cpp @@ -0,0 +1,20 @@ +#include "data/graph/token_component/TokenComponentSignature.h" + +TokenComponentSignature::TokenComponentSignature(const std::string& signature) + : m_signature(signature) +{ +} + +TokenComponentSignature::~TokenComponentSignature() +{ +} + +std::shared_ptr TokenComponentSignature::copy() const +{ + return std::make_shared(*this); +} + +const std::string& TokenComponentSignature::getSignature() const +{ + return m_signature; +} diff --git a/src/lib/data/graph/token_component/TokenComponentSignature.h b/src/lib/data/graph/token_component/TokenComponentSignature.h new file mode 100644 index 00000000..e767854c --- /dev/null +++ b/src/lib/data/graph/token_component/TokenComponentSignature.h @@ -0,0 +1,23 @@ +#ifndef TOKEN_COMPONENT_SIGNATURE_H +#define TOKEN_COMPONENT_SIGNATURE_H + +#include + +#include "data/graph/token_component/TokenComponent.h" + +class TokenComponentSignature + : public TokenComponent +{ +public: + TokenComponentSignature(const std::string& signature); + virtual ~TokenComponentSignature(); + + virtual std::shared_ptr copy() const; + + const std::string& getSignature() const; + +private: + const std::string m_signature; +}; + +#endif // TOKEN_COMPONENT_SIGNATURE_H