Highlighting: Add highlighting style for punctuation

Currently only operators have their own style but not
punctuation tokens. Make possible to highlight both.

Task-number: QTCREATORBUG-20666
Change-Id: I9533e0f1bef65b86c4e4f5c9756571103584124b
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-08-22 17:25:12 +02:00
parent ccf2d848f4
commit 50e5aacb02
14 changed files with 93 additions and 79 deletions

View File

@@ -332,6 +332,9 @@ public:
inline bool isOperator() const inline bool isOperator() const
{ return f.kind >= T_FIRST_OPERATOR && f.kind <= T_LAST_OPERATOR; } { return f.kind >= T_FIRST_OPERATOR && f.kind <= T_LAST_OPERATOR; }
inline bool isPunctuation() const
{ return f.kind >= T_FIRST_PUNCTUATION && f.kind <= T_LAST_PUNCTUATION; }
inline bool isPunctuationOrOperator() const inline bool isPunctuationOrOperator() const
{ return f.kind >= T_FIRST_PUNCTUATION_OR_OPERATOR && f.kind <= T_LAST_PUNCTUATION_OR_OPERATOR; } { return f.kind >= T_FIRST_PUNCTUATION_OR_OPERATOR && f.kind <= T_LAST_PUNCTUATION_OR_OPERATOR; }

View File

@@ -86,6 +86,7 @@ enum class HighlightingType : quint8
Preprocessor, Preprocessor,
PreprocessorDefinition, PreprocessorDefinition,
PreprocessorExpansion, PreprocessorExpansion,
Punctuation,
Label, Label,
Declaration, Declaration,
FunctionDefinition, FunctionDefinition,

View File

@@ -53,6 +53,7 @@ static const char *highlightingTypeToCStringLiteral(HighlightingType type)
RETURN_TEXT_FOR_CASE(OutputArgument); RETURN_TEXT_FOR_CASE(OutputArgument);
RETURN_TEXT_FOR_CASE(PreprocessorDefinition); RETURN_TEXT_FOR_CASE(PreprocessorDefinition);
RETURN_TEXT_FOR_CASE(PreprocessorExpansion); RETURN_TEXT_FOR_CASE(PreprocessorExpansion);
RETURN_TEXT_FOR_CASE(Punctuation);
RETURN_TEXT_FOR_CASE(Namespace); RETURN_TEXT_FOR_CASE(Namespace);
RETURN_TEXT_FOR_CASE(Class); RETURN_TEXT_FOR_CASE(Class);
RETURN_TEXT_FOR_CASE(Struct); RETURN_TEXT_FOR_CASE(Struct);

View File

@@ -138,7 +138,7 @@ public:
return extraInfo.declaration return extraInfo.declaration
&& types.mainHighlightingType != HighlightingType::LocalVariable && types.mainHighlightingType != HighlightingType::LocalVariable
&& ((types.mainHighlightingType == HighlightingType::Operator) && (types.mixinHighlightingTypes.contains(HighlightingType::Operator)
== extraInfo.token.startsWith("operator")); == extraInfo.token.startsWith("operator"));
} }

View File

@@ -62,6 +62,8 @@ TextEditor::TextStyle toTextStyle(ClangBackEnd::HighlightingType type)
case HighlightingType::PreprocessorDefinition: case HighlightingType::PreprocessorDefinition:
case HighlightingType::PreprocessorExpansion: case HighlightingType::PreprocessorExpansion:
return TextEditor::C_PREPROCESSOR; return TextEditor::C_PREPROCESSOR;
case HighlightingType::Punctuation:
return TextEditor::C_PUNCTUATION;
case HighlightingType::Declaration: case HighlightingType::Declaration:
return TextEditor::C_DECLARATION; return TextEditor::C_DECLARATION;
case HighlightingType::FunctionDefinition: case HighlightingType::FunctionDefinition:

View File

@@ -235,7 +235,8 @@ int clangColumn(const QTextBlock &line, int cppEditorColumn)
ClangBackEnd::StorageClass storageClass = extraInfo.storageClass; ClangBackEnd::StorageClass storageClass = extraInfo.storageClass;
if (mainType == ClangBackEnd::HighlightingType::VirtualFunction if (mainType == ClangBackEnd::HighlightingType::VirtualFunction
|| mainType == ClangBackEnd::HighlightingType::Function || mainType == ClangBackEnd::HighlightingType::Function
|| mainType == ClangBackEnd::HighlightingType::Operator) { || token.types.mixinHighlightingTypes.contains(
ClangBackEnd::HighlightingType::Operator)) {
if (storageClass != ClangBackEnd::StorageClass::Static) { if (storageClass != ClangBackEnd::StorageClass::Static) {
switch (access) { switch (access) {
case ClangBackEnd::AccessSpecifier::Public: case ClangBackEnd::AccessSpecifier::Public:

View File

@@ -203,6 +203,8 @@ void CppHighlighter::highlightBlock(const QString &text)
formatForCategory(C_PRIMITIVE_TYPE)); formatForCategory(C_PRIMITIVE_TYPE));
} else if (tk.isOperator()) { } else if (tk.isOperator()) {
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_OPERATOR)); setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_OPERATOR));
} else if (tk.isPunctuation()) {
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_PUNCTUATION));
} else if (i == 0 && tokens.size() > 1 && tk.is(T_IDENTIFIER) && tokens.at(1).is(T_COLON)) { } else if (i == 0 && tokens.size() > 1 && tk.is(T_IDENTIFIER) && tokens.at(1).is(T_COLON)) {
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_LABEL)); setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_LABEL));
} else if (tk.is(T_IDENTIFIER)) { } else if (tk.is(T_IDENTIFIER)) {

View File

@@ -60,6 +60,7 @@ enum TextStyle : quint8 {
C_PRIMITIVE_TYPE, C_PRIMITIVE_TYPE,
C_OPERATOR, C_OPERATOR,
C_OVERLOADED_OPERATOR, C_OVERLOADED_OPERATOR,
C_PUNCTUATION,
C_PREPROCESSOR, C_PREPROCESSOR,
C_LABEL, C_LABEL,
C_COMMENT, C_COMMENT,

View File

@@ -224,9 +224,16 @@ TextEditorSettings::TextEditorSettings()
formatDescr.emplace_back(C_KEYWORD, tr("Keyword"), formatDescr.emplace_back(C_KEYWORD, tr("Keyword"),
tr("Reserved keywords of the programming language except " tr("Reserved keywords of the programming language except "
"keywords denoting primitive types."), Qt::darkYellow); "keywords denoting primitive types."), Qt::darkYellow);
formatDescr.emplace_back(C_PUNCTUATION, tr("Punctuation"),
tr("Punctuation excluding operators."));
formatDescr.emplace_back(C_OPERATOR, tr("Operator"), formatDescr.emplace_back(C_OPERATOR, tr("Operator"),
tr("Non user-defined language operators.\n" tr("Non user-defined language operators.\n"
"To style user-defined operators, use Overloaded Operator.")); "To style user-defined operators, use Overloaded Operator."),
Format::createMixinFormat());
formatDescr.emplace_back(C_OVERLOADED_OPERATOR,
tr("Overloaded Operators"),
tr("Calls and declarations of overloaded (user-defined) operators."),
Format::createMixinFormat());
formatDescr.emplace_back(C_PREPROCESSOR, tr("Preprocessor"), formatDescr.emplace_back(C_PREPROCESSOR, tr("Preprocessor"),
tr("Preprocessor directives."), Qt::darkBlue); tr("Preprocessor directives."), Qt::darkBlue);
formatDescr.emplace_back(C_LABEL, tr("Label"), tr("Labels for goto statements."), formatDescr.emplace_back(C_LABEL, tr("Label"), tr("Labels for goto statements."),
@@ -313,10 +320,6 @@ TextEditorSettings::TextEditorSettings()
QColor(255, 190, 0), QColor(255, 190, 0),
QTextCharFormat::DotLine, QTextCharFormat::DotLine,
FormatDescription::ShowUnderlineControl); FormatDescription::ShowUnderlineControl);
formatDescr.emplace_back(C_OVERLOADED_OPERATOR,
tr("Overloaded Operators"),
tr("Calls and declarations of overloaded (user-defined) operators."),
Format::createMixinFormat());
Format declarationFormat = Format::createMixinFormat(); Format declarationFormat = Format::createMixinFormat();
declarationFormat.setBold(true); declarationFormat.setBold(true);
formatDescr.emplace_back(C_DECLARATION, formatDescr.emplace_back(C_DECLARATION,

View File

@@ -243,7 +243,7 @@ void FullTokenInfo::overloadedOperatorKind()
{ {
TokenInfo::overloadedOperatorKind(); TokenInfo::overloadedOperatorKind();
if (m_types.mixinHighlightingTypes.front() != HighlightingType::OverloadedOperator) if (!m_types.mixinHighlightingTypes.contains(HighlightingType::OverloadedOperator))
return; return;
// Overloaded operator // Overloaded operator

View File

@@ -529,13 +529,13 @@ void TokenInfo::overloadedOperatorKind()
if (inOperatorDeclaration && !isTokenPartOfOperator(declarationCursor, m_cxToken)) if (inOperatorDeclaration && !isTokenPartOfOperator(declarationCursor, m_cxToken))
return; return;
if (m_types.mainHighlightingType == HighlightingType::Invalid) m_types.mixinHighlightingTypes.push_back(HighlightingType::Operator);
m_types.mainHighlightingType = HighlightingType::Operator;
m_types.mixinHighlightingTypes.push_back(HighlightingType::OverloadedOperator); m_types.mixinHighlightingTypes.push_back(HighlightingType::OverloadedOperator);
} }
void TokenInfo::punctuationOrOperatorKind() void TokenInfo::punctuationOrOperatorKind()
{ {
m_types.mainHighlightingType = HighlightingType::Punctuation;
auto kind = m_originalCursor.kind(); auto kind = m_originalCursor.kind();
switch (kind) { switch (kind) {
case CXCursor_CallExpr: case CXCursor_CallExpr:
@@ -557,9 +557,7 @@ void TokenInfo::punctuationOrOperatorKind()
case CXCursor_BinaryOperator: case CXCursor_BinaryOperator:
case CXCursor_CompoundAssignOperator: case CXCursor_CompoundAssignOperator:
case CXCursor_ConditionalOperator: case CXCursor_ConditionalOperator:
m_types.mainHighlightingType = HighlightingType::Operator; m_types.mixinHighlightingTypes.push_back(HighlightingType::Operator);
break;
default:
break; break;
} }

View File

@@ -672,4 +672,5 @@ int signalSlotTest() {
SIGNAL(something(QString)); SIGNAL(something(QString));
SLOT(something(QString)); SLOT(something(QString));
SIGNAL(something(QString (*func1)(QString))); SIGNAL(something(QString (*func1)(QString)));
1 == 2;
} }

View File

@@ -518,6 +518,7 @@ static const char *highlightingTypeToCStringLiteral(HighlightingType type)
RETURN_TEXT_FOR_CASE(PreprocessorDefinition); RETURN_TEXT_FOR_CASE(PreprocessorDefinition);
RETURN_TEXT_FOR_CASE(PreprocessorExpansion); RETURN_TEXT_FOR_CASE(PreprocessorExpansion);
RETURN_TEXT_FOR_CASE(PrimitiveType); RETURN_TEXT_FOR_CASE(PrimitiveType);
RETURN_TEXT_FOR_CASE(Punctuation);
RETURN_TEXT_FOR_CASE(Declaration); RETURN_TEXT_FOR_CASE(Declaration);
RETURN_TEXT_FOR_CASE(Namespace); RETURN_TEXT_FOR_CASE(Namespace);
RETURN_TEXT_FOR_CASE(Class); RETURN_TEXT_FOR_CASE(Class);

View File

@@ -588,64 +588,64 @@ TEST_F(TokenProcessor, OverriddenPlusOperatorDeclaration)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(220, 67)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(220, 67));
ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
} }
TEST_F(TokenProcessor, CallToOverriddenPlusOperator) TEST_F(TokenProcessor, CallToOverriddenPlusOperator)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(224, 49)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(224, 49));
ASSERT_THAT(infos[6], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[6], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
} }
TEST_F(TokenProcessor, CallToOverriddenPlusAssignOperator) TEST_F(TokenProcessor, CallToOverriddenPlusAssignOperator)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(226, 24)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(226, 24));
ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
} }
TEST_F(TokenProcessor, OverriddenStarOperatorMemberDefinition) TEST_F(TokenProcessor, OverriddenStarOperatorMemberDefinition)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(604, 26)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(604, 26));
ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
} }
TEST_F(TokenProcessor, OverriddenStarOperatorNonMemberDefinition) TEST_F(TokenProcessor, OverriddenStarOperatorNonMemberDefinition)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(607, 29)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(607, 29));
ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
} }
TEST_F(TokenProcessor, IntegerCallToOverriddenBinaryOperator) TEST_F(TokenProcessor, IntegerCallToOverriddenBinaryOperator)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(613, 9)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(613, 9));
ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
} }
TEST_F(TokenProcessor, FloatCallToOverriddenBinaryOperator) TEST_F(TokenProcessor, FloatCallToOverriddenBinaryOperator)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(614, 9)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(614, 9));
ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
} }
TEST_F(TokenProcessor, LeftShiftAssignmentOperatorMemberDefinition) TEST_F(TokenProcessor, LeftShiftAssignmentOperatorMemberDefinition)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(618, 32)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(618, 32));
ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); // ( is a punctuation. ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Punctuation)); // ( is a punctuation.
} }
TEST_F(TokenProcessor, CalledLeftShiftAssignmentOperator) TEST_F(TokenProcessor, CalledLeftShiftAssignmentOperator)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(629, 18)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(629, 18));
ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::NumberLiteral)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::NumberLiteral));
} }
@@ -653,48 +653,48 @@ TEST_F(TokenProcessor, FunctionCallOperatorMemberDefinition)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(619, 29)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(619, 29));
ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
ASSERT_THAT(infos[3], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[3], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Invalid)); // ( is a punctuation. ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Punctuation)); // ( is a punctuation.
} }
TEST_F(TokenProcessor, CalledFunctionCallOperator) TEST_F(TokenProcessor, CalledFunctionCallOperator)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(632, 16)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(632, 16));
ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
ASSERT_THAT(infos[3], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[3], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
} }
TEST_F(TokenProcessor, AccessOperatorMemberDefinition) TEST_F(TokenProcessor, AccessOperatorMemberDefinition)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(620, 38)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(620, 38));
ASSERT_THAT(infos[3], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[3], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
ASSERT_THAT(infos[4], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[4], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); // ( is a punctuation. ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Punctuation)); // ( is a punctuation.
} }
TEST_F(TokenProcessor, CalledAccessOperator) TEST_F(TokenProcessor, CalledAccessOperator)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(633, 16)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(633, 16));
ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
ASSERT_THAT(infos[3], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[3], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator));
} }
TEST_F(TokenProcessor, NewOperatorMemberDefinition) TEST_F(TokenProcessor, NewOperatorMemberDefinition)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(621, 39)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(621, 39));
ASSERT_THAT(infos[3], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); ASSERT_THAT(infos[3], HasThreeTypes(HighlightingType::Keyword, HighlightingType::Operator, HighlightingType::OverloadedOperator));
ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Invalid)); // ( is a punctuation. ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Punctuation)); // ( is a punctuation.
} }
TEST_F(TokenProcessor, CalledNewOperator) TEST_F(TokenProcessor, CalledNewOperator)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(635, 34)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(635, 34));
ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); // = is not marked. ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Punctuation)); // = is not marked.
// CLANG-UPGRADE-CHECK: Check if 'new' keyword usage cursor correctly returns referenced() cursor // CLANG-UPGRADE-CHECK: Check if 'new' keyword usage cursor correctly returns referenced() cursor
// and uncomment this test in that case. // and uncomment this test in that case.
// ASSERT_THAT(infos[4], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); // new // ASSERT_THAT(infos[4], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); // new
@@ -704,8 +704,8 @@ TEST_F(TokenProcessor, DeleteOperatorMemberDefinition)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(622, 37)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(622, 37));
ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); // delete ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::Keyword, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // delete
ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); // ( is a punctuation. ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Punctuation)); // ( is a punctuation.
} }
TEST_F(TokenProcessor, CalledDeleteOperator) TEST_F(TokenProcessor, CalledDeleteOperator)
@@ -716,24 +716,24 @@ TEST_F(TokenProcessor, CalledDeleteOperator)
// and uncomment this test in that case. // and uncomment this test in that case.
// ASSERT_THAT(infos[0], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); // delete // ASSERT_THAT(infos[0], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); // delete
ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable));
ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Invalid)); // ; is a punctuation. ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Punctuation)); // ; is a punctuation.
} }
TEST_F(TokenProcessor, NewArrayOperatorMemberDefinition) TEST_F(TokenProcessor, NewArrayOperatorMemberDefinition)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(623, 41)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(623, 41));
ASSERT_THAT(infos[3], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); // new ASSERT_THAT(infos[3], HasThreeTypes(HighlightingType::Keyword, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // new
ASSERT_THAT(infos[4], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); // [ ASSERT_THAT(infos[4], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // [
ASSERT_THAT(infos[5], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); // ] ASSERT_THAT(infos[5], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // ]
ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Invalid)); // ( is a punctuation. ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Punctuation)); // ( is a punctuation.
} }
TEST_F(TokenProcessor, CalledNewArrayOperator) TEST_F(TokenProcessor, CalledNewArrayOperator)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(637, 34)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(637, 34));
ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); // = is not marked. ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Punctuation)); // = is not marked.
// CLANG-UPGRADE-CHECK: Check if 'new' keyword usage cursor correctly returns referenced() cursor // CLANG-UPGRADE-CHECK: Check if 'new' keyword usage cursor correctly returns referenced() cursor
// and uncomment this test in that case. // and uncomment this test in that case.
// ASSERT_THAT(infos[4], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); // new // ASSERT_THAT(infos[4], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); // new
@@ -743,10 +743,10 @@ TEST_F(TokenProcessor, DeleteArrayOperatorMemberDefinition)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(624, 39)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(624, 39));
ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); // delete ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::Keyword, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // delete
ASSERT_THAT(infos[3], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); // [ ASSERT_THAT(infos[3], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // [
ASSERT_THAT(infos[4], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); // ] ASSERT_THAT(infos[4], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // ]
ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); // ( is a punctuation. ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Punctuation)); // ( is a punctuation.
} }
TEST_F(TokenProcessor, CalledDeleteArrayOperator) TEST_F(TokenProcessor, CalledDeleteArrayOperator)
@@ -769,120 +769,120 @@ TEST_F(TokenProcessor, ParenthesisOperatorWithoutArguments)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(654, 25)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(654, 25));
ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); // operator ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Keyword, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // operator
ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); // '(' ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // '('
ASSERT_THAT(infos[3], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); // ')' ASSERT_THAT(infos[3], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // ')'
ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Invalid)); // second '(' is a punctuation ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Punctuation)); // second '(' is a punctuation
} }
TEST_F(TokenProcessor, CalledParenthesisOperatorWithoutArguments) TEST_F(TokenProcessor, CalledParenthesisOperatorWithoutArguments)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(662, 14)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(662, 14));
ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); // '(' ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // '('
ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); // ')' ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // ')'
} }
TEST_F(TokenProcessor, OperatorWithOnePunctuationTokenWithoutArguments) TEST_F(TokenProcessor, OperatorWithOnePunctuationTokenWithoutArguments)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(655, 25)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(655, 25));
ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); // operator ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Keyword, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // operator
ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); // '*' ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // '*'
ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); // ( is a punctuation ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Punctuation)); // ( is a punctuation
} }
TEST_F(TokenProcessor, CalledOperatorWithOnePunctuationTokenWithoutArguments) TEST_F(TokenProcessor, CalledOperatorWithOnePunctuationTokenWithoutArguments)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(663, 13)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(663, 13));
ASSERT_THAT(infos[0], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); // '*' ASSERT_THAT(infos[0], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // '*'
} }
TEST_F(TokenProcessor, EqualsOperatorOverload) TEST_F(TokenProcessor, EqualsOperatorOverload)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(656, 43)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(656, 43));
ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Keyword, HighlightingType::OverloadedOperator)); // operator ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Keyword, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // operator
ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); // '=' ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // '='
ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); // ( is a punctuation ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Punctuation)); // ( is a punctuation
} }
TEST_F(TokenProcessor, CalledEqualsOperatorOverload) TEST_F(TokenProcessor, CalledEqualsOperatorOverload)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(664, 23)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(664, 23));
ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Operator, HighlightingType::OverloadedOperator)); // '=' ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Punctuation, HighlightingType::Operator, HighlightingType::OverloadedOperator)); // '='
} }
TEST_F(TokenProcessor, LeftParenthesisIsAPunctuation) TEST_F(TokenProcessor, LeftParenthesisIsAPunctuation)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(607, 29)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(607, 29));
ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Punctuation));
} }
TEST_F(TokenProcessor, SeparatingCommaIsAPunctuation) TEST_F(TokenProcessor, SeparatingCommaIsAPunctuation)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(607, 29)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(607, 29));
ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Punctuation));
} }
TEST_F(TokenProcessor, RightParenthesisIsAPunctuation) TEST_F(TokenProcessor, RightParenthesisIsAPunctuation)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(607, 29)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(607, 29));
ASSERT_THAT(infos[7], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[7], HasOnlyType(HighlightingType::Punctuation));
} }
TEST_F(TokenProcessor, CurlyLeftParenthesisIsAPunctuation) TEST_F(TokenProcessor, CurlyLeftParenthesisIsAPunctuation)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(607, 29)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(607, 29));
ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::Punctuation));
} }
TEST_F(TokenProcessor, CurlyRightParenthesisIsAPunctuation) TEST_F(TokenProcessor, CurlyRightParenthesisIsAPunctuation)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(607, 29)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(607, 29));
ASSERT_THAT(infos[9], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[9], HasOnlyType(HighlightingType::Punctuation));
} }
TEST_F(TokenProcessor, OperatorColon) TEST_F(TokenProcessor, OperatorColon)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(668, 28)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(668, 28));
ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Operator)); ASSERT_THAT(infos[6], HasTwoTypes(HighlightingType::Punctuation, HighlightingType::Operator));
} }
TEST_F(TokenProcessor, PunctuationColon) TEST_F(TokenProcessor, PunctuationColon)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(133, 10)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(133, 10));
ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Punctuation));
} }
TEST_F(TokenProcessor, LessThanOperator) TEST_F(TokenProcessor, LessThanOperator)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(668, 28)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(668, 28));
ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Operator)); ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::Punctuation, HighlightingType::Operator));
} }
TEST_F(TokenProcessor, LessThanPunctuation) TEST_F(TokenProcessor, LessThanPunctuation)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(247, 19)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(247, 19));
ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Punctuation));
} }
TEST_F(TokenProcessor, GreaterThanPunctuation) TEST_F(TokenProcessor, GreaterThanPunctuation)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(247, 19)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(247, 19));
ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Punctuation));
} }
TEST_F(TokenProcessor, Comment) TEST_F(TokenProcessor, Comment)
@@ -1136,13 +1136,13 @@ TEST_F(TokenProcessor, StaticCastIsKeyword)
ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Keyword)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Keyword));
} }
TEST_F(TokenProcessor, StaticCastPunctationIsInvalid) TEST_F(TokenProcessor, StaticCastPunctation)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(328, 64)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(328, 64));
ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Punctuation));
ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Punctuation));
ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Punctuation));
} }
TEST_F(TokenProcessor, TypeInReinterpretCast) TEST_F(TokenProcessor, TypeInReinterpretCast)
@@ -1240,14 +1240,14 @@ TEST_F(TokenProcessor, NoOperator)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(389, 24)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(389, 24));
ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Punctuation));
} }
TEST_F(TokenProcessor, ScopeOperator) TEST_F(TokenProcessor, ScopeOperator)
{ {
const auto infos = translationUnit.tokenInfosInRange(sourceRange(400, 33)); const auto infos = translationUnit.tokenInfosInRange(sourceRange(400, 33));
ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Punctuation));
} }
TEST_F(TokenProcessor, TemplateClassNamespace) TEST_F(TokenProcessor, TemplateClassNamespace)
@@ -1652,7 +1652,7 @@ TEST_F(TokenProcessor, LexicalParentIndex)
const auto containers = translationUnit.fullTokenInfosInRange( const auto containers = translationUnit.fullTokenInfosInRange(
translationUnit.sourceRange(50, 1, 53, 3)).toTokenInfoContainers(); translationUnit.sourceRange(50, 1, 53, 3)).toTokenInfoContainers();
ASSERT_THAT(containers[3].extraInfo.lexicalParentIndex, 1); ASSERT_THAT(containers[4].extraInfo.lexicalParentIndex, 1);
} }
TEST_F(TokenProcessor, QtOldStyleSignal) TEST_F(TokenProcessor, QtOldStyleSignal)