forked from qt-creator/qt-creator
Fixed import of "." in a library with a hack.
Task-number: QTCREATORBUG-4198 Reviewed-by: Kai Koehne
This commit is contained in:
@@ -183,6 +183,28 @@ void Link::populateImportedTypes(TypeEnvironment *typeEnv, Document::Ptr doc)
|
||||
// explicit imports, whether directories, files or libraries
|
||||
foreach (const ImportInfo &info, doc->bind()->imports()) {
|
||||
ObjectValue *import = d->importCache.value(ImportCacheKey(info));
|
||||
|
||||
//### Hack: if this document is in a library, and if there is an qmldir file in the same directory, and if the prefix is an import-path, the import means to import everything in this library.
|
||||
if (info.ast() && info.ast()->fileName && info.ast()->fileName->asString() == QLatin1String(".")) {
|
||||
const QString importInfoName(info.name());
|
||||
if (QFileInfo(QDir(importInfoName), QLatin1String("qmldir")).exists()) {
|
||||
foreach (const QString &importPath, d->importPaths) {
|
||||
if (importInfoName.startsWith(importPath)) {
|
||||
// Got it.
|
||||
|
||||
const QString cleanPath = QFileInfo(importInfoName).canonicalFilePath();
|
||||
const QString forcedPackageName = cleanPath.mid(importPath.size() + 1).replace('/', '.').replace('\\', '.');
|
||||
import = importNonFile(doc, info, forcedPackageName);
|
||||
if (import)
|
||||
d->importCache.insert(ImportCacheKey(info), import);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//### End of hack.
|
||||
|
||||
if (!import) {
|
||||
switch (info.type()) {
|
||||
case ImportInfo::FileImport:
|
||||
@@ -245,12 +267,12 @@ ObjectValue *Link::importFileOrDirectory(Document::Ptr doc, const ImportInfo &im
|
||||
import Qt 4.6 as Xxx
|
||||
(import com.nokia.qt is the same as the ones above)
|
||||
*/
|
||||
ObjectValue *Link::importNonFile(Document::Ptr doc, const ImportInfo &importInfo)
|
||||
ObjectValue *Link::importNonFile(Document::Ptr doc, const ImportInfo &importInfo, const QString &forcedPackageName)
|
||||
{
|
||||
Q_D(Link);
|
||||
|
||||
ObjectValue *import = new ObjectValue(engine());
|
||||
const QString packageName = Bind::toString(importInfo.ast()->importUri, '.');
|
||||
const QString packageName = forcedPackageName.isEmpty() ? Bind::toString(importInfo.ast()->importUri, '.') : forcedPackageName;
|
||||
const ComponentVersion version = importInfo.version();
|
||||
|
||||
bool importFound = false;
|
||||
@@ -277,7 +299,7 @@ ObjectValue *Link::importNonFile(Document::Ptr doc, const ImportInfo &importInfo
|
||||
}
|
||||
}
|
||||
|
||||
if (!importFound) {
|
||||
if (!importFound && importInfo.ast()) {
|
||||
error(doc, locationFromRange(importInfo.ast()->firstSourceLocation(),
|
||||
importInfo.ast()->lastSourceLocation()),
|
||||
tr("package not found"));
|
||||
|
||||
Reference in New Issue
Block a user