ui: snippet sizes
* added SnippetMerger class that conducts the merging and snapping of TokenLocations to create snippets. * added parameters for snippet snapping and merging to ApplicationSettings. * added forEachStartTokenLocation() and forEachEndTokenLocation() to TokenLocationLine and TokenLocationFile. * added < and > operators to TokenLocation that compare the location part (not the id).
This commit is contained in:
@@ -1055,6 +1055,48 @@ TokenLocationCollection Storage::getErrorTokenLocations(std::vector<std::string>
|
||||
return m_errorLocationCollection;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> Storage::getTokenLocationOfParentScope(const TokenLocation* child) const
|
||||
{
|
||||
const TokenLocation* parent = child;
|
||||
const FilePath filePath = child->getFilePath();
|
||||
const TokenLocationFile* locationFile = m_locationCollection.findTokenLocationFileByPath(child->getFilePath());
|
||||
locationFile->forEachTokenLocation(
|
||||
[&](TokenLocation* tokenLocation) -> void
|
||||
{
|
||||
if (tokenLocation->isStartTokenLocation())
|
||||
{
|
||||
TokenLocation::LocationType lt = tokenLocation->getType();
|
||||
int sln = tokenLocation->getLineNumber();
|
||||
int eln = tokenLocation->getEndTokenLocation()->getLineNumber();
|
||||
if (tokenLocation->getType() == TokenLocation::LOCATION_SCOPE &&
|
||||
tokenLocation->isStartTokenLocation() &&
|
||||
(*tokenLocation) < *(child->getStartTokenLocation()) &&
|
||||
(*tokenLocation->getEndTokenLocation()) > *(child->getEndTokenLocation()))
|
||||
{
|
||||
if (parent == child)
|
||||
{
|
||||
parent = tokenLocation;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((*tokenLocation) > *parent) // since tokenLocation is a start location the > location indiceates the scope that is closer to the child.
|
||||
{
|
||||
parent = tokenLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
std::shared_ptr<TokenLocationFile> file = std::make_shared<TokenLocationFile>(filePath);
|
||||
if (parent != child)
|
||||
{
|
||||
file->addTokenLocationAsPlainCopy(parent);
|
||||
file->addTokenLocationAsPlainCopy(parent->getOtherTokenLocation());
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
const Graph& Storage::getGraph() const
|
||||
{
|
||||
return m_graph;
|
||||
|
||||
@@ -126,6 +126,8 @@ public:
|
||||
|
||||
virtual TokenLocationCollection getErrorTokenLocations(std::vector<std::string>* errorMessages) const;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationOfParentScope(const TokenLocation* child) const;
|
||||
|
||||
protected:
|
||||
const Graph& getGraph() const;
|
||||
const TokenLocationCollection& getTokenLocationCollection() const;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "data/search/SearchMatch.h"
|
||||
|
||||
class Graph;
|
||||
class TokenLocation;
|
||||
class TokenLocationCollection;
|
||||
class TokenLocationFile;
|
||||
|
||||
@@ -38,6 +39,7 @@ public:
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber) const = 0;
|
||||
|
||||
virtual TokenLocationCollection getErrorTokenLocations(std::vector<std::string>* errorMessages) const = 0;
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationOfParentScope(const TokenLocation* child) const = 0;
|
||||
};
|
||||
|
||||
#endif // STORAGE_ACCESS_H
|
||||
|
||||
@@ -153,3 +153,13 @@ TokenLocationCollection StorageAccessProxy::getErrorTokenLocations(std::vector<s
|
||||
|
||||
return TokenLocationCollection();
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> StorageAccessProxy::getTokenLocationOfParentScope(const TokenLocation* child) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationOfParentScope(child);
|
||||
}
|
||||
|
||||
return std::make_shared<TokenLocationFile>("");
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ public:
|
||||
|
||||
virtual TokenLocationCollection getErrorTokenLocations(std::vector<std::string>* errorMessages) const;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationOfParentScope(const TokenLocation* child) const;
|
||||
|
||||
private:
|
||||
StorageAccess* m_subject;
|
||||
};
|
||||
|
||||
@@ -39,6 +39,26 @@ TokenLocation::~TokenLocation()
|
||||
{
|
||||
}
|
||||
|
||||
bool TokenLocation::operator<(const TokenLocation& rhs) const
|
||||
{
|
||||
return (
|
||||
getLineNumber() < rhs.getLineNumber() || (
|
||||
getLineNumber() == rhs.getLineNumber() &&
|
||||
getColumnNumber() < rhs.getColumnNumber()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
bool TokenLocation::operator>(const TokenLocation& rhs) const
|
||||
{
|
||||
return (
|
||||
getLineNumber() > rhs.getLineNumber() || (
|
||||
getLineNumber() == rhs.getLineNumber() &&
|
||||
getColumnNumber() > rhs.getColumnNumber()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Id TokenLocation::getId() const
|
||||
{
|
||||
return m_id;
|
||||
@@ -123,6 +143,30 @@ TokenLocation* TokenLocation::getEndTokenLocation()
|
||||
}
|
||||
}
|
||||
|
||||
const TokenLocation* TokenLocation::getStartTokenLocation() const
|
||||
{
|
||||
if (m_isStart)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_other;
|
||||
}
|
||||
}
|
||||
|
||||
const TokenLocation* TokenLocation::getEndTokenLocation() const
|
||||
{
|
||||
if (!m_isStart)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_other;
|
||||
}
|
||||
}
|
||||
|
||||
bool TokenLocation::isStartTokenLocation() const
|
||||
{
|
||||
return m_isStart;
|
||||
|
||||
@@ -26,6 +26,9 @@ public:
|
||||
TokenLocation(const TokenLocation& other, TokenLocationLine* line);
|
||||
~TokenLocation();
|
||||
|
||||
bool operator<(const TokenLocation& rhs) const;
|
||||
bool operator>(const TokenLocation& rhs) const;
|
||||
|
||||
Id getId() const;
|
||||
Id getTokenId() const;
|
||||
|
||||
@@ -45,6 +48,9 @@ public:
|
||||
TokenLocation* getStartTokenLocation();
|
||||
TokenLocation* getEndTokenLocation();
|
||||
|
||||
const TokenLocation* getStartTokenLocation() const;
|
||||
const TokenLocation* getEndTokenLocation() const;
|
||||
|
||||
bool isStartTokenLocation() const;
|
||||
bool isEndTokenLocation() const;
|
||||
|
||||
|
||||
@@ -89,6 +89,22 @@ void TokenLocationFile::forEachTokenLocation(std::function<void(TokenLocation*)>
|
||||
}
|
||||
}
|
||||
|
||||
void TokenLocationFile::forEachStartTokenLocation(std::function<void(TokenLocation*)> func) const
|
||||
{
|
||||
for (const TokenLocationLinePairType& line : m_lines)
|
||||
{
|
||||
line.second->forEachStartTokenLocation(func);
|
||||
}
|
||||
}
|
||||
|
||||
void TokenLocationFile::forEachEndTokenLocation(std::function<void(TokenLocation*)> func) const
|
||||
{
|
||||
for (const TokenLocationLinePairType& line : m_lines)
|
||||
{
|
||||
line.second->forEachEndTokenLocation(func);
|
||||
}
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocationFile::addTokenLocationAsPlainCopy(const TokenLocation* location)
|
||||
{
|
||||
unsigned int lineNumber = location->getTokenLocationLine()->getLineNumber();
|
||||
|
||||
@@ -37,6 +37,8 @@ public:
|
||||
|
||||
void forEachTokenLocationLine(std::function<void(TokenLocationLine*)> func) const;
|
||||
void forEachTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
void forEachStartTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
void forEachEndTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
|
||||
TokenLocation* addTokenLocationAsPlainCopy(const TokenLocation* location);
|
||||
|
||||
|
||||
@@ -91,6 +91,28 @@ void TokenLocationLine::forEachTokenLocation(std::function<void(TokenLocation*)>
|
||||
}
|
||||
}
|
||||
|
||||
void TokenLocationLine::forEachStartTokenLocation(std::function<void(TokenLocation*)> func) const
|
||||
{
|
||||
for (const TokenLocationPairType& location : m_locations)
|
||||
{
|
||||
if (location.second->isStartTokenLocation())
|
||||
{
|
||||
func(location.second.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TokenLocationLine::forEachEndTokenLocation(std::function<void(TokenLocation*)> func) const
|
||||
{
|
||||
for (const TokenLocationPairType& location : m_locations)
|
||||
{
|
||||
if (location.second->isEndTokenLocation())
|
||||
{
|
||||
func(location.second.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocationLine::addTokenLocationAsPlainCopy(const TokenLocation* location)
|
||||
{
|
||||
std::shared_ptr<TokenLocation> locationPtr = std::make_shared<TokenLocation>(*location, this);
|
||||
|
||||
@@ -37,6 +37,8 @@ public:
|
||||
TokenLocation* getTokenLocationById(Id id) const;
|
||||
|
||||
void forEachTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
void forEachStartTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
void forEachEndTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
|
||||
TokenLocation* addTokenLocationAsPlainCopy(const TokenLocation* location);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user