Commit b71dd842 authored by Denis Steckelmacher's avatar Denis Steckelmacher

Support versioned module names

ParseSession parses names like "QtQuick_2.2.qml" and "MyModule.qml" and has
methods to get the module name (QtQuick and MyModule) and its version
(2.2 and 1.0)
parent ec09f48d
......@@ -651,7 +651,7 @@ void DeclarationBuilder::declareComponentSubclass(QmlJS::AST::UiObjectInitialize
DUChainWriteLocker lock;
ClassDeclaration* decl = openDeclaration<ClassDeclaration>(
currentContext()->type() == DUContext::Global ?
QualifiedIdentifier(m_session->urlBaseName()) :
QualifiedIdentifier(m_session->moduleName()) :
name,
RangeInRevision()
);
......
......@@ -72,6 +72,16 @@ ParseSession::ParseSession(const IndexedString& url, const QString& contents, in
m_doc->setSource(contents);
m_doc->parse();
Q_ASSERT(isSorted(m_doc->engine()->comments()));
// Parse the module name and the version of url (this is used only when the file
// is a QML module, but doesn't break for JavaScript files)
QString baseName = QString::fromUtf8(m_url.byteArray())
.section('/', -1, -1) // Base name
.section('.', 0, -2); // Without extension
QStringList nameAndVersion = baseName.split('_');
m_baseNameWithoutVersion = nameAndVersion.at(0);
m_version = (nameAndVersion.count() > 1 ? nameAndVersion.at(1) : QLatin1String("1.0"));
}
bool ParseSession::isParsedCorrectly() const
......@@ -89,11 +99,14 @@ IndexedString ParseSession::url() const
return m_url;
}
QString ParseSession::urlBaseName() const
QString ParseSession::moduleName() const
{
return m_baseNameWithoutVersion;
}
QString ParseSession::moduleVersion() const
{
return QString::fromUtf8(m_url.byteArray())
.section('/', -1, -1) // Base name
.section('.', 0, -2); // Without its extension
return m_version;
}
QList<ProblemPointer> ParseSession::problems() const
......
......@@ -66,9 +66,14 @@ public:
KDevelop::IndexedString url() const;
/**
* @return the basename, without its extension, of url()
* @return The module name of this file ("/foo/QtQuick_1.0.qml" yields "QtQuick")
*/
QString urlBaseName() const;
QString moduleName() const;
/**
* @return The version of this file, or QString if none ("QtQuick_1.0.qml" yields "1.0")
*/
QString moduleVersion() const;
/**
* @return true if the document was properly parsed, false otherwise.
......@@ -158,6 +163,8 @@ public:
private:
KDevelop::IndexedString m_url;
QString m_baseNameWithoutVersion;
QString m_version;
QmlJS::Document::MutablePtr m_doc;
int m_ownPriority;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment