diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-02-15 16:53:55 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-02-15 21:48:04 +0000 |
commit | 98d337183c4f80dbcd0f12f0f0a7a58a3696526b (patch) | |
tree | 007b071c95ee9594e034889d930f45df623bd398 /sources/shiboken2/generator | |
parent | ea4c5ce68b5a186623e78837b7e4b9c15d8b45b9 (diff) |
shiboken/docgenerator: Handle empty snippets
Empty snippets may actually be valid in case a single
closing bracket in C++ is turned into an empty line
in Python (customstyle.cpp[1]). Differentiate between
those by using QString::isNull() for the fallback
mechanism. Always output snippet identifier in messages.
Amends 45f3126a04cd5493323b689c85a48106d0f8367e.
Task-number: PYSIDE-363
Change-Id: I0391b18fafacbd4c57c4017adb08126a5e2c7c7e
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/generator')
-rw-r--r-- | sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp index 1a5e8b3e5..08c342cfa 100644 --- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp @@ -124,12 +124,14 @@ static QString msgTagWarning(const QXmlStreamReader &reader, const QString &cont } static QString msgFallbackWarning(const QXmlStreamReader &reader, const QString &context, - const QString &tag, const QString &location, + const QString &tag, const QString &location, const QString &identifier, const QString &fallback) { - const QString message = QLatin1String("Falling back to \"") + QString message = QLatin1String("Falling back to \"") + QDir::toNativeSeparators(fallback) + QLatin1String("\" for \"") + location + QLatin1Char('"'); + if (!identifier.isEmpty()) + message += QLatin1String(" [") + identifier + QLatin1Char(']'); return msgTagWarning(reader, context, tag, message); } @@ -345,10 +347,10 @@ QString QtXmlToSphinx::readFromLocations(const QStringList &locations, const QSt if (resolvedPath.isEmpty()) { QTextStream(errorMessage) << "Could not resolve \"" << path << "\" in \"" << locations.join(QLatin1String("\", \"")); - return QString(); + return QString(); // null } qCDebug(lcShiboken).noquote().nospace() << "snippet file " << path - << " resolved to " << resolvedPath; + << " [" << identifier << ']' << " resolved to " << resolvedPath; return readFromLocation(resolvedPath, identifier, errorMessage); } @@ -361,10 +363,10 @@ QString QtXmlToSphinx::readFromLocation(const QString &location, const QString & QTextStream(errorMessage) << "Could not read code snippet file: " << QDir::toNativeSeparators(inputFile.fileName()) << ": " << inputFile.errorString(); - return QString(); + return QString(); // null } - QString code; + QString code = QLatin1String(""); // non-null if (identifier.isEmpty()) { while (!inputFile.atEnd()) code += QString::fromUtf8(inputFile.readLine()); @@ -395,6 +397,7 @@ QString QtXmlToSphinx::readFromLocation(const QString &location, const QString & QTextStream(errorMessage) << "Code snippet file found (" << QDir::toNativeSeparators(location) << "), but snippet [" << identifier << "] not found."; + return QString(); // null } return code; @@ -539,12 +542,12 @@ void QtXmlToSphinx::handleSnippetTag(QXmlStreamReader& reader) // Fall back to C++ snippet when "path" attribute is present. // Also read fallback snippet when comparison is desired. QString fallbackCode; - if ((pythonCode.isEmpty() || snippetComparison()) + if ((pythonCode.isNull() || snippetComparison()) && reader.attributes().hasAttribute(fallbackPathAttribute())) { const QString fallback = reader.attributes().value(fallbackPathAttribute()).toString(); if (QFileInfo::exists(fallback)) { - if (pythonCode.isEmpty()) - qCWarning(lcShiboken, "%s", qPrintable(msgFallbackWarning(reader, m_context, m_lastTagName, location, fallback))); + if (pythonCode.isNull()) + qCWarning(lcShiboken, "%s", qPrintable(msgFallbackWarning(reader, m_context, m_lastTagName, location, identifier, fallback))); fallbackCode = readFromLocation(fallback, identifier, &errorMessage); if (!errorMessage.isEmpty()) qCWarning(lcShiboken, "%s", qPrintable(msgTagWarning(reader, m_context, m_lastTagName, errorMessage))); @@ -558,7 +561,7 @@ void QtXmlToSphinx::handleSnippetTag(QXmlStreamReader& reader) m_output << INDENT << "::\n\n"; Indentation indentation(INDENT); - const QString code = pythonCode.isEmpty() ? fallbackCode : pythonCode; + const QString code = pythonCode.isNull() ? fallbackCode : pythonCode; if (code.isEmpty()) m_output << INDENT << "<Code snippet \"" << location << ':' << identifier << "\" not found>" << endl; else |