forked from qt-creator/qt-creator
QmlJS: Collect import version numbers in Bind.
This commit is contained in:
@@ -53,17 +53,17 @@ Bind::~Bind()
|
||||
{
|
||||
}
|
||||
|
||||
QStringList Bind::fileImports() const
|
||||
QList<Bind::ImportInfo> Bind::fileImports() const
|
||||
{
|
||||
return _fileImports;
|
||||
}
|
||||
|
||||
QStringList Bind::directoryImports() const
|
||||
QList<Bind::ImportInfo> Bind::directoryImports() const
|
||||
{
|
||||
return _directoryImports;
|
||||
}
|
||||
|
||||
QStringList Bind::libraryImports() const
|
||||
QList<Bind::ImportInfo> Bind::libraryImports() const
|
||||
{
|
||||
return _libraryImports;
|
||||
}
|
||||
@@ -185,14 +185,30 @@ bool Bind::visit(AST::Program *)
|
||||
|
||||
bool Bind::visit(UiImport *ast)
|
||||
{
|
||||
ImportInfo info;
|
||||
|
||||
info.majorVersion = QmlObjectValue::NoVersion;
|
||||
info.minorVersion = QmlObjectValue::NoVersion;
|
||||
|
||||
if (ast->versionToken.isValid()) {
|
||||
const QString versionString = _doc->source().mid(ast->versionToken.offset, ast->versionToken.length);
|
||||
const int dotIdx = versionString.indexOf(QLatin1Char('.'));
|
||||
if (dotIdx != -1) {
|
||||
info.majorVersion = versionString.left(dotIdx).toInt();
|
||||
info.minorVersion = versionString.mid(dotIdx + 1).toInt();
|
||||
}
|
||||
}
|
||||
|
||||
if (ast->importUri) {
|
||||
_libraryImports += toString(ast->importUri, QLatin1Char('/'));
|
||||
info.name = toString(ast->importUri, QLatin1Char('/'));
|
||||
_libraryImports += info;
|
||||
} else if (ast->fileName) {
|
||||
const QFileInfo importFileInfo(_doc->path() + QLatin1Char('/') + ast->fileName->asString());
|
||||
info.name = importFileInfo.absoluteFilePath();
|
||||
if (importFileInfo.isFile())
|
||||
_fileImports += importFileInfo.absoluteFilePath();
|
||||
_fileImports += info;
|
||||
else if (importFileInfo.isDir())
|
||||
_directoryImports += importFileInfo.absoluteFilePath();
|
||||
_directoryImports += info;
|
||||
//else
|
||||
// error: file or directory does not exist
|
||||
}
|
||||
|
||||
@@ -50,9 +50,15 @@ public:
|
||||
Bind(Document *doc);
|
||||
virtual ~Bind();
|
||||
|
||||
QStringList fileImports() const;
|
||||
QStringList directoryImports() const;
|
||||
QStringList libraryImports() const;
|
||||
struct ImportInfo {
|
||||
QString name;
|
||||
int majorVersion;
|
||||
int minorVersion;
|
||||
};
|
||||
|
||||
QList<ImportInfo> fileImports() const;
|
||||
QList<ImportInfo> directoryImports() const;
|
||||
QList<ImportInfo> libraryImports() const;
|
||||
|
||||
Interpreter::ObjectValue *currentObjectValue() const;
|
||||
Interpreter::ObjectValue *idEnvironment() const;
|
||||
@@ -105,9 +111,9 @@ private:
|
||||
QHash<AST::FunctionDeclaration *, Interpreter::ObjectValue *> _functionScopes;
|
||||
QStringList _includedScripts;
|
||||
|
||||
QStringList _fileImports;
|
||||
QStringList _directoryImports;
|
||||
QStringList _libraryImports;
|
||||
QList<ImportInfo> _fileImports;
|
||||
QList<ImportInfo> _directoryImports;
|
||||
QList<ImportInfo> _libraryImports;
|
||||
};
|
||||
|
||||
} // end of namespace Qml
|
||||
|
||||
@@ -65,8 +65,8 @@ void Link::initializeScopeChain()
|
||||
} else {
|
||||
// add scope chains for all components that import this file
|
||||
foreach (Document::Ptr otherDoc, _snapshot) {
|
||||
foreach (const QString &fileImport, otherDoc->bind()->fileImports()) {
|
||||
if (_doc->fileName() == fileImport) {
|
||||
foreach (const Bind::ImportInfo &fileImport, otherDoc->bind()->fileImports()) {
|
||||
if (_doc->fileName() == fileImport.name) {
|
||||
ScopeChain::QmlComponentChain *component = new ScopeChain::QmlComponentChain;
|
||||
componentScopes.insert(otherDoc.data(), component);
|
||||
scopeChain.qmlComponentScope.instantiatingComponents += component;
|
||||
|
||||
Reference in New Issue
Block a user