2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-02-07 15:30:33 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-02-07 15:30:33 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-02-07 15:30:33 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-02-07 15:30:33 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-02-07 15:30:33 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-02-07 15:30:33 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2012-02-07 15:30:33 +01:00
|
|
|
|
|
|
|
|
#include "qmljs_global.h"
|
|
|
|
|
|
|
|
|
|
#include <qmljs/qmljsdocument.h>
|
|
|
|
|
#include <qmljs/parser/qmljsastvisitor_p.h>
|
|
|
|
|
#include <qmljs/qmljsstaticanalysismessage.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/json.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStack>
|
|
|
|
|
#include <QList>
|
2012-02-07 15:30:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace QmlJS {
|
|
|
|
|
|
|
|
|
|
class QMLJS_EXPORT JsonCheck : public AST::Visitor
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
JsonCheck(Document::Ptr doc);
|
2014-02-07 09:01:53 +01:00
|
|
|
~JsonCheck();
|
2012-02-07 15:30:33 +01:00
|
|
|
|
|
|
|
|
QList<StaticAnalysis::Message> operator()(Utils::JsonSchema *schema);
|
|
|
|
|
|
|
|
|
|
private:
|
2015-06-03 15:34:13 +02:00
|
|
|
bool preVisit(AST::Node *) override;
|
|
|
|
|
void postVisit(AST::Node *) override;
|
|
|
|
|
|
2018-10-16 15:32:58 +02:00
|
|
|
bool visit(AST::ObjectPattern *ast) override;
|
|
|
|
|
bool visit(AST::ArrayPattern *ast) override;
|
2015-06-03 15:34:13 +02:00
|
|
|
bool visit(AST::NullExpression *ast) override;
|
|
|
|
|
bool visit(AST::TrueLiteral *ast) override;
|
|
|
|
|
bool visit(AST::FalseLiteral *ast) override;
|
|
|
|
|
bool visit(AST::NumericLiteral *ast) override;
|
|
|
|
|
bool visit(AST::StringLiteral *ast) override;
|
2012-02-07 15:30:33 +01:00
|
|
|
|
|
|
|
|
struct AnalysisData
|
|
|
|
|
{
|
2012-02-08 15:19:47 +01:00
|
|
|
AnalysisData() : m_ranking(0), m_hasMatch(false) {}
|
2012-02-07 15:30:33 +01:00
|
|
|
|
|
|
|
|
void boostRanking(int unit = 1) { m_ranking += unit; }
|
|
|
|
|
|
|
|
|
|
int m_ranking;
|
|
|
|
|
bool m_hasMatch;
|
|
|
|
|
QList<StaticAnalysis::Message> m_messages;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void processSchema(AST::Node *ast);
|
|
|
|
|
bool proceedCheck(Utils::JsonValue::Kind kind, const AST::SourceLocation &location);
|
|
|
|
|
|
|
|
|
|
AnalysisData *analysis();
|
|
|
|
|
|
|
|
|
|
Document::Ptr m_doc;
|
|
|
|
|
AST::SourceLocation m_firstLoc;
|
|
|
|
|
Utils::JsonSchema *m_schema;
|
|
|
|
|
QStack<AnalysisData> m_analysis;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // QmlJs
|