diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp index c8666b96053..1d725360c55 100644 --- a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp +++ b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp @@ -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(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(ast->base); + if (!it) + return true; + const IdentifierExpression *idExp = cast(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())