QmlJS.PropertyReader: Allow access to raw ast value

Change-Id: I92f9f241c9780345dd03b931232c4a811356c216
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Thomas Hartmann
2016-04-28 14:39:54 +02:00
parent c75c54e930
commit 1ba0e5cdf9
2 changed files with 18 additions and 6 deletions

View File

@@ -146,13 +146,14 @@ PropertyReader::PropertyReader(Document::Ptr doc, AST::UiObjectInitializer *ast)
continue; // better safe than sorry.
const QString propertyName = toString(property->qualifiedId);
const QString astValue = cleanupSemicolon(textAt(doc,
property->statement->firstSourceLocation(),
property->statement->lastSourceLocation()));
property->statement->firstSourceLocation(),
property->statement->lastSourceLocation()));
m_astPropertyValues.insert(propertyName, astValue);
if (isLiteralValue(property)) {
m_properties.insert(propertyName, QVariant(deEscape(stripQuotes(astValue))));
} else if (isEnum(property->statement)) { //enum
m_properties.insert(propertyName, QVariant(astValue));
m_bindingOrEnum.append(propertyName);
m_properties.insert(propertyName, QVariant(astValue));
m_bindingOrEnum.append(propertyName);
}
} else if (UiObjectDefinition *objectDefinition = cast<UiObjectDefinition *>(member)) { //font { bold: true }
const QString propertyName = objectDefinition->qualifiedTypeNameId->name.toString();
@@ -162,8 +163,9 @@ PropertyReader::PropertyReader(Document::Ptr doc, AST::UiObjectInitializer *ast)
if (UiScriptBinding *property = cast<UiScriptBinding *>(objectMember)) {
const QString propertyNamePart2 = toString(property->qualifiedId);
const QString astValue = cleanupSemicolon(textAt(doc,
property->statement->firstSourceLocation(),
property->statement->lastSourceLocation()));
property->statement->firstSourceLocation(),
property->statement->lastSourceLocation()));
m_astPropertyValues.insert(propertyName, astValue);
if (isLiteralValue(property)) {
m_properties.insert(propertyName + QLatin1Char('.') + propertyNamePart2,
QVariant(deEscape(stripQuotes(astValue))));
@@ -181,6 +183,7 @@ PropertyReader::PropertyReader(Document::Ptr doc, AST::UiObjectInitializer *ast)
initializer->rbraceToken));
const QString propertyName = objectBinding->qualifiedId->name.toString();
m_properties.insert(propertyName, QVariant(astValue));
m_astPropertyValues.insert(propertyName, astValue);
}
}
}

View File

@@ -54,6 +54,14 @@ public:
return QVariant();
}
QString readAstValue(const QString &propertyName) const
{
if (hasProperty(propertyName))
return m_astPropertyValues.value(propertyName);
else
return QString();
}
QLinearGradient parseGradient(const QString &propertyName, bool *isBound) const;
QStringList properties() const
@@ -64,6 +72,7 @@ public:
private:
QHash<QString, QVariant> m_properties;
QHash<QString, QString> m_astPropertyValues;
QList<QString> m_bindingOrEnum;
AST::UiObjectInitializer *m_ast;
Document::Ptr m_doc;