data: Added getName() method to Edge
format = EdgeType:fromNode->toNode
This commit is contained in:
@@ -246,8 +246,21 @@ Id Storage::getIdForNodeWithName(const std::string& fullName) const
|
|||||||
|
|
||||||
std::string Storage::getNameForNodeWithId(Id id) const
|
std::string Storage::getNameForNodeWithId(Id id) const
|
||||||
{
|
{
|
||||||
Node* node = m_graph.getNodeById(id);
|
Token* token = m_graph.getTokenById(id);
|
||||||
return (node ? node->getFullName() : "");
|
|
||||||
|
if (!token)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (token->isEdge())
|
||||||
|
{
|
||||||
|
return dynamic_cast<Edge*>(token)->getName();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return dynamic_cast<Node*>(token)->getFullName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> Storage::getNamesForNodesWithNamePrefix(const std::string& prefix) const
|
std::vector<std::string> Storage::getNamesForNodesWithNamePrefix(const std::string& prefix) const
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ Node* Edge::getTo() const
|
|||||||
return m_to;
|
return m_to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Edge::getName() const
|
||||||
|
{
|
||||||
|
return getTypeString() + ":" + getFrom()->getFullName() + "->" + getTo()->getFullName();
|
||||||
|
}
|
||||||
|
|
||||||
bool Edge::isNode() const
|
bool Edge::isNode() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -101,21 +106,21 @@ std::string Edge::getTypeString() const
|
|||||||
switch (m_type)
|
switch (m_type)
|
||||||
{
|
{
|
||||||
case EDGE_MEMBER:
|
case EDGE_MEMBER:
|
||||||
return "has child";
|
return "child";
|
||||||
case EDGE_TYPE_OF:
|
case EDGE_TYPE_OF:
|
||||||
return "is type of";
|
return "type use";
|
||||||
case EDGE_RETURN_TYPE_OF:
|
case EDGE_RETURN_TYPE_OF:
|
||||||
return "has return type";
|
return "return type";
|
||||||
case EDGE_PARAMETER_TYPE_OF:
|
case EDGE_PARAMETER_TYPE_OF:
|
||||||
return "has parameter of type";
|
return "parameter type";
|
||||||
case EDGE_INHERITANCE:
|
case EDGE_INHERITANCE:
|
||||||
return "is derived from";
|
return "inheritance";
|
||||||
case EDGE_CALL:
|
case EDGE_CALL:
|
||||||
return "calls";
|
return "call";
|
||||||
case EDGE_USAGE:
|
case EDGE_USAGE:
|
||||||
return "uses";
|
return "usage";
|
||||||
case EDGE_TYPEDEF_OF:
|
case EDGE_TYPEDEF_OF:
|
||||||
return "is typedef of";
|
return "typedef";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -123,7 +128,7 @@ std::string Edge::getTypeString() const
|
|||||||
std::string Edge::getAsString() const
|
std::string Edge::getAsString() const
|
||||||
{
|
{
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
str << "[" << getId() << "] \"" << m_from->getName() << "\" " << getTypeString() << " \"" + m_to->getName() << "\"";
|
str << "[" << getId() << "] " << getTypeString() << ": \"" << m_from->getName() << "\" -> \"" + m_to->getName() << "\"";
|
||||||
|
|
||||||
TokenComponentAccess* component = getComponent<TokenComponentAccess>();
|
TokenComponentAccess* component = getComponent<TokenComponentAccess>();
|
||||||
if (component)
|
if (component)
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public:
|
|||||||
Node* getFrom() const;
|
Node* getFrom() const;
|
||||||
Node* getTo() const;
|
Node* getTo() const;
|
||||||
|
|
||||||
|
std::string getName() const;
|
||||||
|
|
||||||
// Token implementation
|
// Token implementation
|
||||||
virtual bool isNode() const;
|
virtual bool isNode() const;
|
||||||
virtual bool isEdge() const;
|
virtual bool isEdge() const;
|
||||||
|
|||||||
@@ -59,12 +59,12 @@ Edge* Graph::getEdgeById(Id id) const
|
|||||||
|
|
||||||
Token* Graph::getTokenById(Id id) const
|
Token* Graph::getTokenById(Id id) const
|
||||||
{
|
{
|
||||||
return findToken(
|
Token* token = getNodeById(id);
|
||||||
[id](Token* t)
|
if (!token)
|
||||||
{
|
{
|
||||||
return t->getId() == id;
|
token = getEdgeById(id);
|
||||||
}
|
}
|
||||||
);
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* Graph::createNodeHierarchy(const std::string& fullName)
|
Node* Graph::createNodeHierarchy(const std::string& fullName)
|
||||||
|
|||||||
@@ -360,6 +360,25 @@ public:
|
|||||||
TS_ASSERT_DIFFERS(x, b);
|
TS_ASSERT_DIFFERS(x, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_node_has_name_and_full_name()
|
||||||
|
{
|
||||||
|
TestGraph graph;
|
||||||
|
Node* n = graph.createNodeHierarchy("A::B::C");
|
||||||
|
|
||||||
|
TS_ASSERT_EQUALS(n->getName(), "C");
|
||||||
|
TS_ASSERT_EQUALS(n->getFullName(), "A::B::C");
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_edge_has_name()
|
||||||
|
{
|
||||||
|
TestGraph graph;
|
||||||
|
Node* a = graph.createNodeHierarchy(Node::NODE_FUNCTION, "A");
|
||||||
|
Node* b = graph.createNodeHierarchy(Node::NODE_FUNCTION, "B");
|
||||||
|
Edge* e = graph.createEdge(Edge::EDGE_CALL, a, b);
|
||||||
|
|
||||||
|
TS_ASSERT_EQUALS(e->getName(), "call:A->B");
|
||||||
|
}
|
||||||
|
|
||||||
void test_graph_saves_nodes_with_distinct_signatures()
|
void test_graph_saves_nodes_with_distinct_signatures()
|
||||||
{
|
{
|
||||||
TestGraph graph;
|
TestGraph graph;
|
||||||
|
|||||||
Reference in New Issue
Block a user