ui: improved file nodes

* added colors for file nodes and dependency edges
* use TokenComponentFilePath on file nodes to store FilePath
This commit is contained in:
Eberhard Graether
2015-03-09 14:07:58 +01:00
parent 3893868386
commit ca9dfe7f75
15 changed files with 114 additions and 48 deletions
+27 -7
View File
@@ -8,6 +8,7 @@
#include "data/graph/token_component/TokenComponentConst.h"
#include "data/graph/token_component/TokenComponentName.h"
#include "data/graph/token_component/TokenComponentStatic.h"
#include "data/graph/token_component/TokenComponentFilePath.h"
#include "data/graph/SubGraph.h"
#include "data/location/TokenLocation.h"
#include "data/location/TokenLocationFile.h"
@@ -46,13 +47,13 @@ void Storage::clearFileData(const std::set<FilePath>& filePaths)
{
for (const FilePath& filePath : filePaths)
{
TokenLocationFile* errorFile = m_errorLocationCollection.findTokenLocationFileByPath(filePath.str());
TokenLocationFile* errorFile = m_errorLocationCollection.findTokenLocationFileByPath(filePath);
if (errorFile)
{
m_errorLocationCollection.removeTokenLocationFile(errorFile);
}
TokenLocationFile* file = m_locationCollection.findTokenLocationFileByPath(filePath.str());
TokenLocationFile* file = m_locationCollection.findTokenLocationFileByPath(filePath);
if (!file)
{
continue;
@@ -105,7 +106,7 @@ std::set<FilePath> Storage::getDependingFilePathsAndRemoveFileNodes(const std::s
for (const FilePath& filePath : filePaths)
{
SearchNode* searchNode = m_tokenIndex.getNode(filePath.absoluteStr());
SearchNode* searchNode = m_tokenIndex.getNode(filePath.fileName());
if (!searchNode || searchNode->getTokenIds().size() != 1)
{
continue;
@@ -118,6 +119,13 @@ std::set<FilePath> Storage::getDependingFilePathsAndRemoveFileNodes(const std::s
continue;
}
if (!fileNode->getComponent<TokenComponentFilePath>() ||
fileNode->getComponent<TokenComponentFilePath>()->getFilePath() != filePath)
{
LOG_ERROR("Node is not resolving to the same file.");
continue;
}
addDependingFilePathsAndRemoveFileNodesRecursive(fileNode, &dependingFilePaths);
}
@@ -640,7 +648,7 @@ Id Storage::onFileParsed(const std::string& filePath)
{
log("file", filePath, ParseLocation());
Node* fileNode = addNodeHierarchy(Node::NODE_FILE, std::vector<std::string>(1, FilePath(filePath).absoluteStr()));
Node* fileNode = addFileNode(filePath);
return fileNode->getId();
}
@@ -648,8 +656,8 @@ Id Storage::onFileIncludeParsed(const ParseLocation& location, const std::string
{
log("include", includedPath, location);
Node* fileNode = addNodeHierarchy(Node::NODE_FILE, std::vector<std::string>(1, FilePath(filePath).absoluteStr()));
Node* includedFileNode = addNodeHierarchy(Node::NODE_FILE, std::vector<std::string>(1, FilePath(includedPath).absoluteStr()));
Node* fileNode = addFileNode(filePath);
Node* includedFileNode = addFileNode(includedPath);
Edge* edge = m_graph.createEdge(Edge::EDGE_INCLUDE, fileNode, includedFileNode);
addTokenLocation(edge, location);
@@ -1071,6 +1079,18 @@ Node* Storage::addNodeHierarchyWithDistinctSignature(Node::NodeType type, const
return m_graph.createNodeHierarchyWithDistinctSignature(type, searchNode, signature);
}
Node* Storage::addFileNode(const FilePath& filePath)
{
Node* fileNode = addNodeHierarchy(Node::NODE_FILE, std::vector<std::string>(1, filePath.fileName()));
if (!fileNode->getComponent<TokenComponentFilePath>())
{
fileNode->addComponentFilePath(std::make_shared<TokenComponentFilePath>(filePath));
}
return fileNode;
}
TokenComponentAccess::AccessType Storage::convertAccessType(ParserClient::AccessType access) const
{
switch (access)
@@ -1259,7 +1279,7 @@ bool Storage::getQuerySearchResults(const std::string& query, const std::string&
void Storage::addDependingFilePathsAndRemoveFileNodesRecursive(Node* fileNode, std::set<FilePath>* filePaths)
{
bool inserted = filePaths->insert(FilePath(fileNode->getFullName())).second;
bool inserted = filePaths->insert(fileNode->getComponent<TokenComponentFilePath>()->getFilePath()).second;
if (!inserted)
{
return;
+2
View File
@@ -139,6 +139,8 @@ private:
Node* addNodeHierarchy(Node::NodeType type, std::vector<std::string> nameHierarchy);
Node* addNodeHierarchyWithDistinctSignature(Node::NodeType type, const ParseFunction& function);
Node* addFileNode(const FilePath& filePath);
TokenComponentAccess::AccessType convertAccessType(ParserClient::AccessType access) const;
TokenComponentAccess* addAccess(Node* node, ParserClient::AccessType access);
+1 -8
View File
@@ -52,14 +52,7 @@ void FilterableGraph::printBasic(std::ostream& ostream) const
forEachNode(
[&ostream](Node* n)
{
if (n->isType(Node::NODE_FILE))
{
ostream << ' ' << n->getTypeString() << ':' << n->getName();
}
else
{
ostream << ' ' << n->getTypeString() << ':' << n->getFullName();
}
ostream << ' ' << n->getTypeString() << ':' << n->getFullName();
}
);
ostream << '\n';
+18 -8
View File
@@ -10,6 +10,7 @@
#include "data/graph/token_component/TokenComponentName.h"
#include "data/graph/token_component/TokenComponentStatic.h"
#include "data/graph/token_component/TokenComponentSignature.h"
#include "data/graph/token_component/TokenComponentFilePath.h"
Node::Node(NodeType type, std::shared_ptr<TokenComponentName> nameComponent)
: m_type(type)
@@ -52,14 +53,7 @@ bool Node::isType(NodeTypeMask mask) const
std::string Node::getName() const
{
if (isType(NODE_FILE))
{
return FileSystem::fileName(m_nameComponent->getName());
}
else
{
return m_nameComponent->getName();
}
return m_nameComponent->getName();
}
std::string Node::getFullName() const
@@ -317,6 +311,22 @@ void Node::addComponentSignature(std::shared_ptr<TokenComponentSignature> compon
}
}
void Node::addComponentFilePath(std::shared_ptr<TokenComponentFilePath> component)
{
if (getComponent<TokenComponentFilePath>())
{
LOG_ERROR("TokenComponentFilePath has been set before!");
}
else if (!isType(NODE_FILE))
{
LOG_ERROR("TokenComponentSignature can't be set on node of type: " + getTypeString());
}
else
{
addComponent(component);
}
}
std::string Node::getTypeString(NodeType type)
{
switch (type)
+2
View File
@@ -14,6 +14,7 @@ class TokenComponentConst;
class TokenComponentName;
class TokenComponentStatic;
class TokenComponentSignature;
class TokenComponentFilePath;
class Node: public Token
{
@@ -85,6 +86,7 @@ public:
void addComponentConst(std::shared_ptr<TokenComponentConst> component);
void addComponentStatic(std::shared_ptr<TokenComponentStatic> component);
void addComponentSignature(std::shared_ptr<TokenComponentSignature> component);
void addComponentFilePath(std::shared_ptr<TokenComponentFilePath> component);
// Logging.
virtual std::string getTypeString() const;
@@ -0,0 +1,20 @@
#include "data/graph/token_component/TokenComponentFilePath.h"
TokenComponentFilePath::TokenComponentFilePath(const FilePath& path)
: m_path(path)
{
}
TokenComponentFilePath::~TokenComponentFilePath()
{
}
std::shared_ptr<TokenComponent> TokenComponentFilePath::copy() const
{
return std::make_shared<TokenComponentFilePath>(*this);
}
const FilePath& TokenComponentFilePath::getFilePath() const
{
return m_path;
}
@@ -0,0 +1,23 @@
#ifndef TOKEN_COMPONENT_FILE_PATH_H
#define TOKEN_COMPONENT_FILE_PATH_H
#include "utility/file/FilePath.h"
#include "data/graph/token_component/TokenComponent.h"
class TokenComponentFilePath
: public TokenComponent
{
public:
TokenComponentFilePath(const FilePath& path);
virtual ~TokenComponentFilePath();
virtual std::shared_ptr<TokenComponent> copy() const;
const FilePath& getFilePath() const;
private:
const FilePath m_path;
};
#endif // TOKEN_COMPONENT_FILE_PATH_H