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:
malte_langkabel
2015-05-04 15:00:18 +02:00
parent 4ec3dfd372
commit fd73abde64
19 changed files with 345 additions and 35 deletions
+44
View File
@@ -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;
+6
View File
@@ -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);