forked from qt-creator/qt-creator
		
	QmlJS:SimpleReader: adding support for arrays
Also adding test. Change-Id: Idaf0aeacbb6f78e5c8404db740c2a8b7b297dad2 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
		| @@ -232,12 +232,12 @@ void SimpleAbstractStreamReader::readProperty(AST::UiScriptBinding *uiScriptBind | ||||
|     setSourceLocation(uiScriptBinding->firstSourceLocation()); | ||||
|  | ||||
|     const QString name = toString(uiScriptBinding->qualifiedId); | ||||
|     const QVariant value = parseProperty(uiScriptBinding); | ||||
|     const QVariant value = parsePropertyScriptBinding(uiScriptBinding); | ||||
|  | ||||
|     propertyDefinition(name, value); | ||||
| } | ||||
|  | ||||
| QVariant SimpleAbstractStreamReader::parseProperty(AST::UiScriptBinding *uiScriptBinding) | ||||
| QVariant SimpleAbstractStreamReader::parsePropertyScriptBinding(AST::UiScriptBinding *uiScriptBinding) | ||||
| { | ||||
|     Q_ASSERT(uiScriptBinding); | ||||
|  | ||||
| @@ -247,23 +247,39 @@ QVariant SimpleAbstractStreamReader::parseProperty(AST::UiScriptBinding *uiScrip | ||||
|         return QVariant(); | ||||
|     } | ||||
|  | ||||
|     AST::StringLiteral *stringLiteral = AST::cast<AST::StringLiteral *>(expStmt->expression); | ||||
|     return parsePropertyExpression(expStmt->expression); | ||||
| } | ||||
|  | ||||
| QVariant SimpleAbstractStreamReader::parsePropertyExpression(AST::ExpressionNode *expressionNode) | ||||
| { | ||||
|     Q_ASSERT(expressionNode); | ||||
|  | ||||
|     AST::ArrayLiteral *arrayLiteral = AST::cast<AST::ArrayLiteral *>(expressionNode); | ||||
|  | ||||
|     if (arrayLiteral) { | ||||
|         QList<QVariant> variantList; | ||||
|         for (AST::ElementList *it = arrayLiteral->elements; it; it = it->next) | ||||
|             variantList << parsePropertyExpression(it->expression); | ||||
|         return variantList; | ||||
|     } | ||||
|  | ||||
|     AST::StringLiteral *stringLiteral = AST::cast<AST::StringLiteral *>(expressionNode); | ||||
|     if (stringLiteral) | ||||
|         return stringLiteral->value.toString(); | ||||
|  | ||||
|     AST::TrueLiteral *trueLiteral = AST::cast<AST::TrueLiteral *>(expStmt->expression); | ||||
|     AST::TrueLiteral *trueLiteral = AST::cast<AST::TrueLiteral *>(expressionNode); | ||||
|     if (trueLiteral) | ||||
|         return true; | ||||
|  | ||||
|     AST::FalseLiteral *falseLiteral = AST::cast<AST::FalseLiteral *>(expStmt->expression); | ||||
|     AST::FalseLiteral *falseLiteral = AST::cast<AST::FalseLiteral *>(expressionNode); | ||||
|     if (falseLiteral) | ||||
|         return false; | ||||
|  | ||||
|     AST::NumericLiteral *numericLiteral = AST::cast<AST::NumericLiteral *>(expStmt->expression); | ||||
|     AST::NumericLiteral *numericLiteral = AST::cast<AST::NumericLiteral *>(expressionNode); | ||||
|     if (numericLiteral) | ||||
|         return numericLiteral->value; | ||||
|  | ||||
|     addError(tr("Expected expression statement to be a literal"), uiScriptBinding->statement->firstSourceLocation()); | ||||
|     addError(tr("Expected expression statement to be a literal"), expressionNode->firstSourceLocation()); | ||||
|     return QVariant(); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -102,7 +102,8 @@ private: | ||||
|     void readChild(AST::UiObjectDefinition *uiObjectDefinition); | ||||
|     void readProperties(AST::UiObjectDefinition *ast); | ||||
|     void readProperty(AST::UiScriptBinding *uiScriptBinding); | ||||
|     QVariant parseProperty(AST::UiScriptBinding *ast); | ||||
|     QVariant parsePropertyScriptBinding(AST::UiScriptBinding *ExpressionNode); | ||||
|     QVariant parsePropertyExpression(AST::ExpressionNode *expressionNode); | ||||
|     void setSourceLocation(const AST::SourceLocation &sourceLocation); | ||||
|  | ||||
|     QStringList m_errors; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user