logic: removed namespace splitting from GraphController
Namespace splitting is now handled in active token id retrieval from the Storage, so that namespace nodes are not added to the Graph at all and complexity in the GraphController is reduced.
This commit is contained in:
@@ -54,6 +54,21 @@ void HierarchyCache::HierarchyNode::addChildIdsRecursive(std::vector<Id>* nodeId
|
||||
}
|
||||
}
|
||||
|
||||
void HierarchyCache::HierarchyNode::addVisibleNodeIdsRecursive(std::vector<Id>* nodeIds) const
|
||||
{
|
||||
if (isVisible())
|
||||
{
|
||||
nodeIds->push_back(getNodeId());
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const HierarchyNode* child : m_children)
|
||||
{
|
||||
child->addVisibleNodeIdsRecursive(nodeIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool HierarchyCache::HierarchyNode::isVisible() const
|
||||
{
|
||||
return m_isVisible;
|
||||
@@ -65,7 +80,6 @@ void HierarchyCache::HierarchyNode::setIsVisible(bool isVisible)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HierarchyCache::clear()
|
||||
{
|
||||
m_nodes.clear();
|
||||
@@ -108,6 +122,19 @@ void HierarchyCache::addAllChildIdsForNodeId(Id nodeId, std::vector<Id>* nodeIds
|
||||
}
|
||||
}
|
||||
|
||||
void HierarchyCache::addFirstVisibleChildIdsForNodeId(Id nodeId, std::vector<Id>* nodeIds) const
|
||||
{
|
||||
HierarchyNode* node = getNode(nodeId);
|
||||
if (node)
|
||||
{
|
||||
node->addVisibleNodeIdsRecursive(nodeIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeIds->push_back(nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
HierarchyCache::HierarchyNode* HierarchyCache::getNode(Id nodeId) const
|
||||
{
|
||||
std::map<Id, std::shared_ptr<HierarchyNode>>::const_iterator it = m_nodes.find(nodeId);
|
||||
|
||||
@@ -15,7 +15,9 @@ public:
|
||||
void createConnection(Id edgeId, Id fromId, Id toId, bool fromVisible);
|
||||
|
||||
Id getLastVisibleParentNodeId(Id nodeId) const;
|
||||
|
||||
void addAllChildIdsForNodeId(Id nodeId, std::vector<Id>* nodeIds, std::vector<Id>* edgeIds) const;
|
||||
void addFirstVisibleChildIdsForNodeId(Id nodeId, std::vector<Id>* nodeIds) const;
|
||||
|
||||
private:
|
||||
class HierarchyNode
|
||||
@@ -33,7 +35,9 @@ private:
|
||||
|
||||
void addChild(HierarchyNode* child);
|
||||
const std::vector<HierarchyNode*>& getChildren() const;
|
||||
|
||||
void addChildIdsRecursive(std::vector<Id>* nodeIds, std::vector<Id>* edgeIds) const;
|
||||
void addVisibleNodeIdsRecursive(std::vector<Id>* nodeIds) const;
|
||||
|
||||
bool isVisible() const;
|
||||
void setIsVisible(bool isVisible);
|
||||
|
||||
@@ -824,6 +824,25 @@ std::shared_ptr<Graph> Storage::getGraphForActiveTokenIds(const std::vector<Id>&
|
||||
return g;
|
||||
}
|
||||
|
||||
std::vector<Id> Storage::getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
std::vector<Id> activeIds;
|
||||
|
||||
for (Id id : tokenIds)
|
||||
{
|
||||
if (m_sqliteStorage.isNode(id))
|
||||
{
|
||||
m_hierarchyCache.addFirstVisibleChildIdsForNodeId(id, &activeIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
activeIds.push_back(id);
|
||||
}
|
||||
}
|
||||
|
||||
return activeIds;
|
||||
}
|
||||
|
||||
// TODO: rename: getActiveElementIdsForId; TODO: make separate function for declarationId
|
||||
std::vector<Id> Storage::getActiveTokenIdsForId(Id tokenId, Id* declarationId) const
|
||||
{
|
||||
@@ -849,16 +868,26 @@ std::vector<Id> Storage::getActiveTokenIdsForId(Id tokenId, Id* declarationId) c
|
||||
return activeTokenIds;
|
||||
}
|
||||
|
||||
Id Storage::getActiveNodeIdForLocationId(Id locationId) const
|
||||
std::vector<Id> Storage::getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const
|
||||
{
|
||||
Id activeElementId = m_sqliteStorage.getElementIdByLocationId(locationId);
|
||||
std::vector<Id> nodeIds;
|
||||
|
||||
StorageEdge edge = m_sqliteStorage.getEdgeById(activeElementId);
|
||||
if (edge.id != 0) // here we test if location is an edge.
|
||||
for (Id locationId : locationIds)
|
||||
{
|
||||
activeElementId = edge.targetNodeId;
|
||||
Id elementId = m_sqliteStorage.getElementIdByLocationId(locationId);
|
||||
|
||||
StorageEdge edge = m_sqliteStorage.getEdgeById(elementId);
|
||||
if (edge.id != 0) // here we test if location is an edge.
|
||||
{
|
||||
nodeIds.push_back(edge.targetNodeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeIds.push_back(elementId);
|
||||
}
|
||||
}
|
||||
return activeElementId;
|
||||
|
||||
return nodeIds;
|
||||
}
|
||||
|
||||
std::vector<Id> Storage::getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const
|
||||
|
||||
@@ -132,8 +132,10 @@ public:
|
||||
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
|
||||
virtual Id getActiveNodeIdForLocationId(Id locationId) const;
|
||||
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
|
||||
virtual std::vector<Id> getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const;
|
||||
virtual Id getTokenIdForFileNode(const FilePath& filePath) const;
|
||||
|
||||
@@ -34,8 +34,10 @@ public:
|
||||
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const = 0;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const = 0;
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const = 0;
|
||||
virtual Id getActiveNodeIdForLocationId(Id locationId) const = 0;
|
||||
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const = 0;
|
||||
|
||||
virtual std::vector<Id> getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const = 0;
|
||||
virtual Id getTokenIdForFileNode(const FilePath& filePath) const = 0;
|
||||
|
||||
@@ -103,6 +103,16 @@ std::shared_ptr<Graph> StorageAccessProxy::getGraphForActiveTokenIds(const std::
|
||||
return std::make_shared<Graph>();
|
||||
}
|
||||
|
||||
std::vector<Id> StorageAccessProxy::getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getActiveTokenIdsForTokenIds(tokenIds);
|
||||
}
|
||||
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::vector<Id> StorageAccessProxy::getActiveTokenIdsForId(Id tokenId, Id* delcarationId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
@@ -113,14 +123,14 @@ std::vector<Id> StorageAccessProxy::getActiveTokenIdsForId(Id tokenId, Id* delca
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
Id StorageAccessProxy::getActiveNodeIdForLocationId(Id locationId) const
|
||||
std::vector<Id> StorageAccessProxy::getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getActiveNodeIdForLocationId(locationId);
|
||||
return m_subject->getNodeIdsForLocationIds(locationIds);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::vector<Id> StorageAccessProxy::getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const
|
||||
|
||||
@@ -25,8 +25,10 @@ public:
|
||||
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
|
||||
virtual Id getActiveNodeIdForLocationId(Id locationId) const;
|
||||
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
|
||||
virtual std::vector<Id> getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const;
|
||||
virtual Id getTokenIdForFileNode(const FilePath& filePath) const;
|
||||
|
||||
Reference in New Issue
Block a user