forked from qt-creator/qt-creator
Qml: Make import classification in Bind less verbose.
This commit is contained in:
@@ -49,8 +49,7 @@ using namespace QmlJS::Interpreter;
|
||||
information that goes beyond that, you need to create a
|
||||
\l{QmlJS::Interpreter::Context} using \l{QmlJS::Link}.
|
||||
|
||||
The document's imports are classified and available through fileImports(),
|
||||
directoryImports() and libraryImports().
|
||||
The document's imports are classified and available through imports().
|
||||
|
||||
It allows AST to code model lookup through findQmlObject() and findFunctionScope().
|
||||
*/
|
||||
@@ -69,19 +68,9 @@ Bind::~Bind()
|
||||
{
|
||||
}
|
||||
|
||||
QList<Bind::ImportInfo> Bind::fileImports() const
|
||||
QList<Bind::ImportInfo> Bind::imports() const
|
||||
{
|
||||
return _fileImports;
|
||||
}
|
||||
|
||||
QList<Bind::ImportInfo> Bind::directoryImports() const
|
||||
{
|
||||
return _directoryImports;
|
||||
}
|
||||
|
||||
QList<Bind::ImportInfo> Bind::libraryImports() const
|
||||
{
|
||||
return _libraryImports;
|
||||
return _imports;
|
||||
}
|
||||
|
||||
Interpreter::ObjectValue *Bind::idEnvironment() const
|
||||
@@ -209,18 +198,19 @@ bool Bind::visit(UiImport *ast)
|
||||
}
|
||||
|
||||
if (ast->importUri) {
|
||||
info.type = ImportInfo::LibraryImport;
|
||||
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 += info;
|
||||
info.type = ImportInfo::FileImport;
|
||||
else if (importFileInfo.isDir())
|
||||
_directoryImports += info;
|
||||
//else
|
||||
// error: file or directory does not exist
|
||||
info.type = ImportInfo::DirectoryImport;
|
||||
else
|
||||
info.type = ImportInfo::InvalidFileImport;
|
||||
}
|
||||
_imports += info;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -52,14 +52,22 @@ public:
|
||||
virtual ~Bind();
|
||||
|
||||
struct ImportInfo {
|
||||
enum Type {
|
||||
LibraryImport,
|
||||
FileImport,
|
||||
DirectoryImport,
|
||||
InvalidFileImport // refers a file/directoy that wasn't found
|
||||
};
|
||||
|
||||
Type type;
|
||||
// LibraryImport: uri with '/' separator
|
||||
// Other: absoluteFilePath
|
||||
QString name;
|
||||
ComponentVersion version;
|
||||
AST::UiImport *ast;
|
||||
};
|
||||
|
||||
QList<ImportInfo> fileImports() const;
|
||||
QList<ImportInfo> directoryImports() const;
|
||||
QList<ImportInfo> libraryImports() const;
|
||||
QList<ImportInfo> imports() const;
|
||||
|
||||
Interpreter::ObjectValue *idEnvironment() const;
|
||||
Interpreter::ObjectValue *rootObjectValue() const;
|
||||
@@ -111,9 +119,7 @@ private:
|
||||
QHash<AST::FunctionDeclaration *, Interpreter::ObjectValue *> _functionScopes;
|
||||
QStringList _includedScripts;
|
||||
|
||||
QList<ImportInfo> _fileImports;
|
||||
QList<ImportInfo> _directoryImports;
|
||||
QList<ImportInfo> _libraryImports;
|
||||
QList<ImportInfo> _imports;
|
||||
};
|
||||
|
||||
} // end of namespace Qml
|
||||
|
||||
Reference in New Issue
Block a user