2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-04-12 15:51:56 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-04-12 15:51:56 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-04-12 15:51:56 +02: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:57:40 +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-04-12 15:51:56 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +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-04-12 15:51:56 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-12 15:51:56 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2012-04-12 15:51:56 +02:00
|
|
|
|
|
|
|
|
#include "qmljstools_global.h"
|
|
|
|
|
|
2015-03-04 16:46:23 +01:00
|
|
|
#include <qmljs/qmljsdocument.h>
|
|
|
|
|
#include <qmljs/qmljscontext.h>
|
2012-04-12 15:51:56 +02:00
|
|
|
#include <qmljs/qmljsstaticanalysismessage.h>
|
2015-03-04 16:46:23 +01:00
|
|
|
#include <qmljs/parser/qmljsengine_p.h>
|
2012-04-12 15:51:56 +02:00
|
|
|
|
|
|
|
|
#include <QTextCursor>
|
|
|
|
|
|
2015-03-04 16:46:23 +01:00
|
|
|
namespace QmlJS {
|
|
|
|
|
class ScopeChain;
|
|
|
|
|
namespace AST { class Node; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-12 15:51:56 +02:00
|
|
|
namespace QmlJSTools {
|
|
|
|
|
|
|
|
|
|
class QMLJSTOOLS_EXPORT Range
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Range(): ast(0) {}
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
|
|
|
|
QmlJS::AST::Node *ast;
|
|
|
|
|
QTextCursor begin;
|
|
|
|
|
QTextCursor end;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QMLJSTOOLS_EXPORT SemanticInfo
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SemanticInfo() {}
|
|
|
|
|
SemanticInfo(QmlJS::ScopeChain *rootScopeChain);
|
|
|
|
|
|
|
|
|
|
bool isValid() const;
|
|
|
|
|
int revision() const;
|
|
|
|
|
|
|
|
|
|
// Returns the AST path
|
|
|
|
|
QList<QmlJS::AST::Node *> astPath(int cursorPosition) const;
|
|
|
|
|
|
|
|
|
|
// Returns the AST node at the offset (the last member of the astPath)
|
|
|
|
|
QmlJS::AST::Node *astNodeAt(int cursorPosition) const;
|
|
|
|
|
|
|
|
|
|
// Returns the list of declaration-type nodes that enclose the given position.
|
|
|
|
|
// It is more robust than astPath because it tracks ranges with text cursors
|
|
|
|
|
// and will thus be correct even if the document was changed and not yet
|
|
|
|
|
// reparsed. It does not return the full path of AST nodes.
|
|
|
|
|
QList<QmlJS::AST::Node *> rangePath(int cursorPosition) const;
|
|
|
|
|
|
|
|
|
|
// Returns the declaring member
|
|
|
|
|
QmlJS::AST::Node *rangeAt(int cursorPosition) const;
|
|
|
|
|
QmlJS::AST::Node *declaringMemberNoProperties(int cursorPosition) const;
|
|
|
|
|
|
|
|
|
|
// Returns a scopeChain for the given path
|
|
|
|
|
QmlJS::ScopeChain scopeChain(const QList<QmlJS::AST::Node *> &path = QList<QmlJS::AST::Node *>()) const;
|
|
|
|
|
|
|
|
|
|
void setRootScopeChain(QSharedPointer<const QmlJS::ScopeChain> rootScopeChain);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
|
|
|
|
QmlJS::Document::Ptr document;
|
|
|
|
|
QmlJS::Snapshot snapshot;
|
|
|
|
|
QmlJS::ContextPtr context;
|
|
|
|
|
QList<Range> ranges;
|
|
|
|
|
QHash<QString, QList<QmlJS::AST::SourceLocation> > idLocations;
|
|
|
|
|
|
|
|
|
|
// these are in addition to the parser messages in the document
|
|
|
|
|
QList<QmlJS::DiagnosticMessage> semanticMessages;
|
|
|
|
|
QList<QmlJS::StaticAnalysis::Message> staticAnalysisMessages;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QSharedPointer<const QmlJS::ScopeChain> m_rootScopeChain;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace QmlJSTools
|
|
|
|
|
|
2012-04-13 11:57:34 +02:00
|
|
|
Q_DECLARE_METATYPE(QmlJSTools::SemanticInfo)
|