utility: added FilePath abstraction and rewrote data management to use it

The utility class FilePath wraps an instance of boost::filesystem::path. Using FilePath allows for easy comparision of
file paths on different platforms using absolute or relative paths. Whereever file paths are compared, this wrapper
should be used.
This commit is contained in:
Eberhard Graether
2015-03-09 01:51:32 +01:00
parent 7014c8ac4c
commit df888e4151
37 changed files with 387 additions and 126 deletions
+2 -2
View File
@@ -39,7 +39,7 @@ void QtCodeFileList::addCodeSnippet(
const std::string& code, const std::string& code,
const TokenLocationFile& locationFile const TokenLocationFile& locationFile
){ ){
std::string fileName = FileSystem::fileName(locationFile.getFilePath()); std::string fileName = locationFile.getFilePath().fileName();
QtCodeFile* file = nullptr; QtCodeFile* file = nullptr;
for (std::shared_ptr<QtCodeFile> filePtr : m_files) for (std::shared_ptr<QtCodeFile> filePtr : m_files)
@@ -53,7 +53,7 @@ void QtCodeFileList::addCodeSnippet(
if (!file) if (!file)
{ {
std::shared_ptr<QtCodeFile> filePtr = std::make_shared<QtCodeFile>(locationFile.getFilePath(), this); std::shared_ptr<QtCodeFile> filePtr = std::make_shared<QtCodeFile>(locationFile.getFilePath().absoluteStr(), this);
m_files.push_back(filePtr); m_files.push_back(filePtr);
file = filePtr.get(); file = filePtr.get();
+1 -1
View File
@@ -104,7 +104,7 @@ void QtCodeView::doShowCodeFile(const CodeSnippetParams& params)
ptr->setErrorMessages(m_errorMessages); ptr->setErrorMessages(m_errorMessages);
ptr->addCodeSnippet(1, params.code, params.locationFile); ptr->addCodeSnippet(1, params.code, params.locationFile);
ptr->setWindowTitle(FileSystem::fileName(params.locationFile.getFilePath()).c_str()); ptr->setWindowTitle(params.locationFile.getFilePath().fileName().c_str());
ptr->show(); ptr->show();
float percent = float(params.startLineNumber + params.endLineNumber) / float(params.lineCount) / 2; float percent = float(params.startLineNumber + params.endLineNumber) / float(params.lineCount) / 2;
+2
View File
@@ -192,6 +192,8 @@ add_files(
utility/file/FileInfo.h utility/file/FileInfo.h
utility/file/FileManager.cpp utility/file/FileManager.cpp
utility/file/FileManager.h utility/file/FileManager.h
utility/file/FilePath.cpp
utility/file/FilePath.h
utility/file/FileRegister.cpp utility/file/FileRegister.cpp
utility/file/FileRegister.h utility/file/FileRegister.h
utility/file/FileSystem.cpp utility/file/FileSystem.cpp
+5 -5
View File
@@ -103,11 +103,11 @@ void Project::parseCode()
} }
m_fileManager->fetchFilePaths(); m_fileManager->fetchFilePaths();
std::set<std::string> addedFilePaths = m_fileManager->getAddedFilePaths(); std::set<FilePath> addedFilePaths = m_fileManager->getAddedFilePaths();
std::set<std::string> updatedFilePaths = m_fileManager->getUpdatedFilePaths(); std::set<FilePath> updatedFilePaths = m_fileManager->getUpdatedFilePaths();
std::set<std::string> removedFilePaths = m_fileManager->getRemovedFilePaths(); std::set<FilePath> removedFilePaths = m_fileManager->getRemovedFilePaths();
std::set<std::string> dependingFilePaths; std::set<FilePath> dependingFilePaths;
dependingFilePaths = m_storage->getDependingFilePathsAndRemoveFileNodes(updatedFilePaths); dependingFilePaths = m_storage->getDependingFilePathsAndRemoveFileNodes(updatedFilePaths);
updatedFilePaths.insert(dependingFilePaths.begin(), dependingFilePaths.end()); updatedFilePaths.insert(dependingFilePaths.begin(), dependingFilePaths.end());
@@ -117,7 +117,7 @@ void Project::parseCode()
m_storage->clearFileData(updatedFilePaths); m_storage->clearFileData(updatedFilePaths);
m_storage->clearFileData(removedFilePaths); m_storage->clearFileData(removedFilePaths);
std::vector<std::string> filesToParse; std::vector<FilePath> filesToParse;
filesToParse.insert(filesToParse.end(), addedFilePaths.begin(), addedFilePaths.end()); filesToParse.insert(filesToParse.end(), addedFilePaths.begin(), addedFilePaths.end());
filesToParse.insert(filesToParse.end(), updatedFilePaths.begin(), updatedFilePaths.end()); filesToParse.insert(filesToParse.end(), updatedFilePaths.begin(), updatedFilePaths.end());
@@ -108,7 +108,7 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
for (CodeView::CodeSnippetParams& params : fileSnippets) for (CodeView::CodeSnippetParams& params : fileSnippets)
{ {
params.locationFile = m_locationAccess->getTokenLocationsForLinesInFile( params.locationFile = m_locationAccess->getTokenLocationsForLinesInFile(
file->getFilePath(), params.startLineNumber, params.endLineNumber); file->getFilePath().str(), params.startLineNumber, params.endLineNumber);
} }
if (declarationId != 0) if (declarationId != 0)
@@ -144,7 +144,7 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(const TokenLocationFile* file) const std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(const TokenLocationFile* file) const
{ {
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(file->getFilePath()); std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(file->getFilePath().str());
std::vector<std::pair<uint, uint>> ranges = getSnippetRangesForFile(file); std::vector<std::pair<uint, uint>> ranges = getSnippetRangesForFile(file);
std::vector<CodeView::CodeSnippetParams> snippets; std::vector<CodeView::CodeSnippetParams> snippets;
+7 -7
View File
@@ -40,21 +40,21 @@ bool CodeView::CodeSnippetParams::sort(const CodeSnippetParams& a, const CodeSni
return false; return false;
} }
const FilePath& aFilePath = a.locationFile.getFilePath();
const FilePath& bFilePath = b.locationFile.getFilePath();
// different files // different files
if (a.locationFile.getFilePath() != b.locationFile.getFilePath()) if (aFilePath != bFilePath)
{ {
// first header // first header
if (FileSystem::filePathWithoutExtension(a.locationFile.getFilePath()) == if (aFilePath.withoutExtension() == bFilePath.withoutExtension())
FileSystem::filePathWithoutExtension(b.locationFile.getFilePath()))
{ {
return FileSystem::extension(a.locationFile.getFilePath()) > return aFilePath.extension() > bFilePath.extension();
FileSystem::extension(b.locationFile.getFilePath());
} }
// alphabetical filepath without extension // alphabetical filepath without extension
else else
{ {
return FileSystem::filePathWithoutExtension(a.locationFile.getFilePath()) return aFilePath.withoutExtension() < bFilePath.withoutExtension();
< FileSystem::filePathWithoutExtension(b.locationFile.getFilePath());
} }
} }
+14 -14
View File
@@ -42,17 +42,17 @@ void Storage::clear()
m_errorLocationCollection.clear(); m_errorLocationCollection.clear();
} }
void Storage::clearFileData(const std::set<std::string>& filePaths) void Storage::clearFileData(const std::set<FilePath>& filePaths)
{ {
for (const std::string& filePath : filePaths) for (const FilePath& filePath : filePaths)
{ {
TokenLocationFile* errorFile = m_errorLocationCollection.findTokenLocationFileByPath(filePath); TokenLocationFile* errorFile = m_errorLocationCollection.findTokenLocationFileByPath(filePath.str());
if (errorFile) if (errorFile)
{ {
m_errorLocationCollection.removeTokenLocationFile(errorFile); m_errorLocationCollection.removeTokenLocationFile(errorFile);
} }
TokenLocationFile* file = m_locationCollection.findTokenLocationFileByPath(filePath); TokenLocationFile* file = m_locationCollection.findTokenLocationFileByPath(filePath.str());
if (!file) if (!file)
{ {
continue; continue;
@@ -99,13 +99,13 @@ void Storage::clearFileData(const std::set<std::string>& filePaths)
} }
} }
std::set<std::string> Storage::getDependingFilePathsAndRemoveFileNodes(const std::set<std::string>& filePaths) std::set<FilePath> Storage::getDependingFilePathsAndRemoveFileNodes(const std::set<FilePath>& filePaths)
{ {
std::set<std::string> dependingFilePaths; std::set<FilePath> dependingFilePaths;
for (const std::string& filePath : filePaths) for (const FilePath& filePath : filePaths)
{ {
SearchNode* searchNode = m_tokenIndex.getNode(filePath); SearchNode* searchNode = m_tokenIndex.getNode(filePath.absoluteStr());
if (!searchNode || searchNode->getTokenIds().size() != 1) if (!searchNode || searchNode->getTokenIds().size() != 1)
{ {
continue; continue;
@@ -121,7 +121,7 @@ std::set<std::string> Storage::getDependingFilePathsAndRemoveFileNodes(const std
addDependingFilePathsAndRemoveFileNodesRecursive(fileNode, &dependingFilePaths); addDependingFilePathsAndRemoveFileNodesRecursive(fileNode, &dependingFilePaths);
} }
for (const std::string& path : filePaths) for (const FilePath& path : filePaths)
{ {
dependingFilePaths.erase(path); dependingFilePaths.erase(path);
} }
@@ -640,7 +640,7 @@ Id Storage::onFileParsed(const std::string& filePath)
{ {
log("file", filePath, ParseLocation()); log("file", filePath, ParseLocation());
Node* fileNode = addNodeHierarchy(Node::NODE_FILE, std::vector<std::string>(1, FileSystem::absoluteFilePath(filePath))); Node* fileNode = addNodeHierarchy(Node::NODE_FILE, std::vector<std::string>(1, FilePath(filePath).absoluteStr()));
return fileNode->getId(); return fileNode->getId();
} }
@@ -648,8 +648,8 @@ Id Storage::onFileIncludeParsed(const ParseLocation& location, const std::string
{ {
log("include", includedPath, location); log("include", includedPath, location);
Node* fileNode = addNodeHierarchy(Node::NODE_FILE, std::vector<std::string>(1, FileSystem::absoluteFilePath(filePath))); 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, FileSystem::absoluteFilePath(includedPath))); Node* includedFileNode = addNodeHierarchy(Node::NODE_FILE, std::vector<std::string>(1, FilePath(includedPath).absoluteStr()));
Edge* edge = m_graph.createEdge(Edge::EDGE_INCLUDE, fileNode, includedFileNode); Edge* edge = m_graph.createEdge(Edge::EDGE_INCLUDE, fileNode, includedFileNode);
addTokenLocation(edge, location); addTokenLocation(edge, location);
@@ -1257,9 +1257,9 @@ bool Storage::getQuerySearchResults(const std::string& query, const std::string&
return true; return true;
} }
void Storage::addDependingFilePathsAndRemoveFileNodesRecursive(Node* fileNode, std::set<std::string>* filePaths) void Storage::addDependingFilePathsAndRemoveFileNodesRecursive(Node* fileNode, std::set<FilePath>* filePaths)
{ {
bool inserted = filePaths->insert(fileNode->getFullName()).second; bool inserted = filePaths->insert(FilePath(fileNode->getFullName())).second;
if (!inserted) if (!inserted)
{ {
return; return;
+5 -3
View File
@@ -4,6 +4,8 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "utility/file/FilePath.h"
#include "data/access/GraphAccess.h" #include "data/access/GraphAccess.h"
#include "data/access/LocationAccess.h" #include "data/access/LocationAccess.h"
#include "data/graph/StorageGraph.h" #include "data/graph/StorageGraph.h"
@@ -23,8 +25,8 @@ public:
virtual ~Storage(); virtual ~Storage();
void clear(); void clear();
void clearFileData(const std::set<std::string>& filePaths); void clearFileData(const std::set<FilePath>& filePaths);
std::set<std::string> getDependingFilePathsAndRemoveFileNodes(const std::set<std::string>& filePaths); std::set<FilePath> getDependingFilePathsAndRemoveFileNodes(const std::set<FilePath>& filePaths);
void logGraph() const; void logGraph() const;
void logLocations() const; void logLocations() const;
@@ -148,7 +150,7 @@ private:
bool getQuerySearchResults(const std::string& query, const std::string& word, SearchResults* results) const; bool getQuerySearchResults(const std::string& query, const std::string& word, SearchResults* results) const;
void addDependingFilePathsAndRemoveFileNodesRecursive(Node* fileNode, std::set<std::string>* filePaths); void addDependingFilePathsAndRemoveFileNodesRecursive(Node* fileNode, std::set<FilePath>* filePaths);
void removeNodeIfUnreferenced(Node* node); void removeNodeIfUnreferenced(Node* node);
void log(std::string type, std::string str, const ParseLocation& location) const; void log(std::string type, std::string str, const ParseLocation& location) const;
+1 -1
View File
@@ -84,7 +84,7 @@ unsigned int TokenLocation::getLineNumber() const
return m_line->getLineNumber(); return m_line->getLineNumber();
} }
const std::string& TokenLocation::getFilePath() const const FilePath& TokenLocation::getFilePath() const
{ {
return m_line->getFilePath(); return m_line->getFilePath();
} }
+2 -1
View File
@@ -5,6 +5,7 @@
#include <ostream> #include <ostream>
#include <string> #include <string>
#include "utility/file/FilePath.h"
#include "utility/types.h" #include "utility/types.h"
class Token; class Token;
@@ -36,7 +37,7 @@ public:
unsigned int getColumnNumber() const; unsigned int getColumnNumber() const;
unsigned int getLineNumber() const; unsigned int getLineNumber() const;
const std::string& getFilePath() const; const FilePath& getFilePath() const;
TokenLocation* getOtherTokenLocation() const; TokenLocation* getOtherTokenLocation() const;
void setOtherTokenLocation(TokenLocation* location); void setOtherTokenLocation(TokenLocation* location);
@@ -38,7 +38,7 @@ size_t TokenLocationCollection::getTokenLocationCount() const
} }
TokenLocation* TokenLocationCollection::addTokenLocation( TokenLocation* TokenLocationCollection::addTokenLocation(
Id tokenId, const std::string& filePath, Id tokenId, const FilePath& filePath,
unsigned int startLineNumber, unsigned int startColumnNumber, unsigned int startLineNumber, unsigned int startColumnNumber,
unsigned int endLineNumber, unsigned int endColumnNumber) unsigned int endLineNumber, unsigned int endColumnNumber)
{ {
@@ -87,13 +87,13 @@ TokenLocation* TokenLocationCollection::findTokenLocationById(Id id) const
return nullptr; return nullptr;
} }
TokenLocationFile* TokenLocationCollection::findTokenLocationFileByPath(const std::string& filePath) const TokenLocationFile* TokenLocationCollection::findTokenLocationFileByPath(const FilePath& filePath) const
{ {
std::map<std::string, std::shared_ptr<TokenLocationFile>>::const_iterator it = std::map<FilePath, std::shared_ptr<TokenLocationFile>>::const_iterator it =
find_if(m_files.begin(), m_files.end(), find_if(m_files.begin(), m_files.end(),
[&](const std::pair<std::string, std::shared_ptr<TokenLocationFile>>& p) [&](const std::pair<FilePath, std::shared_ptr<TokenLocationFile>>& p)
{ {
return FileSystem::equivalent(p.first, filePath); return p.first == filePath;
} }
); );
@@ -143,7 +143,7 @@ void TokenLocationCollection::removeTokenLocationFile(TokenLocationFile* file)
TokenLocation* TokenLocationCollection::addTokenLocationAsPlainCopy(const TokenLocation* location) TokenLocation* TokenLocationCollection::addTokenLocationAsPlainCopy(const TokenLocation* location)
{ {
const std::string& filePath = location->getTokenLocationLine()->getTokenLocationFile()->getFilePath(); const FilePath& filePath = location->getTokenLocationLine()->getTokenLocationFile()->getFilePath();
TokenLocationFile* file = createTokenLocationFile(filePath); TokenLocationFile* file = createTokenLocationFile(filePath);
TokenLocation* copy = file->addTokenLocationAsPlainCopy(location); TokenLocation* copy = file->addTokenLocationAsPlainCopy(location);
@@ -157,7 +157,7 @@ void TokenLocationCollection::clear()
m_files.clear(); m_files.clear();
} }
TokenLocationFile* TokenLocationCollection::createTokenLocationFile(const std::string& filePath) TokenLocationFile* TokenLocationCollection::createTokenLocationFile(const FilePath& filePath)
{ {
TokenLocationFile* file = findTokenLocationFileByPath(filePath); TokenLocationFile* file = findTokenLocationFileByPath(filePath);
@@ -7,6 +7,7 @@
#include <ostream> #include <ostream>
#include <string> #include <string>
#include "utility/file/FilePath.h"
#include "utility/types.h" #include "utility/types.h"
class TokenLocation; class TokenLocation;
@@ -16,8 +17,8 @@ class TokenLocationLine;
class TokenLocationCollection class TokenLocationCollection
{ {
public: public:
typedef std::map<std::string, std::shared_ptr<TokenLocationFile> > TokenLocationFileMapType; typedef std::map<FilePath, std::shared_ptr<TokenLocationFile> > TokenLocationFileMapType;
typedef std::pair<std::string, std::shared_ptr<TokenLocationFile> > TokenLocationFilePairType; typedef std::pair<FilePath, std::shared_ptr<TokenLocationFile> > TokenLocationFilePairType;
TokenLocationCollection(); TokenLocationCollection();
~TokenLocationCollection(); ~TokenLocationCollection();
@@ -29,13 +30,13 @@ public:
size_t getTokenLocationCount() const; size_t getTokenLocationCount() const;
TokenLocation* addTokenLocation( TokenLocation* addTokenLocation(
Id tokenId, const std::string& filePath, Id tokenId, const FilePath& filePath,
unsigned int startLineNumber, unsigned int startColumnNumber, unsigned int startLineNumber, unsigned int startColumnNumber,
unsigned int endLineNumber, unsigned int endColumnNumber); unsigned int endLineNumber, unsigned int endColumnNumber);
void removeTokenLocation(TokenLocation* location); void removeTokenLocation(TokenLocation* location);
TokenLocation* findTokenLocationById(Id id) const; TokenLocation* findTokenLocationById(Id id) const;
TokenLocationFile* findTokenLocationFileByPath(const std::string& filePath) const; TokenLocationFile* findTokenLocationFileByPath(const FilePath& filePath) const;
void forEachTokenLocationFile(std::function<void(TokenLocationFile*)> func) const; void forEachTokenLocationFile(std::function<void(TokenLocationFile*)> func) const;
void forEachTokenLocationLine(std::function<void(TokenLocationLine*)> func) const; void forEachTokenLocationLine(std::function<void(TokenLocationLine*)> func) const;
@@ -48,7 +49,7 @@ public:
void clear(); void clear();
private: private:
TokenLocationFile* createTokenLocationFile(const std::string& filePath); TokenLocationFile* createTokenLocationFile(const FilePath& filePath);
TokenLocationFileMapType m_files; TokenLocationFileMapType m_files;
std::map<Id, TokenLocation*> m_locations; std::map<Id, TokenLocation*> m_locations;
+5 -4
View File
@@ -1,10 +1,11 @@
#include "data/location/TokenLocationFile.h" #include "data/location/TokenLocationFile.h"
#include "utility/logging/logging.h"
#include "data/location/TokenLocation.h" #include "data/location/TokenLocation.h"
#include "data/location/TokenLocationLine.h" #include "data/location/TokenLocationLine.h"
#include "utility/logging/logging.h"
TokenLocationFile::TokenLocationFile(const std::string& filePath) TokenLocationFile::TokenLocationFile(const FilePath& filePath)
: m_filePath(filePath) : m_filePath(filePath)
{ {
} }
@@ -23,7 +24,7 @@ size_t TokenLocationFile::getTokenLocationLineCount() const
return m_lines.size(); return m_lines.size();
} }
const std::string& TokenLocationFile::getFilePath() const const FilePath& TokenLocationFile::getFilePath() const
{ {
return m_filePath; return m_filePath;
} }
@@ -156,7 +157,7 @@ TokenLocationLine* TokenLocationFile::createTokenLocationLine(unsigned int lineN
std::ostream& operator<<(std::ostream& ostream, const TokenLocationFile& file) std::ostream& operator<<(std::ostream& ostream, const TokenLocationFile& file)
{ {
ostream << "file \"" << file.getFilePath() << "\"\n"; ostream << "file \"" << file.getFilePath().str() << "\"\n";
file.forEachTokenLocationLine([&ostream](TokenLocationLine* l) file.forEachTokenLocationLine([&ostream](TokenLocationLine* l)
{ {
ostream << *l << '\n'; ostream << *l << '\n';
+6 -5
View File
@@ -7,6 +7,7 @@
#include <ostream> #include <ostream>
#include <string> #include <string>
#include "utility/file/FilePath.h"
#include "utility/types.h" #include "utility/types.h"
class TokenLocation; class TokenLocation;
@@ -15,16 +16,16 @@ class TokenLocationLine;
class TokenLocationFile class TokenLocationFile
{ {
public: public:
typedef std::map<unsigned int, std::shared_ptr<TokenLocationLine> > TokenLocationLineMapType; typedef std::map<unsigned int, std::shared_ptr<TokenLocationLine>> TokenLocationLineMapType;
typedef std::pair<unsigned int, std::shared_ptr<TokenLocationLine> > TokenLocationLinePairType; typedef std::pair<unsigned int, std::shared_ptr<TokenLocationLine>> TokenLocationLinePairType;
TokenLocationFile(const std::string& filePath); TokenLocationFile(const FilePath& filePath);
~TokenLocationFile(); ~TokenLocationFile();
const TokenLocationLineMapType& getTokenLocationLines() const; const TokenLocationLineMapType& getTokenLocationLines() const;
size_t getTokenLocationLineCount() const; size_t getTokenLocationLineCount() const;
const std::string& getFilePath() const; const FilePath& getFilePath() const;
TokenLocation* addTokenLocation( TokenLocation* addTokenLocation(
Id tokenId, Id tokenId,
@@ -44,7 +45,7 @@ private:
TokenLocationLine* createTokenLocationLine(unsigned int lineNumber); TokenLocationLine* createTokenLocationLine(unsigned int lineNumber);
std::map<unsigned int, std::shared_ptr<TokenLocationLine> > m_lines; std::map<unsigned int, std::shared_ptr<TokenLocationLine> > m_lines;
std::string m_filePath; FilePath m_filePath;
}; };
std::ostream& operator<<(std::ostream& ostream, const TokenLocationFile& file); std::ostream& operator<<(std::ostream& ostream, const TokenLocationFile& file);
+1 -1
View File
@@ -29,7 +29,7 @@ TokenLocationFile* TokenLocationLine::getTokenLocationFile() const
return m_file; return m_file;
} }
const std::string& TokenLocationLine::getFilePath() const const FilePath& TokenLocationLine::getFilePath() const
{ {
return m_file->getFilePath(); return m_file->getFilePath();
} }
+2 -1
View File
@@ -7,6 +7,7 @@
#include <ostream> #include <ostream>
#include <string> #include <string>
#include "utility/file/FilePath.h"
#include "utility/types.h" #include "utility/types.h"
class TokenLocation; class TokenLocation;
@@ -25,7 +26,7 @@ public:
size_t getTokenLocationCount() const; size_t getTokenLocationCount() const;
TokenLocationFile* getTokenLocationFile() const; TokenLocationFile* getTokenLocationFile() const;
const std::string& getFilePath() const; const FilePath& getFilePath() const;
unsigned int getLineNumber() const; unsigned int getLineNumber() const;
+2 -1
View File
@@ -7,6 +7,7 @@
#include "data/parser/ParserClient.h" #include "data/parser/ParserClient.h"
class FilePath;
class TextAccess; class TextAccess;
class Parser class Parser
@@ -16,7 +17,7 @@ public:
virtual ~Parser(); virtual ~Parser();
virtual void parseFiles( virtual void parseFiles(
const std::vector<std::string>& filePaths, const std::vector<FilePath>& filePaths,
const std::vector<std::string>& systemHeaderSearchPaths, const std::vector<std::string>& systemHeaderSearchPaths,
const std::vector<std::string>& headerSearchPaths) = 0; const std::vector<std::string>& headerSearchPaths) = 0;
virtual void parseFile(std::shared_ptr<TextAccess> textAccess) = 0; virtual void parseFile(std::shared_ptr<TextAccess> textAccess) = 0;
+9 -3
View File
@@ -59,7 +59,7 @@ CxxParser::~CxxParser()
} }
void CxxParser::parseFiles( void CxxParser::parseFiles(
const std::vector<std::string>& filePaths, const std::vector<FilePath>& filePaths,
const std::vector<std::string>& systemHeaderSearchPaths, const std::vector<std::string>& systemHeaderSearchPaths,
const std::vector<std::string>& headerSearchPaths const std::vector<std::string>& headerSearchPaths
){ ){
@@ -113,12 +113,18 @@ void CxxParser::parseFiles(
FileRegister fileRegister(m_fileManager, filePaths); FileRegister fileRegister(m_fileManager, filePaths);
std::vector<std::string> sourcePaths;
for (const FilePath& path : fileRegister.getSourceFilePaths())
{
sourcePaths.push_back(path.absoluteStr());
}
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions(); llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions();
CxxDiagnosticConsumer reporter(llvm::errs(), &*options, m_client); CxxDiagnosticConsumer reporter(llvm::errs(), &*options, m_client);
ASTActionFactory actionFactory(m_client, &fileRegister); ASTActionFactory actionFactory(m_client, &fileRegister);
clang::tooling::ClangTool tool(*compilationDatabase, fileRegister.getSourceFilePaths()); clang::tooling::ClangTool tool(*compilationDatabase, sourcePaths);
tool.setDiagnosticConsumer(&reporter); tool.setDiagnosticConsumer(&reporter);
tool.run(&actionFactory); tool.run(&actionFactory);
} }
@@ -131,7 +137,7 @@ void CxxParser::parseFile(std::shared_ptr<TextAccess> textAccess)
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions(); llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions();
CxxDiagnosticConsumer reporter(llvm::errs(), &*options, m_client, false); CxxDiagnosticConsumer reporter(llvm::errs(), &*options, m_client, false);
FileRegister fileRegister(m_fileManager, std::vector<std::string>()); FileRegister fileRegister(m_fileManager, std::vector<FilePath>());
ASTActionFactory actionFactory(m_client, &fileRegister); ASTActionFactory actionFactory(m_client, &fileRegister);
runToolOnCodeWithArgs(&reporter, actionFactory.create(), textAccess->getText(), args); runToolOnCodeWithArgs(&reporter, actionFactory.create(), textAccess->getText(), args);
+1 -1
View File
@@ -11,7 +11,7 @@ public:
~CxxParser(); ~CxxParser();
virtual void parseFiles( virtual void parseFiles(
const std::vector<std::string>& filePaths, const std::vector<FilePath>& filePaths,
const std::vector<std::string>& systemHeaderSearchPaths, const std::vector<std::string>& systemHeaderSearchPaths,
const std::vector<std::string>& headerSearchPaths); const std::vector<std::string>& headerSearchPaths);
virtual void parseFile(std::shared_ptr<TextAccess> textAccess); virtual void parseFile(std::shared_ptr<TextAccess> textAccess);
+1 -1
View File
@@ -1,6 +1,6 @@
#include "FileInfo.h" #include "FileInfo.h"
FileInfo::FileInfo(std::string path, boost::posix_time::ptime lastWriteTime) FileInfo::FileInfo(const FilePath& path, boost::posix_time::ptime lastWriteTime)
: path(path) : path(path)
, lastWriteTime(lastWriteTime) , lastWriteTime(lastWriteTime)
{ {
+5 -2
View File
@@ -2,13 +2,16 @@
#define FILE_INFO_H #define FILE_INFO_H
#include <string> #include <string>
#include "boost/date_time.hpp" #include "boost/date_time.hpp"
#include "utility/file/FilePath.h"
struct FileInfo struct FileInfo
{ {
FileInfo(std::string path, boost::posix_time::ptime lastWriteTime); FileInfo(const FilePath& path, boost::posix_time::ptime lastWriteTime);
std::string path; FilePath path;
boost::posix_time::ptime lastWriteTime; boost::posix_time::ptime lastWriteTime;
}; };
+14 -14
View File
@@ -36,7 +36,7 @@ void FileManager::fetchFilePaths()
m_updatedFiles.clear(); m_updatedFiles.clear();
m_removedFiles.clear(); m_removedFiles.clear();
for (std::map<std::string, FileInfo>::iterator it = m_files.begin(); it != m_files.end(); it++) for (std::map<FilePath, FileInfo>::iterator it = m_files.begin(); it != m_files.end(); it++)
{ {
m_removedFiles.insert(it->first); m_removedFiles.insert(it->first);
} }
@@ -52,8 +52,8 @@ void FileManager::fetchFilePaths()
for (FileInfo fileInfo: fileInfos) for (FileInfo fileInfo: fileInfos)
{ {
const std::string& filePath = fileInfo.path; const FilePath& filePath = fileInfo.path;
std::map<std::string, FileInfo>::iterator it = m_files.find(filePath); std::map<FilePath, FileInfo>::iterator it = m_files.find(filePath);
if (it != m_files.end()) if (it != m_files.end())
{ {
m_removedFiles.erase(filePath); m_removedFiles.erase(filePath);
@@ -65,44 +65,44 @@ void FileManager::fetchFilePaths()
} }
else else
{ {
m_files.insert(std::pair<std::string, FileInfo>(filePath, fileInfo)); m_files.insert(std::pair<FilePath, FileInfo>(filePath, fileInfo));
m_addedFiles.insert(filePath); m_addedFiles.insert(filePath);
} }
} }
} }
for (const std::string filePath : m_removedFiles) for (const FilePath& filePath : m_removedFiles)
{ {
m_files.erase(filePath); m_files.erase(filePath);
} }
} }
std::set<std::string> FileManager::getAddedFilePaths() const std::set<FilePath> FileManager::getAddedFilePaths() const
{ {
return m_addedFiles; return m_addedFiles;
} }
std::set<std::string> FileManager::getUpdatedFilePaths() const std::set<FilePath> FileManager::getUpdatedFilePaths() const
{ {
return m_updatedFiles; return m_updatedFiles;
} }
std::set<std::string> FileManager::getRemovedFilePaths() const std::set<FilePath> FileManager::getRemovedFilePaths() const
{ {
return m_removedFiles; return m_removedFiles;
} }
bool FileManager::hasFilePath(const std::string& filePath) const bool FileManager::hasFilePath(const FilePath& filePath) const
{ {
return (m_files.find(FileSystem::absoluteFilePath(filePath)) != m_files.end()); return (m_files.find(filePath) != m_files.end());
} }
bool FileManager::hasSourceExtension(const std::string& filePath) const bool FileManager::hasSourceExtension(const FilePath& filePath) const
{ {
return FileSystem::hasExtension(filePath, m_sourceExtensions); return filePath.hasExtension(m_sourceExtensions);
} }
bool FileManager::hasIncludeExtension(const std::string& filePath) const bool FileManager::hasIncludeExtension(const FilePath& filePath) const
{ {
return FileSystem::hasExtension(filePath, m_includeExtensions); return filePath.hasExtension(m_includeExtensions);
} }
+10 -10
View File
@@ -20,13 +20,13 @@ public:
void reset(); void reset();
void fetchFilePaths(); void fetchFilePaths();
std::set<std::string> getAddedFilePaths() const; std::set<FilePath> getAddedFilePaths() const;
std::set<std::string> getUpdatedFilePaths() const; std::set<FilePath> getUpdatedFilePaths() const;
std::set<std::string> getRemovedFilePaths() const; std::set<FilePath> getRemovedFilePaths() const;
virtual bool hasFilePath(const std::string& filePath) const; virtual bool hasFilePath(const FilePath& filePath) const;
virtual bool hasSourceExtension(const std::string& filePath) const; virtual bool hasSourceExtension(const FilePath& filePath) const;
virtual bool hasIncludeExtension(const std::string& filePath) const; virtual bool hasIncludeExtension(const FilePath& filePath) const;
private: private:
std::vector<std::string> m_sourcePaths; std::vector<std::string> m_sourcePaths;
@@ -34,10 +34,10 @@ private:
std::vector<std::string> m_sourceExtensions; std::vector<std::string> m_sourceExtensions;
std::vector<std::string> m_includeExtensions; std::vector<std::string> m_includeExtensions;
std::map<std::string, FileInfo> m_files; std::map<FilePath, FileInfo> m_files;
std::set<std::string> m_addedFiles; std::set<FilePath> m_addedFiles;
std::set<std::string> m_updatedFiles; std::set<FilePath> m_updatedFiles;
std::set<std::string> m_removedFiles; std::set<FilePath> m_removedFiles;
}; };
#endif // FILE_MANAGER_H #endif // FILE_MANAGER_H
+79
View File
@@ -0,0 +1,79 @@
#include "utility/file/FilePath.h"
FilePath::FilePath(const char* filePath)
: m_path(filePath)
{
}
FilePath::FilePath(const std::string& filePath)
: m_path(filePath)
{
}
FilePath::FilePath(const boost::filesystem::path& filePath)
: m_path(filePath)
{
}
bool FilePath::exists() const
{
return boost::filesystem::exists(m_path);
}
std::string FilePath::str() const
{
return m_path.generic_string();
}
std::string FilePath::absoluteStr() const
{
return boost::filesystem::absolute(m_path).generic_string();
}
std::string FilePath::fileName() const
{
return m_path.filename().generic_string();
}
std::string FilePath::extension() const
{
return m_path.extension().generic_string();
}
FilePath FilePath::withoutExtension() const
{
return FilePath(boost::filesystem::path(m_path).replace_extension());
}
bool FilePath::hasExtension(const std::vector<std::string>& extensions) const
{
std::string e = extension();
for (std::string ext : extensions)
{
if (e == ext)
{
return true;
}
}
return false;
}
bool FilePath::operator==(const FilePath& other) const
{
if (exists() && other.exists())
{
return boost::filesystem::equivalent(m_path, other.m_path);
}
return m_path.compare(other.m_path) == 0;
}
bool FilePath::operator!=(const FilePath& other) const
{
return !(*this == other);
}
bool FilePath::operator<(const FilePath& other) const
{
return m_path.compare(other.m_path) < 0;
}
+33
View File
@@ -0,0 +1,33 @@
#ifndef FILE_PATH_H
#define FILE_PATH_H
#include <string>
#include "boost/filesystem.hpp"
class FilePath
{
public:
FilePath(const char* filePath);
FilePath(const std::string& filePath);
FilePath(const boost::filesystem::path& filePath);
bool exists() const;
std::string str() const;
std::string absoluteStr() const;
std::string fileName() const;
std::string extension() const;
FilePath withoutExtension() const;
bool hasExtension(const std::vector<std::string>& extensions) const;
bool operator==(const FilePath& other) const;
bool operator!=(const FilePath& other) const;
bool operator<(const FilePath& other) const;
private:
boost::filesystem::path m_path;
};
#endif // FILE_PATH_H
+6 -6
View File
@@ -3,10 +3,10 @@
#include "utility/file/FileManager.h" #include "utility/file/FileManager.h"
#include "utility/file/FileSystem.h" #include "utility/file/FileSystem.h"
FileRegister::FileRegister(const FileManager* fileManager, const std::vector<std::string>& filePaths) FileRegister::FileRegister(const FileManager* fileManager, const std::vector<FilePath>& filePaths)
: m_fileManager(fileManager) : m_fileManager(fileManager)
{ {
for (const std::string& path : filePaths) for (const FilePath& path : filePaths)
{ {
if (m_fileManager->hasSourceExtension(path)) if (m_fileManager->hasSourceExtension(path))
{ {
@@ -24,14 +24,14 @@ const FileManager* FileRegister::getFileManager() const
return m_fileManager; return m_fileManager;
} }
const std::vector<std::string>& FileRegister::getSourceFilePaths() const const std::vector<FilePath>& FileRegister::getSourceFilePaths() const
{ {
return m_sourceFilePaths; return m_sourceFilePaths;
} }
bool FileRegister::includeFileIsParsing(const std::string& filePath) const bool FileRegister::includeFileIsParsing(const std::string& filePath) const
{ {
std::map<std::string, ParseState>::const_iterator it = m_includeFilePaths.find(FileSystem::absoluteFilePath(filePath)); std::map<FilePath, ParseState>::const_iterator it = m_includeFilePaths.find(FilePath(filePath));
if (it == m_includeFilePaths.end()) if (it == m_includeFilePaths.end())
{ {
return false; return false;
@@ -42,7 +42,7 @@ bool FileRegister::includeFileIsParsing(const std::string& filePath) const
void FileRegister::markIncludeFileParsing(const std::string& filePath) void FileRegister::markIncludeFileParsing(const std::string& filePath)
{ {
std::map<std::string, ParseState>::iterator it = m_includeFilePaths.find(FileSystem::absoluteFilePath(filePath)); std::map<FilePath, ParseState>::iterator it = m_includeFilePaths.find(FilePath(filePath));
if (it == m_includeFilePaths.end()) if (it == m_includeFilePaths.end())
{ {
return; return;
@@ -56,7 +56,7 @@ void FileRegister::markIncludeFileParsing(const std::string& filePath)
void FileRegister::markParsingIncludeFilesParsed() void FileRegister::markParsingIncludeFilesParsed()
{ {
for (std::pair<std::string, ParseState>&& p : m_includeFilePaths) for (std::pair<FilePath, ParseState>&& p : m_includeFilePaths)
{ {
if (p.second == STATE_PARSING) if (p.second == STATE_PARSING)
{ {
+6 -4
View File
@@ -5,16 +5,18 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "utility/file/FilePath.h"
class FileManager; class FileManager;
class FileRegister class FileRegister
{ {
public: public:
FileRegister(const FileManager* fileManager, const std::vector<std::string>& filePaths); FileRegister(const FileManager* fileManager, const std::vector<FilePath>& filePaths);
const FileManager* getFileManager() const; const FileManager* getFileManager() const;
const std::vector<std::string>& getSourceFilePaths() const; const std::vector<FilePath>& getSourceFilePaths() const;
bool includeFileIsParsing(const std::string& filePath) const; bool includeFileIsParsing(const std::string& filePath) const;
@@ -31,8 +33,8 @@ private:
const FileManager* m_fileManager; const FileManager* m_fileManager;
std::vector<std::string> m_sourceFilePaths; std::vector<FilePath> m_sourceFilePaths;
std::map<std::string, ParseState> m_includeFilePaths; std::map<FilePath, ParseState> m_includeFilePaths;
}; };
#endif // FILE_REGISTER_H #endif // FILE_REGISTER_H
+1 -1
View File
@@ -69,7 +69,7 @@ std::vector<FileInfo> FileSystem::getFileInfosFromDirectoryPaths(
{ {
std::time_t t = boost::filesystem::last_write_time(*it); std::time_t t = boost::filesystem::last_write_time(*it);
boost::posix_time::ptime lastWriteTime = boost::posix_time::from_time_t(t); boost::posix_time::ptime lastWriteTime = boost::posix_time::from_time_t(t);
files.push_back(FileInfo(absoluteFilePath(it->path().generic_string()), lastWriteTime)); files.push_back(FileInfo(it->path(), lastWriteTime));
} }
++it; ++it;
} }
+1
View File
@@ -14,6 +14,7 @@ add_files(
DataTypeTestSuite.h DataTypeTestSuite.h
DictionaryTestSuite.h DictionaryTestSuite.h
FileManagerTestSuite.h FileManagerTestSuite.h
FilePathTestSuite.h
FileSystemTestSuite.h FileSystemTestSuite.h
GraphTestSuite.h GraphTestSuite.h
GraphFilterTestSuite.h GraphFilterTestSuite.h
+3 -3
View File
@@ -1687,9 +1687,9 @@ public:
TestParserClient client; TestParserClient client;
CxxParser parser(&client, &fm); CxxParser parser(&client, &fm);
std::vector<std::string> filePaths; std::vector<FilePath> filePaths;
filePaths.push_back("data/CxxParserTestSuite/header.h"); filePaths.push_back(FilePath("data/CxxParserTestSuite/header.h"));
filePaths.push_back("data/CxxParserTestSuite/code.cpp"); filePaths.push_back(FilePath("data/CxxParserTestSuite/code.cpp"));
parser.parseFiles(filePaths, std::vector<std::string>(), std::vector<std::string>()); parser.parseFiles(filePaths, std::vector<std::string>(), std::vector<std::string>());
TS_ASSERT_EQUALS(client.errors.size(), 0); TS_ASSERT_EQUALS(client.errors.size(), 0);
+127
View File
@@ -0,0 +1,127 @@
#include "cxxtest/TestSuite.h"
#include "utility/file/FilePath.h"
class FilePathTestSuite : public CxxTest::TestSuite
{
public:
void test_file_path_gets_created_with_char_array()
{
FilePath path("data/FilePathTestSuite/main.cpp");
TS_ASSERT_EQUALS(path.str(), "data/FilePathTestSuite/main.cpp");
}
void test_file_path_gets_created_with_string()
{
std::string str("data/FilePathTestSuite/main.cpp");
FilePath path(str);
TS_ASSERT_EQUALS(path.str(), str);
}
void test_file_path_gets_created_other_file_path()
{
FilePath path("data/FilePathTestSuite/main.cpp");
FilePath path2(path);
TS_ASSERT_EQUALS(path, path2);
}
void test_file_path_exists()
{
FilePath path("data/FilePathTestSuite/a.cpp");
TS_ASSERT(path.exists());
}
void test_file_path_not_exists()
{
FilePath path("data/FilePathTestSuite/a.h");
TS_ASSERT(!path.exists());
}
void test_file_path_file_name()
{
FilePath path("data/FilePathTestSuite/abc.h");
TS_ASSERT_EQUALS(path.fileName(), "abc.h");
}
void test_file_path_extension()
{
FilePath path("data/FilePathTestSuite/a.h");
TS_ASSERT_EQUALS(path.extension(), ".h");
}
void test_file_path_without_extension()
{
FilePath path("data/FilePathTestSuite/a.h");
TS_ASSERT_EQUALS(path.withoutExtension(), "data/FilePathTestSuite/a");
}
void test_file_path_has_extension()
{
std::vector<std::string> extensions;
extensions.push_back(".h");
extensions.push_back(".cpp");
extensions.push_back(".cc");
TS_ASSERT(FilePath("data/FilePathTestSuite/a.h").hasExtension(extensions));
TS_ASSERT(FilePath("data/FilePathTestSuite/b.cpp").hasExtension(extensions));
TS_ASSERT(!FilePath("data/FilePathTestSuite/a.m").hasExtension(extensions));
}
void test_file_path_equals_file_with_different_relative_paths()
{
FilePath pathA("data/FilePathTestSuite/a.cpp");
FilePath pathA2("data/../data/FilePathTestSuite/./a.cpp");
TS_ASSERT_EQUALS(pathA, pathA2);
}
void test_file_path_equals_relative_and_absolute_paths()
{
FilePath pathA("data/FilePathTestSuite/a.cpp");
FilePath pathA2(pathA.absoluteStr());
TS_ASSERT_EQUALS(pathA, pathA2);
}
void test_file_path_compares_paths_with_posix_and_windows_format()
{
#ifdef _WIN32
FilePath pathB("data/FilePathTestSuite/b.cc");
FilePath pathB2("data\\FilePathTestSuite\\b.cc");
TS_ASSERT_EQUALS(pathB, pathB2);
#endif
}
void test_file_path_differs_for_different_existing_files()
{
FilePath pathA("data/FilePathTestSuite/a.cpp");
FilePath pathB("data/FilePathTestSuite/b.cc");
TS_ASSERT_DIFFERS(pathA, pathB);
}
void test_file_path_differs_for_different_nonexisting_files()
{
FilePath pathA("data/FilePathTestSuite/a.h");
FilePath pathB("data/FilePathTestSuite/b.c");
TS_ASSERT_DIFFERS(pathA, pathB);
}
void test_file_path_differs_for_existing_and_nonexisting_files()
{
FilePath pathA("data/FilePathTestSuite/a.h");
FilePath pathB("data/FilePathTestSuite/b.cc");
TS_ASSERT_DIFFERS(pathA, pathB);
}
};
+13 -13
View File
@@ -573,8 +573,8 @@ public:
TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 4); TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 4);
TS_ASSERT_EQUALS(storage.searchIndex().getNodeCount(), 3); TS_ASSERT_EQUALS(storage.searchIndex().getNodeCount(), 3);
std::set<std::string> files; std::set<FilePath> files;
files.insert(m_filePath); files.insert(FilePath(m_filePath));
storage.clearFileData(files); storage.clearFileData(files);
TS_ASSERT_EQUALS(storage.graph().getNodeCount(), 0); TS_ASSERT_EQUALS(storage.graph().getNodeCount(), 0);
@@ -604,8 +604,8 @@ public:
TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 9); TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 9);
TS_ASSERT_EQUALS(storage.searchIndex().getNodeCount(), 6); TS_ASSERT_EQUALS(storage.searchIndex().getNodeCount(), 6);
std::set<std::string> files; std::set<FilePath> files;
files.insert("file.cpp"); files.insert(FilePath("file.cpp"));
storage.clearFileData(files); storage.clearFileData(files);
TS_ASSERT_EQUALS(storage.graph().getNodeCount(), 3); TS_ASSERT_EQUALS(storage.graph().getNodeCount(), 3);
@@ -635,8 +635,8 @@ public:
TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 9); TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 9);
TS_ASSERT_EQUALS(storage.searchIndex().getNodeCount(), 5); TS_ASSERT_EQUALS(storage.searchIndex().getNodeCount(), 5);
std::set<std::string> files; std::set<FilePath> files;
files.insert("file.h"); files.insert(FilePath("file.h"));
storage.clearFileData(files); storage.clearFileData(files);
TS_ASSERT_EQUALS(storage.graph().getNodeCount(), 4); TS_ASSERT_EQUALS(storage.graph().getNodeCount(), 4);
@@ -666,9 +666,9 @@ public:
TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 9); TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 9);
TS_ASSERT_EQUALS(storage.searchIndex().getNodeCount(), 5); TS_ASSERT_EQUALS(storage.searchIndex().getNodeCount(), 5);
std::set<std::string> filePaths; std::set<FilePath> filePaths;
filePaths.insert("file.cpp"); filePaths.insert(FilePath("file.cpp"));
filePaths.insert("file.h"); filePaths.insert(FilePath("file.h"));
storage.clearFileData(filePaths); storage.clearFileData(filePaths);
TS_ASSERT_EQUALS(storage.graph().getNodeCount(), 0); TS_ASSERT_EQUALS(storage.graph().getNodeCount(), 0);
@@ -722,12 +722,12 @@ public:
std::string name1 = storage.getNodeWithId(id2)->getFullName(); std::string name1 = storage.getNodeWithId(id2)->getFullName();
std::string name2 = storage.getNodeWithId(id3)->getFullName(); std::string name2 = storage.getNodeWithId(id3)->getFullName();
std::set<std::string> filePaths; std::set<FilePath> filePaths;
filePaths.insert(name1); filePaths.insert(FilePath(name1));
std::set<std::string> dependingFilePaths = storage.getDependingFilePathsAndRemoveFileNodes(filePaths); std::set<FilePath> dependingFilePaths = storage.getDependingFilePathsAndRemoveFileNodes(filePaths);
TS_ASSERT_EQUALS(dependingFilePaths.size(), 1); TS_ASSERT_EQUALS(dependingFilePaths.size(), 1);
TS_ASSERT_EQUALS(*dependingFilePaths.begin(), name2); TS_ASSERT_EQUALS(dependingFilePaths.begin()->str(), name2);
TS_ASSERT(storage.getNodeWithId(id1)); TS_ASSERT(storage.getNodeWithId(id1));
TS_ASSERT(!storage.getNodeWithId(id2)); TS_ASSERT(!storage.getNodeWithId(id2));
+1 -1
View File
@@ -69,7 +69,7 @@ public:
TS_ASSERT_EQUALS(3, a->getColumnNumber()); TS_ASSERT_EQUALS(3, a->getColumnNumber());
TS_ASSERT_EQUALS(4, a->getOtherTokenLocation()->getLineNumber()); TS_ASSERT_EQUALS(4, a->getOtherTokenLocation()->getLineNumber());
TS_ASSERT_EQUALS(5, a->getOtherTokenLocation()->getColumnNumber()); TS_ASSERT_EQUALS(5, a->getOtherTokenLocation()->getColumnNumber());
TS_ASSERT_EQUALS("file.c", a->getFilePath()); TS_ASSERT_EQUALS("file.c", a->getFilePath().str());
} }
void test_finding_token_locations_by_id() void test_finding_token_locations_by_id()
+3 -3
View File
@@ -10,17 +10,17 @@ TestFileManager::TestFileManager()
{ {
} }
bool TestFileManager::hasFilePath(const std::string& filePath) const bool TestFileManager::hasFilePath(const FilePath& filePath) const
{ {
return true; return true;
} }
bool TestFileManager::hasSourceExtension(const std::string& filePath) const bool TestFileManager::hasSourceExtension(const FilePath& filePath) const
{ {
return true; return true;
} }
bool TestFileManager::hasIncludeExtension(const std::string& filePath) const bool TestFileManager::hasIncludeExtension(const FilePath& filePath) const
{ {
return true; return true;
} }
+3 -3
View File
@@ -8,9 +8,9 @@ class TestFileManager: public FileManager
public: public:
TestFileManager(); TestFileManager();
virtual bool hasFilePath(const std::string& filePath) const; virtual bool hasFilePath(const FilePath& filePath) const;
virtual bool hasSourceExtension(const std::string& filePath) const; virtual bool hasSourceExtension(const FilePath& filePath) const;
virtual bool hasIncludeExtension(const std::string& filePath) const; virtual bool hasIncludeExtension(const FilePath& filePath) const;
}; };
#endif // TEST_FILE_MANAGER_H #endif // TEST_FILE_MANAGER_H