2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
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;
|
|
|
|
|
|
2021-12-06 09:44:24 +01:00
|
|
|
bool visit(AST::TemplateLiteral *ast) 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
|
|
|
|
2020-02-28 17:51:32 +01:00
|
|
|
void throwRecursionDepthError() 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);
|
2020-02-28 17:51:32 +01:00
|
|
|
bool proceedCheck(Utils::JsonValue::Kind kind, const SourceLocation &location);
|
2012-02-07 15:30:33 +01:00
|
|
|
|
|
|
|
|
AnalysisData *analysis();
|
|
|
|
|
|
|
|
|
|
Document::Ptr m_doc;
|
2020-02-28 17:51:32 +01:00
|
|
|
SourceLocation m_firstLoc;
|
2012-02-07 15:30:33 +01:00
|
|
|
Utils::JsonSchema *m_schema;
|
|
|
|
|
QStack<AnalysisData> m_analysis;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // QmlJs
|