logic: extended CodeView to show locations of edges to the active Token and merge overlapping snippets
This commit is contained in:
@@ -387,17 +387,62 @@ bool Storage::checkTokenIsNode(const Id id) const
|
||||
return false;
|
||||
}
|
||||
|
||||
TokenLocationCollection Storage::getTokenLocationsForTokenId(Id id) const
|
||||
std::vector<Id> Storage::getActiveTokenIdsForId(Id tokenId) const
|
||||
{
|
||||
TokenLocationCollection ret;
|
||||
|
||||
Token* token = m_graph.getTokenById(id);
|
||||
std::vector<Id> ret;
|
||||
Token* token = m_graph.getTokenById(tokenId);
|
||||
if (!token)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<Id> locationIds = token->getLocationIds();
|
||||
Node* node;
|
||||
if (token->isEdge())
|
||||
{
|
||||
node = dynamic_cast<Edge*>(token)->getTo();
|
||||
}
|
||||
else
|
||||
{
|
||||
node = dynamic_cast<Node*>(token);
|
||||
}
|
||||
|
||||
ret.push_back(node->getId());
|
||||
|
||||
node->forEachEdge(
|
||||
[&node, &ret](Edge* e)
|
||||
{
|
||||
if (e->getTo() == node)
|
||||
{
|
||||
ret.push_back(e->getId());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<Id> Storage::getLocationIdsForTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
std::vector<Id> ret;
|
||||
|
||||
for (Id tokenId : tokenIds)
|
||||
{
|
||||
Token* token = m_graph.getTokenById(tokenId);
|
||||
if (!token)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ret.insert(ret.end(), token->getLocationIds().begin(), token->getLocationIds().end());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
TokenLocationCollection Storage::getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const
|
||||
{
|
||||
TokenLocationCollection ret;
|
||||
|
||||
for (Id locationId: locationIds)
|
||||
{
|
||||
TokenLocation* location = m_locationCollection.findTokenLocationById(locationId);
|
||||
|
||||
@@ -81,8 +81,11 @@ public:
|
||||
|
||||
virtual bool checkTokenIsNode(const Id id) const;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId) const;
|
||||
virtual std::vector<Id> getLocationIdsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
|
||||
// LocationAccess implementation
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenId(Id locationId) const;
|
||||
virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
virtual TokenLocationFile getTokenLocationsForLinesInFile(
|
||||
const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber
|
||||
) const;
|
||||
|
||||
@@ -30,6 +30,9 @@ public:
|
||||
virtual std::pair<Id, Id> getNodesOfEdge(const Id id) const = 0;
|
||||
|
||||
virtual bool checkTokenIsNode(const Id id) const = 0;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId) const = 0;
|
||||
virtual std::vector<Id> getLocationIdsForTokenIds(const std::vector<Id>& tokenIds) const = 0;
|
||||
};
|
||||
|
||||
#endif // GRAPH_ACCESS_H
|
||||
|
||||
@@ -166,3 +166,23 @@ bool GraphAccessProxy::checkTokenIsNode(const Id id) const
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<Id> GraphAccessProxy::getActiveTokenIdsForId(Id tokenId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getActiveTokenIdsForId(tokenId);
|
||||
}
|
||||
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::vector<Id> GraphAccessProxy::getLocationIdsForTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getLocationIdsForTokenIds(tokenIds);
|
||||
}
|
||||
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ public:
|
||||
|
||||
virtual bool checkTokenIsNode(const Id id) const;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId) const;
|
||||
virtual std::vector<Id> getLocationIdsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
|
||||
private:
|
||||
GraphAccess* m_subject;
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define LOCATION_ACCESS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
@@ -12,7 +13,7 @@ class LocationAccess
|
||||
{
|
||||
public:
|
||||
virtual ~LocationAccess();
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenId(Id id) const = 0;
|
||||
virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const = 0;
|
||||
virtual TokenLocationFile getTokenLocationsForLinesInFile(
|
||||
const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber
|
||||
) const = 0;
|
||||
|
||||
@@ -29,11 +29,11 @@ void LocationAccessProxy::setSubject(LocationAccess* subject)
|
||||
m_subject = subject;
|
||||
}
|
||||
|
||||
TokenLocationCollection LocationAccessProxy::getTokenLocationsForTokenId(Id id) const
|
||||
TokenLocationCollection LocationAccessProxy::getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForTokenId(id);
|
||||
return m_subject->getTokenLocationsForLocationIds(locationIds);
|
||||
}
|
||||
|
||||
return TokenLocationCollection();
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
void setSubject(LocationAccess* subject);
|
||||
|
||||
// LocationAccess implementation
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenId(Id id) const;
|
||||
virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
virtual TokenLocationFile getTokenLocationsForLinesInFile(
|
||||
const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber
|
||||
) const;
|
||||
|
||||
Reference in New Issue
Block a user