forked from qt-creator/qt-creator
Make QmlJS(Tools) build with Qt5 & Qt6
Port from QStringRef to QStringView Change-Id: I472d16f20e40ca52b8e5d481850a6bd8a1a38f3b Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -74,7 +74,7 @@ static bool isDerivedFromTestCase(QmlJS::AST::UiQualifiedId *id, const QmlJS::Do
|
||||
if (auto prototype = val->prototype()) {
|
||||
if (auto qmlPrototypeRef = prototype->asQmlPrototypeReference()) {
|
||||
if (auto qmlTypeName = qmlPrototypeRef->qmlTypeName()) {
|
||||
if (qmlTypeName->name == "TestCase") {
|
||||
if (qmlTypeName->name == QLatin1String("TestCase")) {
|
||||
if (auto astObjVal = val->asAstObjectValue())
|
||||
return documentImportsQtTest(astObjVal->document());
|
||||
}
|
||||
@@ -87,9 +87,9 @@ static bool isDerivedFromTestCase(QmlJS::AST::UiQualifiedId *id, const QmlJS::Do
|
||||
|
||||
bool TestQmlVisitor::visit(QmlJS::AST::UiObjectDefinition *ast)
|
||||
{
|
||||
const QStringRef name = ast->qualifiedTypeNameId->name;
|
||||
const QStringView name = ast->qualifiedTypeNameId->name;
|
||||
m_objectIsTestStack.push(false);
|
||||
if (name != "TestCase") {
|
||||
if (name != QLatin1String("TestCase")) {
|
||||
if (!isDerivedFromTestCase(ast->qualifiedTypeNameId, m_currentDoc, m_snapshot))
|
||||
return true;
|
||||
} else if (!documentImportsQtTest(m_currentDoc.data())) {
|
||||
@@ -122,7 +122,7 @@ bool TestQmlVisitor::visit(QmlJS::AST::ExpressionStatement *ast)
|
||||
bool TestQmlVisitor::visit(QmlJS::AST::UiScriptBinding *ast)
|
||||
{
|
||||
if (m_objectIsTestStack.top())
|
||||
m_expectTestCaseName = ast->qualifiedId->name == "name";
|
||||
m_expectTestCaseName = ast->qualifiedId->name == QLatin1String("name");
|
||||
return m_expectTestCaseName;
|
||||
}
|
||||
|
||||
@@ -137,24 +137,22 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
|
||||
if (m_caseParseStack.isEmpty())
|
||||
return false;
|
||||
|
||||
const QStringRef name = ast->name;
|
||||
if (name.startsWith("test_")
|
||||
|| name.startsWith("benchmark_")
|
||||
|| name.endsWith("_data")
|
||||
|| specialFunctions.contains(name.toString())) {
|
||||
const QString name = ast->name.toString();
|
||||
if (name.startsWith("test_") || name.startsWith("benchmark_") || name.endsWith("_data")
|
||||
|| specialFunctions.contains(name)) {
|
||||
const auto sourceLocation = ast->firstSourceLocation();
|
||||
TestCodeLocationAndType locationAndType;
|
||||
locationAndType.m_name = m_currentDoc->fileName();
|
||||
locationAndType.m_line = sourceLocation.startLine;
|
||||
locationAndType.m_column = sourceLocation.startColumn - 1;
|
||||
if (specialFunctions.contains(name.toString()))
|
||||
if (specialFunctions.contains(name))
|
||||
locationAndType.m_type = TestTreeItem::TestSpecialFunction;
|
||||
else if (name.endsWith("_data"))
|
||||
locationAndType.m_type = TestTreeItem::TestDataFunction;
|
||||
else
|
||||
locationAndType.m_type = TestTreeItem::TestFunction;
|
||||
|
||||
const QString nameStr = name.toString();
|
||||
const QString nameStr = name;
|
||||
// identical test functions inside the same file are not working - will fail at runtime
|
||||
if (!Utils::anyOf(m_caseParseStack.top().m_functions,
|
||||
[nameStr, locationAndType](const QuickTestFunctionSpec func) {
|
||||
|
||||
@@ -1203,7 +1203,7 @@ void TextToModelMerger::syncNode(ModelNode &modelNode,
|
||||
if (property->type == AST::UiPublicMember::Signal)
|
||||
continue; // QML designer doesn't support this yet.
|
||||
|
||||
const QStringRef astName = property->name;
|
||||
const QStringView astName = property->name;
|
||||
QString astValue;
|
||||
if (property->statement)
|
||||
astValue = textAt(context->doc(),
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <qmljs/qmljsscanner.h>
|
||||
|
||||
#include <utils/porting.h>
|
||||
|
||||
#include <QChar>
|
||||
#include <QLatin1Char>
|
||||
#include <QTextDocument>
|
||||
@@ -119,7 +121,7 @@ static bool shouldInsertNewline(const QTextCursor &tc)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool isCompleteStringLiteral(const QStringRef &text)
|
||||
static bool isCompleteStringLiteral(const QStringView &text)
|
||||
{
|
||||
if (text.length() < 2)
|
||||
return false;
|
||||
@@ -173,7 +175,7 @@ bool AutoCompleter::contextAllowsAutoBrackets(const QTextCursor &cursor,
|
||||
|
||||
case Token::String: {
|
||||
const QString blockText = cursor.block().text();
|
||||
const QStringRef tokenText = blockText.midRef(token.offset, token.length);
|
||||
const QStringView tokenText = Utils::midView(blockText, token.offset, token.length);
|
||||
QChar quote = tokenText.at(0);
|
||||
// if a string literal doesn't start with a quote, it must be multiline
|
||||
if (quote != QLatin1Char('"') && quote != QLatin1Char('\'')) {
|
||||
@@ -217,7 +219,7 @@ bool AutoCompleter::contextAllowsAutoQuotes(const QTextCursor &cursor,
|
||||
|
||||
case Token::String: {
|
||||
const QString blockText = cursor.block().text();
|
||||
const QStringRef tokenText = blockText.midRef(token.offset, token.length);
|
||||
const QStringView tokenText = Utils::midView(blockText, token.offset, token.length);
|
||||
QChar quote = tokenText.at(0);
|
||||
// if a string literal doesn't start with a quote, it must be multiline
|
||||
if (quote != QLatin1Char('"') && quote != QLatin1Char('\'')) {
|
||||
|
||||
@@ -411,7 +411,7 @@ protected:
|
||||
{
|
||||
UiQualifiedId *id = qualifiedTypeNameId(member);
|
||||
if (id) {
|
||||
const QStringRef &name = id->name;
|
||||
const QStringView &name = id->name;
|
||||
if (!name.isEmpty() && name.at(0).isUpper())
|
||||
return true;
|
||||
}
|
||||
@@ -429,7 +429,7 @@ protected:
|
||||
else if (script->qualifiedId->next)
|
||||
return false;
|
||||
|
||||
const QStringRef &propertyName = script->qualifiedId->name;
|
||||
const QStringView &propertyName = script->qualifiedId->name;
|
||||
|
||||
if (propertyName == QLatin1String("id"))
|
||||
return true;
|
||||
|
||||
@@ -89,7 +89,7 @@ protected:
|
||||
QString text;
|
||||
for (; id; id = id->next) {
|
||||
if (!id->name.isEmpty())
|
||||
text += id->name;
|
||||
text += id->name.toString();
|
||||
else
|
||||
text += QLatin1Char('?');
|
||||
|
||||
@@ -174,7 +174,7 @@ protected:
|
||||
QString text;
|
||||
for (; id; id = id->next) {
|
||||
if (!id->name.isEmpty())
|
||||
text += id->name;
|
||||
text += id->name.toString();
|
||||
else
|
||||
text += QLatin1Char('?');
|
||||
|
||||
@@ -294,12 +294,12 @@ protected:
|
||||
init(&decl, ast);
|
||||
|
||||
decl.text.fill(QLatin1Char(' '), _depth);
|
||||
decl.text += ast->name;
|
||||
decl.text += ast->name.toString();
|
||||
|
||||
decl.text += QLatin1Char('(');
|
||||
for (FormalParameterList *it = ast->formals; it; it = it->next) {
|
||||
if (!it->element->bindingIdentifier.isEmpty())
|
||||
decl.text += it->element->bindingIdentifier;
|
||||
decl.text += it->element->bindingIdentifier.toString();
|
||||
|
||||
if (it->next)
|
||||
decl.text += QLatin1String(", ");
|
||||
@@ -319,7 +319,7 @@ protected:
|
||||
|
||||
Declaration decl;
|
||||
decl.text.fill(QLatin1Char(' '), _depth);
|
||||
decl.text += ast->bindingIdentifier;
|
||||
decl.text += ast->bindingIdentifier.toString();
|
||||
|
||||
const SourceLocation first = ast->identifierToken;
|
||||
decl.startLine = first.startLine;
|
||||
@@ -342,12 +342,12 @@ protected:
|
||||
init(&decl, ast);
|
||||
|
||||
decl.text.fill(QLatin1Char(' '), _depth);
|
||||
decl.text += field->name;
|
||||
decl.text += field->name.toString();
|
||||
|
||||
decl.text += QLatin1Char('(');
|
||||
for (FormalParameterList *it = funcExpr->formals; it; it = it->next) {
|
||||
if (!it->element->bindingIdentifier.isEmpty())
|
||||
decl.text += it->element->bindingIdentifier;
|
||||
decl.text += it->element->bindingIdentifier.toString();
|
||||
|
||||
if (it->next)
|
||||
decl.text += QLatin1String(", ");
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <QSet>
|
||||
|
||||
#include <utils/porting.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
using namespace QmlJS;
|
||||
@@ -75,7 +76,8 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
||||
break;
|
||||
|
||||
case Token::Comment:
|
||||
if (m_inMultilineComment && text.midRef(token.end() - 2, 2) == QLatin1String("*/")) {
|
||||
if (m_inMultilineComment
|
||||
&& Utils::midView(text, token.end() - 2, 2) == QLatin1String("*/")) {
|
||||
onClosingParenthesis(QLatin1Char('-'), token.end() - 1, index == tokens.size()-1);
|
||||
m_inMultilineComment = false;
|
||||
} else if (!m_inMultilineComment
|
||||
@@ -119,7 +121,7 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
||||
if (!m_qmlEnabled)
|
||||
break;
|
||||
|
||||
const QStringRef spell = text.midRef(token.offset, token.length);
|
||||
const QStringView spell = Utils::midView(text, token.offset, token.length);
|
||||
|
||||
if (maybeQmlKeyword(spell)) {
|
||||
// check the previous token
|
||||
@@ -129,25 +131,25 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (text.midRef(token.offset, token.length) == QLatin1String("enum")) {
|
||||
if (Utils::midView(text, token.offset, token.length) == QLatin1String("enum")) {
|
||||
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
|
||||
break;
|
||||
}
|
||||
} else if (index > 0 && maybeQmlBuiltinType(spell)) {
|
||||
const Token &previousToken = tokens.at(index - 1);
|
||||
if (previousToken.is(Token::Identifier)
|
||||
&& text.at(previousToken.offset) == QLatin1Char('p')
|
||||
&& text.midRef(previousToken.offset, previousToken.length)
|
||||
== QLatin1String("property")) {
|
||||
&& text.at(previousToken.offset) == QLatin1Char('p')
|
||||
&& Utils::midView(text, previousToken.offset, previousToken.length)
|
||||
== QLatin1String("property")) {
|
||||
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
|
||||
break;
|
||||
}
|
||||
} else if (index == 1) {
|
||||
const Token &previousToken = tokens.at(0);
|
||||
if (previousToken.is(Token::Identifier)
|
||||
&& text.at(previousToken.offset) == QLatin1Char('e')
|
||||
&& text.midRef(previousToken.offset, previousToken.length)
|
||||
== QLatin1String("enum")) {
|
||||
&& text.at(previousToken.offset) == QLatin1Char('e')
|
||||
&& Utils::midView(text, previousToken.offset, previousToken.length)
|
||||
== QLatin1String("enum")) {
|
||||
setFormat(token.offset, token.length, formatForCategory(C_ENUMERATION));
|
||||
break;
|
||||
}
|
||||
@@ -200,7 +202,7 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
||||
onBlockEnd(m_scanner.state());
|
||||
}
|
||||
|
||||
bool QmlJSHighlighter::maybeQmlKeyword(const QStringRef &text) const
|
||||
bool QmlJSHighlighter::maybeQmlKeyword(const QStringView &text) const
|
||||
{
|
||||
if (text.isEmpty())
|
||||
return false;
|
||||
@@ -226,7 +228,7 @@ bool QmlJSHighlighter::maybeQmlKeyword(const QStringRef &text) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QmlJSHighlighter::maybeQmlBuiltinType(const QStringRef &text) const
|
||||
bool QmlJSHighlighter::maybeQmlBuiltinType(const QStringView &text) const
|
||||
{
|
||||
if (text.isEmpty())
|
||||
return false;
|
||||
|
||||
@@ -56,8 +56,8 @@ protected:
|
||||
void onOpeningParenthesis(QChar parenthesis, int pos, bool atStart);
|
||||
void onClosingParenthesis(QChar parenthesis, int pos, bool atEnd);
|
||||
|
||||
bool maybeQmlKeyword(const QStringRef &text) const;
|
||||
bool maybeQmlBuiltinType(const QStringRef &text) const;
|
||||
bool maybeQmlKeyword(const QStringView &text) const;
|
||||
bool maybeQmlBuiltinType(const QStringView &text) const;
|
||||
|
||||
private:
|
||||
bool m_qmlEnabled;
|
||||
|
||||
@@ -235,7 +235,7 @@ protected:
|
||||
m_scopeBuilder.pop();
|
||||
}
|
||||
|
||||
void processName(const QStringRef &name, SourceLocation location)
|
||||
void processName(const QStringView &name, SourceLocation location)
|
||||
{
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -599,7 +599,7 @@ void QmlOutlineModel::leavePublicMember()
|
||||
leaveNode();
|
||||
}
|
||||
|
||||
static QString functionDisplayName(QStringRef name, AST::FormalParameterList *formals)
|
||||
static QString functionDisplayName(QStringView name, AST::FormalParameterList *formals)
|
||||
{
|
||||
QString display;
|
||||
|
||||
@@ -1002,7 +1002,7 @@ QString QmlOutlineModel::asString(AST::UiQualifiedId *id)
|
||||
QString text;
|
||||
for (; id; id = id->next) {
|
||||
if (!id->name.isEmpty())
|
||||
text += id->name;
|
||||
text += id->name.toString();
|
||||
else
|
||||
text += QLatin1Char('?');
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ Node *SemanticInfo::declaringMemberNoProperties(int cursorPosition) const
|
||||
AST::Node *node = rangeAt(cursorPosition);
|
||||
|
||||
if (auto objectDefinition = cast<const UiObjectDefinition*>(node)) {
|
||||
const QStringRef name = objectDefinition->qualifiedTypeNameId->name;
|
||||
const QStringView name = objectDefinition->qualifiedTypeNameId->name;
|
||||
if (!name.isEmpty() && name.at(0).isLower()) {
|
||||
QList<AST::Node *> path = rangePath(cursorPosition);
|
||||
if (path.size() > 1)
|
||||
@@ -170,7 +170,7 @@ Node *SemanticInfo::declaringMemberNoProperties(int cursorPosition) const
|
||||
return path.at(path.size() - 3);
|
||||
}
|
||||
} else if (auto objectBinding = cast<const UiObjectBinding*>(node)) {
|
||||
const QStringRef name = objectBinding->qualifiedTypeNameId->name;
|
||||
const QStringView name = objectBinding->qualifiedTypeNameId->name;
|
||||
if (name.contains(QLatin1String("Gradient"))) {
|
||||
QList<AST::Node *> path = rangePath(cursorPosition);
|
||||
if (path.size() > 1)
|
||||
|
||||
Reference in New Issue
Block a user