data: Added getName() method to Edge

format = EdgeType:fromNode->toNode
This commit is contained in:
Eberhard Graether
2014-07-27 02:22:45 +02:00
parent 473e26f072
commit b0e3cda41e
5 changed files with 56 additions and 17 deletions
+15 -2
View File
@@ -246,8 +246,21 @@ Id Storage::getIdForNodeWithName(const std::string& fullName) const
std::string Storage::getNameForNodeWithId(Id id) const
{
Node* node = m_graph.getNodeById(id);
return (node ? node->getFullName() : "");
Token* token = m_graph.getTokenById(id);
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
+14 -9
View File
@@ -53,6 +53,11 @@ Node* Edge::getTo() const
return m_to;
}
std::string Edge::getName() const
{
return getTypeString() + ":" + getFrom()->getFullName() + "->" + getTo()->getFullName();
}
bool Edge::isNode() const
{
return false;
@@ -101,21 +106,21 @@ std::string Edge::getTypeString() const
switch (m_type)
{
case EDGE_MEMBER:
return "has child";
return "child";
case EDGE_TYPE_OF:
return "is type of";
return "type use";
case EDGE_RETURN_TYPE_OF:
return "has return type";
return "return type";
case EDGE_PARAMETER_TYPE_OF:
return "has parameter of type";
return "parameter type";
case EDGE_INHERITANCE:
return "is derived from";
return "inheritance";
case EDGE_CALL:
return "calls";
return "call";
case EDGE_USAGE:
return "uses";
return "usage";
case EDGE_TYPEDEF_OF:
return "is typedef of";
return "typedef";
}
return "";
}
@@ -123,7 +128,7 @@ std::string Edge::getTypeString() const
std::string Edge::getAsString() const
{
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>();
if (component)
+2
View File
@@ -34,6 +34,8 @@ public:
Node* getFrom() const;
Node* getTo() const;
std::string getName() const;
// Token implementation
virtual bool isNode() const;
virtual bool isEdge() const;
+6 -6
View File
@@ -59,12 +59,12 @@ Edge* Graph::getEdgeById(Id id) const
Token* Graph::getTokenById(Id id) const
{
return findToken(
[id](Token* t)
{
return t->getId() == id;
}
);
Token* token = getNodeById(id);
if (!token)
{
token = getEdgeById(id);
}
return token;
}
Node* Graph::createNodeHierarchy(const std::string& fullName)
+19
View File
@@ -360,6 +360,25 @@ public:
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()
{
TestGraph graph;