forked from qt-creator/qt-creator
QmlJS: Add highlighting for enum usage
Highlights the enum and its values if valid. Task-number: QTCREATORBUG-19226 Change-Id: Icca90b0a5d83a4ecdccfe220bcd0a3547b2e6104 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
@@ -368,6 +368,45 @@ protected:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool visit(FieldMemberExpression *ast) override
|
||||
{
|
||||
// we only support IdentifierExpression.FieldMemberExpression (enum)
|
||||
const FieldMemberExpression *right = ast;
|
||||
if (const IdentifierExpression *idExp = cast<IdentifierExpression *>(ast->base)) {
|
||||
const ObjectValue *scope = nullptr;
|
||||
const Value *value = m_scopeChain.lookup(idExp->name.toString(), &scope);
|
||||
if (auto aov = value->asAstObjectValue()) {
|
||||
const ObjectValue *inObject = nullptr;
|
||||
const Value *enumValue = aov->lookupMember(right->name.toString(),
|
||||
m_scopeChain.context(), &inObject);
|
||||
if (enumValue && enumValue->asNumberValue()) // can we do better?
|
||||
addUse(right->identifierToken, SemanticHighlighter::FieldType);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// or IdentifierExpression.FieldMemberExpression.FieldMemberExpression (enum)
|
||||
const FieldMemberExpression *it = cast<FieldMemberExpression *>(ast->base);
|
||||
if (!it)
|
||||
return true;
|
||||
const IdentifierExpression *idExp = cast<IdentifierExpression *>(it->base);
|
||||
if (!idExp)
|
||||
return true;
|
||||
const ObjectValue *scope = nullptr;
|
||||
const Value *value = m_scopeChain.lookup(idExp->name.toString(), &scope);
|
||||
const ASTObjectValue *aoValue= value->asAstObjectValue();
|
||||
if (!aoValue)
|
||||
return true;
|
||||
if (auto maybeEnum = aoValue->lookupMember(it->name.toString(), m_scopeChain.context())) {
|
||||
if (const UiEnumValue *enumObject = maybeEnum->asUiEnumValue()) {
|
||||
addUse(it->identifierToken, SemanticHighlighter::QmlTypeType);
|
||||
if (enumObject->keys().contains(right->name))
|
||||
addUse(right->identifierToken, SemanticHighlighter::FieldType);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool visit(StringLiteral *ast) override
|
||||
{
|
||||
if (ast->value.isEmpty())
|
||||
|
||||
Reference in New Issue
Block a user