Commit b86600a5 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Remove duplicated functions

Change-Id: I0758fc06843363d58faa835238a587095c9eb6de
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 91429aa7
......@@ -97,7 +97,7 @@ void ActivationSequenceContextProcessor::process()
void ActivationSequenceContextProcessor::processActivationSequence()
{
const int nonSpacePosition = findStartOfNonSpaceChar(m_startOfNamePosition);
const int nonSpacePosition = skipPrecedingWhitespace(m_assistInterface, m_startOfNamePosition);
const auto activationSequence = m_assistInterface->textAt(nonSpacePosition - 3, 3);
ActivationSequenceProcessor activationSequenceProcessor(activationSequence,
nonSpacePosition,
......@@ -228,28 +228,40 @@ void ActivationSequenceContextProcessor::resetPositionsForEOFCompletionKind()
m_operatorStartPosition = m_positionInDocument;
}
int ActivationSequenceContextProcessor::findStartOfNonSpaceChar(int startPosition)
int ActivationSequenceContextProcessor::skipPrecedingWhitespace(
const TextEditor::AssistInterface *assistInterface,
int startPosition)
{
int position = startPosition;
while (m_assistInterface->characterAt(position - 1).isSpace())
while (assistInterface->characterAt(position - 1).isSpace())
--position;
return position;
}
int ActivationSequenceContextProcessor::findStartOfName(int startPosition)
static bool isValidIdentifierChar(const QChar &character)
{
return character.isLetterOrNumber()
|| character == QLatin1Char('_')
|| character.isHighSurrogate()
|| character.isLowSurrogate();
}
int ActivationSequenceContextProcessor::findStartOfName(
const TextEditor::AssistInterface *assistInterface,
int startPosition)
{
int position = startPosition;
QChar character;
do {
character = m_assistInterface->characterAt(--position);
} while (character.isLetterOrNumber() || character == QLatin1Char('_'));
character = assistInterface->characterAt(--position);
} while (isValidIdentifierChar(character));
return position + 1;
}
void ActivationSequenceContextProcessor::goBackToStartOfName()
{
m_startOfNamePosition = findStartOfName(m_positionInDocument);
m_startOfNamePosition = findStartOfName(m_assistInterface, m_positionInDocument);
if (m_startOfNamePosition != m_positionInDocument)
m_textCursor.setPosition(m_startOfNamePosition);
......
......@@ -55,10 +55,13 @@ public:
const QTextCursor &textCursor_forTestOnly() const;
static int findStartOfName(const TextEditor::AssistInterface *assistInterface,
int startPosition);
static int skipPrecedingWhitespace(const TextEditor::AssistInterface *assistInterface,
int startPosition);
protected:
void process();
int findStartOfNonSpaceChar(int startPosition);
int findStartOfName(int startPosition);
void goBackToStartOfName();
void processActivationSequence();
void processStringLiteral();
......
......@@ -100,13 +100,15 @@ void ClangCompletionContextAnalyzer::analyze()
ClangCompletionContextAnalyzer::FunctionInfo
ClangCompletionContextAnalyzer::analyzeFunctionCall(int endOfOperator) const
{
int index = skipPrecedingWhitespace(endOfOperator);
int index = ActivationSequenceContextProcessor::skipPrecedingWhitespace(m_interface,
endOfOperator);
QTextCursor textCursor(m_interface->textDocument());
textCursor.setPosition(index);
ExpressionUnderCursor euc(m_languageFeatures);
index = euc.startOfFunctionCall(textCursor);
const int functionNameStart = findStartOfName(index);
const int functionNameStart = ActivationSequenceContextProcessor::findStartOfName(m_interface,
index);
QTextCursor textCursor2(m_interface->textDocument());
textCursor2.setPosition(functionNameStart);
......@@ -118,29 +120,6 @@ ClangCompletionContextAnalyzer::analyzeFunctionCall(int endOfOperator) const
return info;
}
int ClangCompletionContextAnalyzer::findStartOfName(int position) const
{
if (position == -1)
position = m_interface->position();
QChar chr;
do {
chr = m_interface->characterAt(--position);
// TODO: Check also chr.isHighSurrogate() / ch.isLowSurrogate()?
// See also CppTools::isValidFirstIdentifierChar
} while (chr.isLetterOrNumber() || chr == QLatin1Char('_'));
return position + 1;
}
int ClangCompletionContextAnalyzer::skipPrecedingWhitespace(int position) const
{
QTC_ASSERT(position >= 0, return position);
while (m_interface->characterAt(position - 1).isSpace())
--position;
return position;
}
void ClangCompletionContextAnalyzer::setActionAndClangPosition(CompletionAction action,
int position)
{
......
......@@ -72,9 +72,6 @@ private:
struct FunctionInfo { int functionNamePosition; QString functionName; };
FunctionInfo analyzeFunctionCall(int endOfExpression) const;
int findStartOfName(int position = -1) const;
int skipPrecedingWhitespace(int position) const;
void setActionAndClangPosition(CompletionAction action, int position);
void setAction(CompletionAction action);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment