CPlusPlus: Remove Rreprocessor::run overload for QStrings

The preprocessor operates on QByteArray, making it less
convenient to use strings helps preventing accidental
conversion roundtrips.

Change-Id: Ifb2068a8fed137c52b05f2979b99cbce3462151e
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-08-01 09:13:46 +02:00
parent 960e99ecb1
commit 2361353289
5 changed files with 5 additions and 12 deletions

View File

@@ -748,11 +748,6 @@ Preprocessor::Preprocessor(Client *client, Environment *env)
{ {
} }
QByteArray Preprocessor::run(const QString &fileName, const QString &source)
{
return run(fileName, source.toUtf8());
}
QByteArray Preprocessor::run(const QString &fileName, QByteArray Preprocessor::run(const QString &fileName,
const QByteArray &source, const QByteArray &source,
bool noLines, bool noLines,

View File

@@ -79,7 +79,6 @@ public:
public: public:
Preprocessor(Client *client, Environment *env); Preprocessor(Client *client, Environment *env);
QByteArray run(const QString &filename, const QString &source);
QByteArray run(const QString &filename, const QByteArray &source, QByteArray run(const QString &filename, const QByteArray &source,
bool noLines = false, bool markGeneratedTokens = true); bool noLines = false, bool markGeneratedTokens = true);

View File

@@ -63,7 +63,7 @@ static void applyRefactorings(QTextDocument *textDocument, TextEditorWidget *edi
Environment env; Environment env;
Preprocessor preprocess(nullptr, &env); Preprocessor preprocess(nullptr, &env);
const QByteArray preprocessedSource const QByteArray preprocessedSource
= preprocess.run(QLatin1String("<no-file>"), textDocument->toPlainText()); = preprocess.run(QLatin1String("<no-file>"), textDocument->toPlainText().toUtf8());
Document::Ptr cppDocument = Document::create(QLatin1String("<no-file>")); Document::Ptr cppDocument = Document::create(QLatin1String("<no-file>"));
cppDocument->setUtf8Source(preprocessedSource); cppDocument->setUtf8Source(preprocessedSource);

View File

@@ -75,8 +75,8 @@ public:
// Find cursor position and remove cursor marker '@' // Find cursor position and remove cursor marker '@'
int cursorPosition = 0; int cursorPosition = 0;
QString sourceWithoutCursorMarker = QLatin1String(source); QByteArray sourceWithoutCursorMarker = source;
const int pos = sourceWithoutCursorMarker.indexOf(QLatin1Char('@')); const int pos = sourceWithoutCursorMarker.indexOf('@');
if (pos != -1) { if (pos != -1) {
sourceWithoutCursorMarker.remove(pos, 1); sourceWithoutCursorMarker.remove(pos, 1);
cursorPosition = pos; cursorPosition = pos;
@@ -85,8 +85,7 @@ public:
// Write source to temprorary file // Write source to temprorary file
CppEditor::Tests::TemporaryDir temporaryDir; CppEditor::Tests::TemporaryDir temporaryDir;
QVERIFY(temporaryDir.isValid()); QVERIFY(temporaryDir.isValid());
const QString filePath = temporaryDir.createFile("file.h", const QString filePath = temporaryDir.createFile("file.h", sourceWithoutCursorMarker);
sourceWithoutCursorMarker.toUtf8());
QVERIFY(!filePath.isEmpty()); QVERIFY(!filePath.isEmpty());
// Preprocess source // Preprocess source

View File

@@ -1841,7 +1841,7 @@ void tst_Preprocessor::include_guard()
MockClient client(&env, &output); MockClient client(&env, &output);
Preprocessor preprocess(&client, &env); Preprocessor preprocess(&client, &env);
preprocess.setKeepComments(true); preprocess.setKeepComments(true);
/*QByteArray prep =*/ preprocess.run(QLatin1String("<test-case>"), input); /*QByteArray prep =*/ preprocess.run(QLatin1String("<test-case>"), input.toUtf8());
QCOMPARE(QString::fromUtf8(client.includeGuard()), includeGuard); QCOMPARE(QString::fromUtf8(client.includeGuard()), includeGuard);
} }