forked from qt-creator/qt-creator
Clang: Remove duplicated functions
Change-Id: I0758fc06843363d58faa835238a587095c9eb6de Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
@@ -97,7 +97,7 @@ void ActivationSequenceContextProcessor::process()
|
|||||||
|
|
||||||
void ActivationSequenceContextProcessor::processActivationSequence()
|
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);
|
const auto activationSequence = m_assistInterface->textAt(nonSpacePosition - 3, 3);
|
||||||
ActivationSequenceProcessor activationSequenceProcessor(activationSequence,
|
ActivationSequenceProcessor activationSequenceProcessor(activationSequence,
|
||||||
nonSpacePosition,
|
nonSpacePosition,
|
||||||
@@ -228,28 +228,40 @@ void ActivationSequenceContextProcessor::resetPositionsForEOFCompletionKind()
|
|||||||
m_operatorStartPosition = m_positionInDocument;
|
m_operatorStartPosition = m_positionInDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ActivationSequenceContextProcessor::findStartOfNonSpaceChar(int startPosition)
|
int ActivationSequenceContextProcessor::skipPrecedingWhitespace(
|
||||||
|
const TextEditor::AssistInterface *assistInterface,
|
||||||
|
int startPosition)
|
||||||
{
|
{
|
||||||
int position = startPosition;
|
int position = startPosition;
|
||||||
while (m_assistInterface->characterAt(position - 1).isSpace())
|
while (assistInterface->characterAt(position - 1).isSpace())
|
||||||
--position;
|
--position;
|
||||||
return 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;
|
int position = startPosition;
|
||||||
QChar character;
|
QChar character;
|
||||||
do {
|
do {
|
||||||
character = m_assistInterface->characterAt(--position);
|
character = assistInterface->characterAt(--position);
|
||||||
} while (character.isLetterOrNumber() || character == QLatin1Char('_'));
|
} while (isValidIdentifierChar(character));
|
||||||
|
|
||||||
return position + 1;
|
return position + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActivationSequenceContextProcessor::goBackToStartOfName()
|
void ActivationSequenceContextProcessor::goBackToStartOfName()
|
||||||
{
|
{
|
||||||
m_startOfNamePosition = findStartOfName(m_positionInDocument);
|
m_startOfNamePosition = findStartOfName(m_assistInterface, m_positionInDocument);
|
||||||
|
|
||||||
if (m_startOfNamePosition != m_positionInDocument)
|
if (m_startOfNamePosition != m_positionInDocument)
|
||||||
m_textCursor.setPosition(m_startOfNamePosition);
|
m_textCursor.setPosition(m_startOfNamePosition);
|
||||||
|
|||||||
@@ -55,10 +55,13 @@ public:
|
|||||||
|
|
||||||
const QTextCursor &textCursor_forTestOnly() const;
|
const QTextCursor &textCursor_forTestOnly() const;
|
||||||
|
|
||||||
|
static int findStartOfName(const TextEditor::AssistInterface *assistInterface,
|
||||||
|
int startPosition);
|
||||||
|
static int skipPrecedingWhitespace(const TextEditor::AssistInterface *assistInterface,
|
||||||
|
int startPosition);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void process();
|
void process();
|
||||||
int findStartOfNonSpaceChar(int startPosition);
|
|
||||||
int findStartOfName(int startPosition);
|
|
||||||
void goBackToStartOfName();
|
void goBackToStartOfName();
|
||||||
void processActivationSequence();
|
void processActivationSequence();
|
||||||
void processStringLiteral();
|
void processStringLiteral();
|
||||||
|
|||||||
@@ -100,13 +100,15 @@ void ClangCompletionContextAnalyzer::analyze()
|
|||||||
ClangCompletionContextAnalyzer::FunctionInfo
|
ClangCompletionContextAnalyzer::FunctionInfo
|
||||||
ClangCompletionContextAnalyzer::analyzeFunctionCall(int endOfOperator) const
|
ClangCompletionContextAnalyzer::analyzeFunctionCall(int endOfOperator) const
|
||||||
{
|
{
|
||||||
int index = skipPrecedingWhitespace(endOfOperator);
|
int index = ActivationSequenceContextProcessor::skipPrecedingWhitespace(m_interface,
|
||||||
|
endOfOperator);
|
||||||
QTextCursor textCursor(m_interface->textDocument());
|
QTextCursor textCursor(m_interface->textDocument());
|
||||||
textCursor.setPosition(index);
|
textCursor.setPosition(index);
|
||||||
|
|
||||||
ExpressionUnderCursor euc(m_languageFeatures);
|
ExpressionUnderCursor euc(m_languageFeatures);
|
||||||
index = euc.startOfFunctionCall(textCursor);
|
index = euc.startOfFunctionCall(textCursor);
|
||||||
const int functionNameStart = findStartOfName(index);
|
const int functionNameStart = ActivationSequenceContextProcessor::findStartOfName(m_interface,
|
||||||
|
index);
|
||||||
|
|
||||||
QTextCursor textCursor2(m_interface->textDocument());
|
QTextCursor textCursor2(m_interface->textDocument());
|
||||||
textCursor2.setPosition(functionNameStart);
|
textCursor2.setPosition(functionNameStart);
|
||||||
@@ -118,29 +120,6 @@ ClangCompletionContextAnalyzer::analyzeFunctionCall(int endOfOperator) const
|
|||||||
return info;
|
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,
|
void ClangCompletionContextAnalyzer::setActionAndClangPosition(CompletionAction action,
|
||||||
int position)
|
int position)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -72,9 +72,6 @@ private:
|
|||||||
struct FunctionInfo { int functionNamePosition; QString functionName; };
|
struct FunctionInfo { int functionNamePosition; QString functionName; };
|
||||||
FunctionInfo analyzeFunctionCall(int endOfExpression) const;
|
FunctionInfo analyzeFunctionCall(int endOfExpression) const;
|
||||||
|
|
||||||
int findStartOfName(int position = -1) const;
|
|
||||||
int skipPrecedingWhitespace(int position) const;
|
|
||||||
|
|
||||||
void setActionAndClangPosition(CompletionAction action, int position);
|
void setActionAndClangPosition(CompletionAction action, int position);
|
||||||
void setAction(CompletionAction action);
|
void setAction(CompletionAction action);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user