Android: Clean up JavaParser a bit

Change-Id: I8d5113c7916f816d34a1eacc0b978645d710b2be
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2022-09-27 08:54:23 +02:00
parent 52e8b83bd5
commit 4a5c3d871d
3 changed files with 22 additions and 22 deletions

View File

@@ -42,6 +42,7 @@
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include <QRegularExpression>
#include <QVBoxLayout> #include <QVBoxLayout>
using namespace ProjectExplorer; using namespace ProjectExplorer;

View File

@@ -5,35 +5,38 @@
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/task.h> #include <projectexplorer/task.h>
#include <QFileInfo>
using namespace Android::Internal; #include <QRegularExpression>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils;
JavaParser::JavaParser() : namespace Android::Internal {
m_javaRegExp(QLatin1String("^(.*\\[javac\\]\\s)(.*\\.java):(\\d+):(.*)$"))
JavaParser::JavaParser()
{ } { }
void JavaParser::setProjectFileList(const Utils::FilePaths &fileList) void JavaParser::setProjectFileList(const FilePaths &fileList)
{ {
m_fileList = fileList; m_fileList = fileList;
} }
void JavaParser::setBuildDirectory(const Utils::FilePath &buildDirectory) void JavaParser::setBuildDirectory(const FilePath &buildDirectory)
{ {
m_buildDirectory = buildDirectory; m_buildDirectory = buildDirectory;
} }
void JavaParser::setSourceDirectory(const Utils::FilePath &sourceDirectory) void JavaParser::setSourceDirectory(const FilePath &sourceDirectory)
{ {
m_sourceDirectory = sourceDirectory; m_sourceDirectory = sourceDirectory;
} }
Utils::OutputLineParser::Result JavaParser::handleLine(const QString &line, OutputLineParser::Result JavaParser::handleLine(const QString &line, OutputFormat type)
Utils::OutputFormat type)
{ {
Q_UNUSED(type); Q_UNUSED(type);
const QRegularExpressionMatch match = m_javaRegExp.match(line); static const QRegularExpression javaRegExp("^(.*\\[javac\\]\\s)(.*\\.java):(\\d+):(.*)$");
const QRegularExpressionMatch match = javaRegExp.match(line);
if (!match.hasMatch()) if (!match.hasMatch())
return Status::NotHandled; return Status::NotHandled;
@@ -41,9 +44,9 @@ Utils::OutputLineParser::Result JavaParser::handleLine(const QString &line,
int lineno = match.captured(3).toInt(&ok); int lineno = match.captured(3).toInt(&ok);
if (!ok) if (!ok)
lineno = -1; lineno = -1;
Utils::FilePath file = Utils::FilePath::fromUserInput(match.captured(2)); FilePath file = FilePath::fromUserInput(match.captured(2));
if (file.isChildOf(m_buildDirectory)) { if (file.isChildOf(m_buildDirectory)) {
Utils::FilePath relativePath = file.relativeChildPath(m_buildDirectory); FilePath relativePath = file.relativeChildPath(m_buildDirectory);
file = m_sourceDirectory.pathAppended(relativePath.toString()); file = m_sourceDirectory.pathAppended(relativePath.toString());
} }
if (file.toFileInfo().isRelative()) { if (file.toFileInfo().isRelative()) {
@@ -63,3 +66,5 @@ Utils::OutputLineParser::Result JavaParser::handleLine(const QString &line,
scheduleTask(task, 1); scheduleTask(task, 1);
return {Status::Done, linkSpecs}; return {Status::Done, linkSpecs};
} }
} // Android::Internal

View File

@@ -4,17 +4,13 @@
#pragma once #pragma once
#include <projectexplorer/ioutputparser.h> #include <projectexplorer/ioutputparser.h>
#include <utils/fileutils.h>
#include <QRegularExpression> #include <utils/filepath.h>
namespace Android { namespace Android::Internal {
namespace Internal {
class JavaParser : public ProjectExplorer::OutputTaskParser class JavaParser : public ProjectExplorer::OutputTaskParser
{ {
Q_OBJECT
public: public:
JavaParser(); JavaParser();
@@ -23,13 +19,11 @@ public:
void setSourceDirectory(const Utils::FilePath &sourceDirectory); void setSourceDirectory(const Utils::FilePath &sourceDirectory);
private: private:
Result handleLine(const QString &line, Utils::OutputFormat type) override; Result handleLine(const QString &line, Utils::OutputFormat type) final;
const QRegularExpression m_javaRegExp;
Utils::FilePaths m_fileList; Utils::FilePaths m_fileList;
Utils::FilePath m_sourceDirectory; Utils::FilePath m_sourceDirectory;
Utils::FilePath m_buildDirectory; Utils::FilePath m_buildDirectory;
}; };
} // namespace Internal } // Android::Internal
} // namespace Android