aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tools/clangbackend/source/fulltokeninfo.cpp13
-rw-r--r--tests/unit/unittest/data/highlightingmarks.cpp32
-rw-r--r--tests/unit/unittest/tokenprocessor-test.cpp36
3 files changed, 76 insertions, 5 deletions
diff --git a/src/tools/clangbackend/source/fulltokeninfo.cpp b/src/tools/clangbackend/source/fulltokeninfo.cpp
index fd59d25766..58b8398c97 100644
--- a/src/tools/clangbackend/source/fulltokeninfo.cpp
+++ b/src/tools/clangbackend/source/fulltokeninfo.cpp
@@ -106,13 +106,16 @@ static Utf8String getPropertyType(const SourceLocation &location, uint propertyP
uint offset;
clang_getFileLocation(location.cx(), &cxFile, nullptr, nullptr, &offset);
const char *const contents = clang_getFileContents(location.tu(), cxFile, nullptr);
- const char *const lineContents = &contents[offset - propertyPosition];
-
- const char *typeStart = std::strstr(lineContents, "Q_PROPERTY") + 10;
+ const int keywordOffset = QByteArray::fromRawData(contents, propertyPosition)
+ .lastIndexOf("Q_PROPERTY");
+ if (keywordOffset == -1)
+ return {};
+ const char * const keywordStart = contents + keywordOffset;
+ const char *typeStart = keywordStart + 10;
typeStart += std::strspn(typeStart, "( \t\n\r");
- if (typeStart - lineContents >= propertyPosition)
+ if (typeStart - keywordStart >= propertyPosition)
return Utf8String();
- auto typeEnd = std::find_if(std::reverse_iterator<const char*>(lineContents + propertyPosition),
+ auto typeEnd = std::find_if(std::reverse_iterator<const char*>(keywordStart + propertyPosition),
std::reverse_iterator<const char*>(typeStart),
Utils::unequalTo(' '));
diff --git a/tests/unit/unittest/data/highlightingmarks.cpp b/tests/unit/unittest/data/highlightingmarks.cpp
index 2476cabfb2..33dfbe91de 100644
--- a/tests/unit/unittest/data/highlightingmarks.cpp
+++ b/tests/unit/unittest/data/highlightingmarks.cpp
@@ -699,3 +699,35 @@ private:
template <int i, int j> struct S { };
template <int i> using spec = S<i, 1>;
spec<2> s;
+
+class Property {
+ Q_PROPERTY(
+
+ const
+
+ volatile
+
+ unsigned
+
+ long
+
+ long
+
+ *
+
+ prop
+
+ READ
+
+ getProp
+
+ WRITE
+
+ setProp
+
+ NOTIFY
+
+ propChanged
+
+ )
+};
diff --git a/tests/unit/unittest/tokenprocessor-test.cpp b/tests/unit/unittest/tokenprocessor-test.cpp
index 786b980f22..37c76d8ce6 100644
--- a/tests/unit/unittest/tokenprocessor-test.cpp
+++ b/tests/unit/unittest/tokenprocessor-test.cpp
@@ -146,6 +146,7 @@ public:
static void TearDownTestCase();
SourceRange sourceRange(uint line, uint columnEnd) const;
+ SourceRange sourceRangeMultiLine(uint firstLine, uint lastLine, uint columnEnd) const;
protected:
static Data *d;
@@ -1574,6 +1575,14 @@ TEST_F(TokenProcessor, QtPropertyName)
ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::QtProperty));
}
+TEST_F(TokenProcessor, QtPropertyNameMultiLine)
+{
+ const auto infos = translationUnit.fullTokenInfosInRange(sourceRangeMultiLine(704, 732, 14));
+
+ ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::PreprocessorExpansion));
+ ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::QtProperty));
+}
+
TEST_F(TokenProcessor, QtPropertyFunction)
{
const auto infos = translationUnit.fullTokenInfosInRange(sourceRange(599, 103));
@@ -1581,6 +1590,13 @@ TEST_F(TokenProcessor, QtPropertyFunction)
ASSERT_THAT(infos[10], HasOnlyType(HighlightingType::Function));
}
+TEST_F(TokenProcessor, QtPropertyFunctionMultiLine)
+{
+ const auto infos = translationUnit.fullTokenInfosInRange(sourceRangeMultiLine(704, 732, 14));
+
+ ASSERT_THAT(infos[10], HasOnlyType(HighlightingType::Function));
+}
+
TEST_F(TokenProcessor, QtPropertyInternalKeyword)
{
const auto infos = translationUnit.fullTokenInfosInRange(sourceRange(599, 103));
@@ -1588,6 +1604,13 @@ TEST_F(TokenProcessor, QtPropertyInternalKeyword)
ASSERT_THAT(infos[9], HasOnlyType(HighlightingType::Invalid));
}
+TEST_F(TokenProcessor, QtPropertyInternalKeywordMultiLine)
+{
+ const auto infos = translationUnit.fullTokenInfosInRange(sourceRangeMultiLine(704, 732, 14));
+
+ ASSERT_THAT(infos[9], HasOnlyType(HighlightingType::Invalid));
+}
+
TEST_F(TokenProcessor, QtPropertyLastToken)
{
const auto infos = translationUnit.fullTokenInfosInRange(sourceRange(599, 103));
@@ -1595,6 +1618,13 @@ TEST_F(TokenProcessor, QtPropertyLastToken)
ASSERT_THAT(infos[14], HasOnlyType(HighlightingType::Function));
}
+TEST_F(TokenProcessor, QtPropertyLastTokenMultiLine)
+{
+ const auto infos = translationUnit.fullTokenInfosInRange(sourceRangeMultiLine(704, 732, 14));
+
+ ASSERT_THAT(infos[14], HasOnlyType(HighlightingType::Function));
+}
+
TEST_F(TokenProcessor, QtPropertyType)
{
const auto infos = translationUnit.fullTokenInfosInRange(sourceRange(600, 46));
@@ -1747,4 +1777,10 @@ ClangBackEnd::SourceRange TokenProcessor::sourceRange(uint line, uint columnEnd)
return translationUnit.sourceRange(line, 1, line, columnEnd);
}
+ClangBackEnd::SourceRange TokenProcessor::sourceRangeMultiLine(uint firstLine, uint lastLine,
+ uint columnEnd) const
+{
+ return translationUnit.sourceRange(firstLine, 1, lastLine, columnEnd);
+}
+
}